]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/fuel/fuel-edit.el
Use lexical scoping in all fuel sources
[factor.git] / misc / fuel / fuel-edit.el
index e5f0ffd26fcc08bfe270d9fd546ec157a9396d3f..bbc70490495979acea6b1ba2a22adff363dfcc40 100644 (file)
@@ -1,4 +1,4 @@
-;;; fuel-edit.el -- utilities for file editing
+;;; fuel-edit.el -- utilities for file editing -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2009 Jose Antonio Ortega Ruiz
 ;; See http://factorcode.org/license.txt for BSD license.
 (require 'fuel-completion)
 (require 'fuel-eval)
 (require 'fuel-base)
+(require 'factor-mode)
 
 (require 'etags)
 
 \f
 ;;; Customization
 
-(defmacro fuel-edit--define-custom-visit (var group doc)
-  `(defcustom ,var nil
-     ,doc
-     :group ',group
-     :type '(choice (const :tag "Other window" window)
-                    (const :tag "Other frame" frame)
-                    (const :tag "Current window" nil))))
-
-(fuel-edit--define-custom-visit
- fuel-edit-word-method fuel
- "How the new buffer is opened when invoking \\[fuel-edit-word-at-point]")
+(defcustom fuel-edit-word-method nil
+  "How the new buffer is opened when invoking `fuel-edit-word-at-point'."
+  :group 'fuel
+  :type '(choice (const :tag "Other window" window)
+                 (const :tag "Other frame" frame)
+                 (const :tag "Current window" nil)))
 
 \f
 ;;; Auxiliar functions:
         ((eq method 'frame) (find-file-other-frame file))
         (t (find-file file))))
 
-(defun fuel-edit--looking-at-vocab ()
-  (save-excursion
-    (fuel-syntax--beginning-of-defun)
-    (looking-at "USING:\\|USE:\\|IN:")))
-
 (defun fuel-edit--try-edit (ret)
   (let* ((err (fuel-eval--retort-error ret))
          (loc (fuel-eval--retort-result ret)))
     (unless (file-readable-p (car loc))
       (error "Couldn't open '%s' for read" (car loc)))
     (fuel-edit--visit-file (car loc) fuel-edit-word-method)
-    (goto-line (if (numberp (cadr loc)) (cadr loc) 1))))
-
-(defun fuel-edit--read-vocabulary-name (refresh)
-  (let* ((vocabs (fuel-completion--vocabs refresh))
-         (prompt "Vocabulary name: "))
-    (if vocabs
-        (completing-read prompt vocabs nil nil nil fuel-edit--vocab-history)
-      (read-string prompt nil fuel-edit--vocab-history))))
+    (goto-char (point-min))
+    (forward-line (1- (if (numberp (cadr loc)) (cadr loc) 1)))))
 
 (defun fuel-edit--edit-article (name)
   (let ((cmd `(:fuel* (,name fuel-get-article-location) "fuel" t)))
 ;;; Editing commands:
 
 (defvar fuel-edit--word-history nil)
-(defvar fuel-edit--vocab-history nil)
-(defvar fuel-edit--previous-location nil)
 
+;;;###autoload
 (defun fuel-edit-vocabulary (&optional refresh vocab)
   "Visits vocabulary file in Emacs.
 When called interactively, asks for vocabulary with completion.
 With prefix argument, refreshes cached vocabulary list."
   (interactive "P")
-  (let* ((vocab (or vocab (fuel-edit--read-vocabulary-name refresh)))
+  (let* ((vocab (or vocab (fuel-completion--read-vocab refresh)))
          (cmd `(:fuel* (,vocab fuel-get-vocab-location) "fuel" t)))
     (fuel-edit--try-edit (fuel-eval--send/wait cmd))))
 
-(defun fuel-edit-word (&optional arg)
-  "Asks for a word to edit, with completion.
-With prefix, only words visible in the current vocabulary are
-offered."
-  (interactive "P")
-  (let* ((word (fuel-completion--read-word "Edit word: "
-                                           nil
-                                           fuel-edit--word-history
-                                           arg))
-         (cmd `(:fuel* ((:quote ,word) fuel-get-word-location))))
-    (fuel-edit--try-edit (fuel-eval--send/wait cmd))))
-
+;;;###autoload
 (defun fuel-edit-word-at-point (&optional arg)
   "Opens a new window visiting the definition of the word at point.
 With prefix, asks for the word to edit."
   (interactive "P")
-  (let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point))
+  (let* ((word (or (and (not arg) (factor-symbol-at-point))
                    (fuel-completion--read-word "Edit word: ")))
          (cmd `(:fuel* ((:quote ,word) fuel-get-word-location)))
          (marker (and (not arg) (point-marker))))
-    (if (and (not arg) (fuel-edit--looking-at-vocab))
+    (if (and (not arg) (factor-on-vocab))
         (fuel-edit-vocabulary nil word)
       (fuel-edit--try-edit (fuel-eval--send/wait cmd)))
     (when marker (ring-insert find-tag-marker-ring marker))))
@@ -114,7 +87,7 @@ With prefix, asks for the word to edit."
 With prefix, asks for the word to edit."
   (interactive "P")
   (let* ((word (or word
-                   (and (not arg) (fuel-syntax-symbol-at-point))
+                   (and (not arg) (factor-symbol-at-point))
                    (fuel-completion--read-word "Edit word: ")))
          (cmd `(:fuel* ((:quote ,word) fuel-get-doc-location)))
          (marker (and (not arg) (point-marker))))
@@ -137,7 +110,7 @@ was last invoked."
   (interactive)
   (condition-case nil
       (pop-tag-mark)
-    (error "No previous location for find word or vocab invokation")))
+    (error "No previous location for find word or vocab invocation")))
 
 (defvar fuel-edit--buffer-history nil)
 
@@ -147,7 +120,7 @@ was last invoked."
   (let ((buffer (completing-read "Factor buffer: "
                                  (remove (buffer-name)
                                          (mapcar 'buffer-name (buffer-list)))
-                                 '(lambda (s) (string-match "\\.factor$" s))
+                                 #'(lambda (s) (string-match "\\.factor$" s))
                                  t
                                  nil
                                  fuel-edit--buffer-history)))