1 ;;; fuel-autodoc.el -- doc snippets in the echo area
3 ;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Sat Dec 20, 2008 00:50
12 ;; Utilities for displaying information automatically in the echo
18 (require 'fuel-font-lock)
19 (require 'fuel-syntax)
25 (defgroup fuel-autodoc nil
26 "Options controlling FUEL's autodoc system."
29 (defcustom fuel-autodoc-minibuffer-font-lock t
30 "Whether to use font lock for info messages in the minibuffer."
37 (defvar fuel-autodoc--font-lock-buffer
38 (let ((buffer (get-buffer-create " *fuel help minibuffer messages*")))
40 (set-syntax-table fuel-syntax--syntax-table)
41 (fuel-font-lock--font-lock-setup)
44 (defun fuel-autodoc--font-lock-str (str)
45 (set-buffer fuel-autodoc--font-lock-buffer)
48 (let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
51 (defun fuel-autodoc--word-synopsis (&optional word)
52 (let ((word (or word (fuel-syntax-symbol-at-point)))
53 (fuel-log--inhibit-p t))
55 (let* ((cmd (if (fuel-syntax--in-using)
56 `(:fuel* (,word fuel-vocab-summary) :in t)
57 `(:fuel* (((:quote ,word) synopsis :get)) :in)))
58 (ret (fuel-eval--send/wait cmd 20))
59 (res (fuel-eval--retort-result ret)))
60 (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
61 (if fuel-autodoc-minibuffer-font-lock
62 (fuel-autodoc--font-lock-str res)
65 (make-variable-buffer-local
66 (defvar fuel-autodoc--fallback-function nil))
68 (defun fuel-autodoc--eldoc-function ()
69 (or (and fuel-autodoc--fallback-function
70 (funcall fuel-autodoc--fallback-function))
71 (fuel-autodoc--word-synopsis)))
73 (make-variable-buffer-local
74 (defvar fuel-autodoc-mode-string " A"
75 "Modeline indicator for fuel-autodoc-mode"))
77 (define-minor-mode fuel-autodoc-mode
78 "Toggle Fuel's Autodoc mode.
79 With no argument, this command toggles the mode.
80 Non-null prefix argument turns on the mode.
81 Null prefix argument turns off the mode.
83 When Autodoc mode is enabled, a synopsis of the word at point is
84 displayed in the minibuffer."
86 :lighter fuel-autodoc-mode-string
89 (set (make-local-variable 'eldoc-documentation-function)
90 (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
91 (set (make-local-variable 'eldoc-minor-mode-string) nil)
92 (eldoc-mode fuel-autodoc-mode)
93 (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
96 (provide 'fuel-autodoc)
97 ;;; fuel-autodoc.el ends here