add using
[factor/jcg.git] / misc / fuel / fuel-autodoc.el
blob76919702bb93386ed35a26cb2c64c346878144b5
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
10 ;;; Comentary:
12 ;; Utilities for displaying information automatically in the echo
13 ;; area.
15 ;;; Code:
17 (require 'fuel-eval)
18 (require 'fuel-font-lock)
19 (require 'fuel-syntax)
20 (require 'fuel-base)
23 ;;; Customization:
25 (defgroup fuel-autodoc nil
26 "Options controlling FUEL's autodoc system."
27 :group 'fuel)
29 (defcustom fuel-autodoc-minibuffer-font-lock t
30 "Whether to use font lock for info messages in the minibuffer."
31 :group 'fuel-autodoc
32 :type 'boolean)
36 ;;; Eldoc function:
38 (defvar fuel-autodoc--timeout 200)
40 (defun fuel-autodoc--word-synopsis (&optional word)
41 (let ((word (or word (fuel-syntax-symbol-at-point)))
42 (fuel-log--inhibit-p t))
43 (when word
44 (let* ((cmd (if (fuel-syntax--in-using)
45 `(:fuel* (,word fuel-vocab-summary) :in t)
46 `(:fuel* (((:quote ,word) synopsis :get)) :in)))
47 (ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
48 (res (fuel-eval--retort-result ret)))
49 (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
50 (if fuel-autodoc-minibuffer-font-lock
51 (fuel-font-lock--factor-str res)
52 res))))))
54 (make-variable-buffer-local
55 (defvar fuel-autodoc--fallback-function nil))
57 (defun fuel-autodoc--eldoc-function ()
58 (or (and fuel-autodoc--fallback-function
59 (funcall fuel-autodoc--fallback-function))
60 (condition-case e
61 (fuel-autodoc--word-synopsis)
62 (error (format "Autodoc not available (%s)"
63 (error-message-string e))))))
66 ;;; Autodoc mode:
68 (make-variable-buffer-local
69 (defvar fuel-autodoc-mode-string " A"
70 "Modeline indicator for fuel-autodoc-mode"))
72 (define-minor-mode fuel-autodoc-mode
73 "Toggle Fuel's Autodoc mode.
74 With no argument, this command toggles the mode.
75 Non-null prefix argument turns on the mode.
76 Null prefix argument turns off the mode.
78 When Autodoc mode is enabled, a synopsis of the word at point is
79 displayed in the minibuffer."
80 :init-value nil
81 :lighter fuel-autodoc-mode-string
82 :group 'fuel-autodoc
84 (set (make-local-variable 'eldoc-documentation-function)
85 (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
86 (set (make-local-variable 'eldoc-minor-mode-string) nil)
87 (eldoc-mode fuel-autodoc-mode)
88 (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
91 (provide 'fuel-autodoc)
92 ;;; fuel-autodoc.el ends here