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