1 ;;; fuel-autodoc.el -- doc snippets in the echo area -*- lexical-binding: t -*-
3 ;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
4 ;; See https://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."
37 (defvar fuel-autodoc--timeout 200)
39 (defun fuel-autodoc--word-synopsis (&optional word)
40 (let ((word (or word (factor-symbol-at-point)))
41 (fuel-log--inhibit-p t))
43 (let ((cmd `(:fuel* (,word ,'fuel-word-synopsis)
44 ,(factor-current-vocab)
46 (let* ((ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
47 (res (fuel-eval--retort-result ret)))
49 (message "No synopsis for '%s'" word)
50 (if fuel-autodoc-minibuffer-font-lock
51 (factor-font-lock-string res)
54 (defvar-local fuel-autodoc--fallback-function nil)
56 (defun fuel-autodoc--eldoc-function ()
57 (or (and fuel-autodoc--fallback-function
58 (funcall fuel-autodoc--fallback-function))
60 (fuel-autodoc--word-synopsis)
61 (error (format "Autodoc not available (%s)"
62 (error-message-string e))))))
67 (defvar-local fuel-autodoc-mode-string " A"
68 "Modeline indicator for fuel-autodoc-mode")
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.
77 When Autodoc mode is enabled, a synopsis of the word at point is
78 displayed in the minibuffer."
80 :lighter fuel-autodoc-mode-string
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")))
90 (provide 'fuel-autodoc)
92 ;;; fuel-autodoc.el ends here