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-syntax)
24 (defgroup fuel-autodoc nil
25 "Options controlling FUEL's autodoc system"
28 (defcustom fuel-autodoc-minibuffer-font-lock t
29 "Whether to use font lock for info messages in the minibuffer."
36 (defvar fuel-autodoc--font-lock-buffer
37 (let ((buffer (get-buffer-create " *fuel help minibuffer messages*")))
39 (fuel-font-lock--font-lock-setup)
42 (defun fuel-autodoc--font-lock-str (str)
43 (set-buffer fuel-autodoc--font-lock-buffer)
46 (let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
49 (defun fuel-autodoc--word-synopsis (&optional word)
50 (let ((word (or word (fuel-syntax-symbol-at-point)))
51 (fuel-log--inhibit-p t))
53 (let* ((cmd (if (fuel-syntax--in-using)
54 `(:fuel* (,word fuel-vocab-summary) t t)
55 `(:fuel* (((:quote ,word) synopsis :get)) t)))
56 (ret (fuel-eval--send/wait cmd 20))
57 (res (fuel-eval--retort-result ret)))
58 (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
59 (if fuel-autodoc-minibuffer-font-lock
60 (fuel-autodoc--font-lock-str res)
63 (make-variable-buffer-local
64 (defvar fuel-autodoc--fallback-function nil))
66 (defun fuel-autodoc--eldoc-function ()
67 (or (and fuel-autodoc--fallback-function
68 (funcall fuel-autodoc--fallback-function))
69 (fuel-autodoc--word-synopsis)))
71 (make-variable-buffer-local
72 (defvar fuel-autodoc-mode-string " A"
73 "Modeline indicator for fuel-autodoc-mode"))
75 (define-minor-mode fuel-autodoc-mode
76 "Toggle Fuel's Autodoc mode.
77 With no argument, this command toggles the mode.
78 Non-null prefix argument turns on the mode.
79 Null prefix argument turns off the mode.
81 When Autodoc mode is enabled, a synopsis of the word at point is
82 displayed in the minibuffer."
84 :lighter fuel-autodoc-mode-string
87 (set (make-local-variable 'eldoc-documentation-function)
88 (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
89 (set (make-local-variable 'eldoc-minor-mode-string) nil)
90 (eldoc-mode fuel-autodoc-mode)
91 (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
94 (provide 'fuel-autodoc)
95 ;;; fuel-autodoc.el ends here