2008-12-20 10:51:05 -05:00
|
|
|
|
;;; fuel-autodoc.el -- doc snippets in the echo area
|
|
|
|
|
|
2009-01-03 10:37:28 -05:00
|
|
|
|
;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
|
2008-12-20 10:51:05 -05:00
|
|
|
|
;; See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
|
|
|
|
|
;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
|
|
|
|
|
;; 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)
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(require 'factor-mode)
|
2008-12-20 10:51:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Customization:
|
|
|
|
|
|
2013-05-05 00:48:12 -04:00
|
|
|
|
;;;###autoload
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defgroup fuel-autodoc nil
|
2008-12-21 19:51:41 -05:00
|
|
|
|
"Options controlling FUEL's autodoc system."
|
2008-12-20 10:51:05 -05:00
|
|
|
|
: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)
|
|
|
|
|
|
2008-12-30 18:23:44 -05:00
|
|
|
|
|
2009-02-18 19:33:47 -05:00
|
|
|
|
(defcustom fuel-autodoc-eval-using-form-p nil
|
|
|
|
|
"When enabled, automatically load vocabularies in USING: form
|
|
|
|
|
to display autodoc messages.
|
|
|
|
|
|
|
|
|
|
In order to show autodoc messages for words in a Factor buffer,
|
|
|
|
|
the used vocabularies must be loaded in the Factor image. Setting
|
|
|
|
|
this variable to `t' will do that automatically for you,
|
|
|
|
|
asynchronously. That means that you'll be able to move around
|
|
|
|
|
while the vocabs are being loaded, but no other FUEL
|
|
|
|
|
functionality will be available until loading finishes (and it
|
|
|
|
|
may take a while). Thus, this functionality is disabled by
|
|
|
|
|
default. You can force loading the vocabs in a Factor buffer
|
|
|
|
|
USING: form with \\[fuel-load-usings]."
|
|
|
|
|
:group 'fuel-autodoc
|
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
2008-12-30 18:23:44 -05:00
|
|
|
|
|
|
|
|
|
;;; Eldoc function:
|
|
|
|
|
|
|
|
|
|
(defvar fuel-autodoc--timeout 200)
|
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(defun fuel-autodoc--word-synopsis (&optional word)
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(let ((word (or word (factor-symbol-at-point)))
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(fuel-log--inhibit-p t))
|
|
|
|
|
(when word
|
2009-02-18 19:33:47 -05:00
|
|
|
|
(let* ((usings (if fuel-autodoc-eval-using-form-p :usings t))
|
2014-04-17 12:39:10 -04:00
|
|
|
|
(cmd (if (factor-on-vocab)
|
2008-12-27 09:18:17 -05:00
|
|
|
|
`(:fuel* (,word fuel-vocab-summary) :in t)
|
2009-02-18 19:33:47 -05:00
|
|
|
|
`(:fuel* ((,word :usings fuel-word-synopsis)) t ,usings)))
|
2008-12-30 18:23:44 -05:00
|
|
|
|
(ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(res (fuel-eval--retort-result ret)))
|
|
|
|
|
(when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
|
|
|
|
|
(if fuel-autodoc-minibuffer-font-lock
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(factor-font-lock-string res)
|
2008-12-20 10:51:05 -05:00
|
|
|
|
res))))))
|
|
|
|
|
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(defvar-local fuel-autodoc--fallback-function nil)
|
2008-12-20 10:51:05 -05:00
|
|
|
|
|
|
|
|
|
(defun fuel-autodoc--eldoc-function ()
|
|
|
|
|
(or (and fuel-autodoc--fallback-function
|
|
|
|
|
(funcall fuel-autodoc--fallback-function))
|
2009-01-08 21:45:04 -05:00
|
|
|
|
(condition-case e
|
|
|
|
|
(fuel-autodoc--word-synopsis)
|
|
|
|
|
(error (format "Autodoc not available (%s)"
|
|
|
|
|
(error-message-string e))))))
|
2008-12-20 10:51:05 -05:00
|
|
|
|
|
2008-12-30 18:23:44 -05:00
|
|
|
|
|
|
|
|
|
;;; Autodoc mode:
|
|
|
|
|
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(defvar-local fuel-autodoc-mode-string " A"
|
|
|
|
|
"Modeline indicator for fuel-autodoc-mode")
|
2008-12-20 10:51:05 -05:00
|
|
|
|
|
2013-05-05 00:48:12 -04:00
|
|
|
|
;;;###autoload
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(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
|
|
|
|
|
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(setq-local eldoc-documentation-function
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
|
2013-05-05 00:48:12 -04:00
|
|
|
|
(setq-local eldoc-minor-mode-string nil)
|
2008-12-20 10:51:05 -05:00
|
|
|
|
(eldoc-mode fuel-autodoc-mode)
|
|
|
|
|
(message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'fuel-autodoc)
|
2013-05-05 00:48:12 -04:00
|
|
|
|
|
2008-12-20 10:51:05 -05:00
|
|
|
|
;;; fuel-autodoc.el ends here
|