]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/fuel/fuel-autodoc.el
Use lexical scoping in all fuel sources
[factor.git] / misc / fuel / fuel-autodoc.el
index 151631eea19784600fee59ee38bb0904c5f6371b..9b6cb5f59d07fbab66a0b49501ca41b6977edfb8 100644 (file)
@@ -1,6 +1,6 @@
-;;; fuel-autodoc.el -- doc snippets in the echo area
+;;; fuel-autodoc.el -- doc snippets in the echo area -*- lexical-binding: t -*-
 
-;; Copyright (C) 2008 Jose Antonio Ortega Ruiz
+;; Copyright (C) 2008, 2009 Jose Antonio Ortega Ruiz
 ;; See http://factorcode.org/license.txt for BSD license.
 
 ;; Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
 ;;; Code:
 
 (require 'fuel-eval)
-(require 'fuel-font-lock)
-(require 'fuel-syntax)
 (require 'fuel-base)
+(require 'factor-mode)
 
 \f
 ;;; Customization:
 
+;;;###autoload
 (defgroup fuel-autodoc nil
   "Options controlling FUEL's autodoc system."
   :group 'fuel)
   :group 'fuel-autodoc
   :type 'boolean)
 
-
-\f
-;;; Highlighting for autodoc messages:
-
-(defvar fuel-autodoc--font-lock-buffer
-  (let ((buffer (get-buffer-create " *fuel help minibuffer messages*")))
-    (set-buffer buffer)
-    (set-syntax-table fuel-syntax--syntax-table)
-    (fuel-font-lock--font-lock-setup)
-    buffer))
-
-(defun fuel-autodoc--font-lock-str (str)
-  (set-buffer fuel-autodoc--font-lock-buffer)
-  (erase-buffer)
-  (insert str)
-  (let ((font-lock-verbose nil)) (font-lock-fontify-buffer))
-  (buffer-string))
-
 \f
 ;;; Eldoc function:
 
 (defvar fuel-autodoc--timeout 200)
 
 (defun fuel-autodoc--word-synopsis (&optional word)
-  (let ((word (or word (fuel-syntax-symbol-at-point)))
+  (let ((word (or word (factor-symbol-at-point)))
         (fuel-log--inhibit-p t))
     (when word
-      (let* ((cmd (if (fuel-syntax--in-using)
-                      `(:fuel* (,word fuel-vocab-summary) :in t)
-                    `(:fuel* (((:quote ,word) synopsis :get)) :in)))
-             (ret (fuel-eval--send/wait cmd fuel-autodoc--timeout))
-             (res (fuel-eval--retort-result ret)))
-        (when (and ret (not (fuel-eval--retort-error ret)) (stringp res))
-          (if fuel-autodoc-minibuffer-font-lock
-              (fuel-autodoc--font-lock-str res)
-            res))))))
-
-(make-variable-buffer-local
- (defvar fuel-autodoc--fallback-function nil))
+      (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 synposis 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))
-      (fuel-autodoc--word-synopsis)))
+      (condition-case e
+          (fuel-autodoc--word-synopsis)
+        (error (format "Autodoc not available (%s)"
+                       (error-message-string e))))))
 
 \f
 ;;; Autodoc mode:
 
-(make-variable-buffer-local
- (defvar fuel-autodoc-mode-string " A"
-   "Modeline indicator for fuel-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.
@@ -95,12 +80,13 @@ displayed in the minibuffer."
   :lighter fuel-autodoc-mode-string
   :group 'fuel-autodoc
 
-  (set (make-local-variable 'eldoc-documentation-function)
+  (setq-local eldoc-documentation-function
        (when fuel-autodoc-mode 'fuel-autodoc--eldoc-function))
-  (set (make-local-variable 'eldoc-minor-mode-string) nil)
+  (setq-local eldoc-minor-mode-string nil)
   (eldoc-mode fuel-autodoc-mode)
   (message "Fuel Autodoc %s" (if fuel-autodoc-mode "enabled" "disabled")))
 
 \f
 (provide 'fuel-autodoc)
+
 ;;; fuel-autodoc.el ends here