1 ;;; fuel-autodoc.el -- doc snippets in the echo area
3 ;; Copyright (C) 2008, 2009 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
19 (require 'factor-mode)
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."
35 (defcustom fuel-autodoc-eval-using-form-p nil
36 "When enabled, automatically load vocabularies in USING: form
37 to display autodoc messages.
39 In order to show autodoc messages for words in a Factor buffer,
40 the used vocabularies must be loaded in the Factor image. Setting
41 this variable to `t' will do that automatically for you,
42 asynchronously. That means that you'll be able to move around
43 while the vocabs are being loaded, but no other FUEL
44 functionality will be available until loading finishes (and it
45 may take a while). Thus, this functionality is disabled by
46 default. You can force loading the vocabs in a Factor buffer
47 USING: form with \\[fuel-load-usings]."
54 (defvar fuel-autodoc--timeout 200)
56 (defun fuel-autodoc--word-synopsis (&optional word)
57 (let ((word (or word (factor-symbol-at-point)))
58 (fuel-log--inhibit-p t))
60 (let* ((usings (if fuel-autodoc-eval-using-form-p :usings t))
61 (cmd (if (factor-on-vocab)
62 `(:fuel* (,word fuel-vocab-summary) :in t)
63 `(:fuel* ((,word :usings fuel-word-synopsis)) t ,usings)))
64 (ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
65 (res (fuel-eval--retort-result ret)))
66 (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
67 (if fuel-autodoc-minibuffer-font-lock
68 (factor-font-lock-string res)
71 (defvar-local fuel-autodoc--fallback-function nil)
73 (defun fuel-autodoc--eldoc-function ()
74 (or (and fuel-autodoc--fallback-function
75 (funcall fuel-autodoc--fallback-function))
77 (fuel-autodoc--word-synopsis)
78 (error (format "Autodoc not available (%s)"
79 (error-message-string e))))))
84 (defvar-local fuel-autodoc-mode-string " A"
85 "Modeline indicator for fuel-autodoc-mode")
88 (define-minor-mode fuel-autodoc-mode
89 "Toggle Fuel's Autodoc mode.
90 With no argument, this command toggles the mode.
91 Non-null prefix argument turns on the mode.
92 Null prefix argument turns off the mode.
94 When Autodoc mode is enabled, a synopsis of the word at point is
95 displayed in the minibuffer."
97 :lighter fuel-autodoc-mode-string
100 (setq-local eldoc-documentation-function
101 (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
102 (setq-local eldoc-minor-mode-string nil)
103 (eldoc-mode fuel-autodoc-mode)
104 (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
107 (provide 'fuel-autodoc)
109 ;;; fuel-autodoc.el ends here