]> gitweb.factorcode.org Git - factor.git/blob - misc/fuel/fuel-autodoc.el
Use lexical scoping in all fuel sources
[factor.git] / misc / fuel / fuel-autodoc.el
1 ;;; fuel-autodoc.el -- doc snippets in the echo area -*- lexical-binding: t -*-
2
3 ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
4 ;; See http://factorcode.org/license.txt for BSD license.
5
6 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
7 ;; Keywords: languages, fuel, factor
8 ;; Start date: Sat Dec 20, 2008 00:50
9
10 ;;; Comentary:
11
12 ;; Utilities for displaying information automatically in the echo
13 ;; area.
14
15 ;;; Code:
16
17 (require 'fuel-eval)
18 (require 'fuel-base)
19 (require 'factor-mode)
20
21 \f
22 ;;; Customization:
23
24 ;;;###autoload
25 (defgroup fuel-autodoc nil
26   "Options controlling FUEL's autodoc system."
27   :group 'fuel)
28
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)
33
34 \f
35 ;;; Eldoc function:
36
37 (defvar fuel-autodoc--timeout 200)
38
39 (defun fuel-autodoc--word-synopsis (&optional word)
40   (let ((word (or word (factor-symbol-at-point)))
41         (fuel-log--inhibit-p t))
42     (when word
43       (let ((cmd `(:fuel* (,word ,'fuel-word-synopsis)
44                           ,(factor-current-vocab)
45                           ,(factor-usings))))
46         (let* ((ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
47                (res (fuel-eval--retort-result ret)))
48           (if (not res)
49               (message "No synposis for '%s'" word)
50             (if fuel-autodoc-minibuffer-font-lock
51                 (factor-font-lock-string res)
52               res)))))))
53
54 (defvar-local fuel-autodoc--fallback-function nil)
55
56 (defun fuel-autodoc--eldoc-function ()
57   (or (and fuel-autodoc--fallback-function
58            (funcall fuel-autodoc--fallback-function))
59       (condition-case e
60           (fuel-autodoc--word-synopsis)
61         (error (format "Autodoc not available (%s)"
62                        (error-message-string e))))))
63
64 \f
65 ;;; Autodoc mode:
66
67 (defvar-local fuel-autodoc-mode-string " A"
68   "Modeline indicator for fuel-autodoc-mode")
69
70 ;;;###autoload
71 (define-minor-mode fuel-autodoc-mode
72   "Toggle Fuel's Autodoc mode.
73 With no argument, this command toggles the mode.
74 Non-null prefix argument turns on the mode.
75 Null prefix argument turns off the mode.
76
77 When Autodoc mode is enabled, a synopsis of the word at point is
78 displayed in the minibuffer."
79   :init-value nil
80   :lighter fuel-autodoc-mode-string
81   :group 'fuel-autodoc
82
83   (setq-local eldoc-documentation-function
84        (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
85   (setq-local eldoc-minor-mode-string nil)
86   (eldoc-mode fuel-autodoc-mode)
87   (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
88
89 \f
90 (provide 'fuel-autodoc)
91
92 ;;; fuel-autodoc.el ends here