]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Edit word interactive command; completion in help prompt.
authorJose A. Ortega Ruiz <jao@gnu.org>
Wed, 17 Dec 2008 00:12:15 +0000 (01:12 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Wed, 17 Dec 2008 00:12:15 +0000 (01:12 +0100)
misc/fuel/README
misc/fuel/fuel-completion.el
misc/fuel/fuel-help.el
misc/fuel/fuel-mode.el

index 79c24ec69f0c3bc57a61db582ebf2b1432511b1f..cc938a60ff65861ccaab7fd08e65f87ce9d794ab 100644 (file)
@@ -57,7 +57,8 @@ C-cC-eC-r is the same as C-cC-er)).
 
  - M-. : edit word at point in Emacs
  - M-TAB : complete word at point
- - C-cC-ev : edit vocabulary
+ - C-cC-ev : edit vocabulary (M-x fuel-edit-vocabulary)
+ - C-cC-ew : edit word (M-x fuel-edit-word)
 
  - C-cr, C-cC-er : eval region
  - C-M-r, C-cC-ee : eval region, extending it to definition boundaries
index 6b89dbb008f0dd586ea147d9f167f3b8375e4770..8d2d779b318cbcd7a8c8b6ccbff4f97cb2b16621 100644 (file)
@@ -143,6 +143,15 @@ terminates a current completion."
          (vs (and cv `("syntax" ,cv ,@(fuel-syntax--usings)))))
     (fuel-completion--words prefix vs)))
 
+(defsubst fuel-completion--all-words-list (prefix)
+  (fuel-completion--words prefix nil))
+
+(defvar fuel-completion--word-list-func
+  (completion-table-dynamic 'fuel-completion--word-list))
+
+(defvar fuel-completion--all-words-list-func
+  (completion-table-dynamic 'fuel-completion--all-words-list))
+
 (defun fuel-completion--complete (prefix)
   (let* ((words (fuel-completion--word-list prefix))
          (completions (all-completions prefix words))
@@ -150,6 +159,14 @@ terminates a current completion."
          (partial (if (eq partial t) prefix partial)))
     (cons completions partial)))
 
+(defsubst fuel-completion--read-word (prompt &optional default history all)
+  (completing-read prompt
+                   (if all fuel-completion--all-words-list-func
+                     fuel-completion--word-list-func)
+                   nil nil nil
+                   history
+                   (or default (fuel-syntax-symbol-at-point))))
+
 (defun fuel-completion--complete-symbol ()
   "Complete the symbol at point.
 Perform completion similar to Emacs' complete-symbol."
index 1b9cd9b1212f188f19244fbceb49d9f0caecd055..1b0890ef9b1e5205ffd3278f9cc483e17b90ad67 100644 (file)
 
 ;;; Code:
 
-(require 'fuel-base)
-(require 'fuel-font-lock)
 (require 'fuel-eval)
+(require 'fuel-completion)
+(require 'fuel-font-lock)
+(require 'fuel-base)
 
 \f
 ;;; Customization:
@@ -149,7 +150,9 @@ displayed in the minibuffer."
          (ask (or (not (memq major-mode '(factor-mode fuel-help-mode)))
                   (not def)
                   fuel-help-always-ask))
-         (def (if ask (read-string prompt nil 'fuel-help--prompt-history def)
+         (def (if ask (fuel-completion--read-word prompt
+                                                  def
+                                                  'fuel-help--prompt-history)
                 def))
          (cmd `(:fuel* ((:quote ,def) ,(if see 'see 'help)) t)))
     (message "Looking up '%s' ..." def)
index 0f8e60016579eee9dd6dce3a2f28da825836375f..b93160518375dc4138dc4a04fd0de9d332c5c5c8 100644 (file)
@@ -114,18 +114,26 @@ buffer in case of errors."
   "Opens a new window visiting the definition of the word at point.
 With prefix, asks for the word to edit."
   (interactive "P")
-  (let* ((word (fuel-syntax-symbol-at-point))
-         (ask (or arg (not word)))
-         (word (if ask
-                   (read-string nil
-                                (format "Edit word%s: "
-                                        (if word (format " (%s)" word) ""))
-                                word)
-                 word)))
-    (let ((cmd `(:fuel ((:quote ,word) fuel-get-edit-location))))
-      (condition-case nil
-          (fuel--try-edit (fuel-eval--send/wait cmd))
-        (error (fuel-edit-vocabulary nil word))))))
+  (let* ((word (or (and (not arg) (fuel-syntax-symbol-at-point))
+                  (fuel-completion--read-word "Edit word: ")))
+         (cmd `(:fuel ((:quote ,word) fuel-get-edit-location))))
+    (condition-case nil
+        (fuel--try-edit (fuel-eval--send/wait cmd))
+      (error (fuel-edit-vocabulary nil word)))))
+
+(defvar fuel-mode--word-history nil)
+
+(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-mode--word-history
+                                           arg))
+         (cmd `(:fuel ((:quote ,word) fuel-get-edit-location))))
+    (fuel--try-edit (fuel-eval--send/wait cmd))))
 
 (defvar fuel--vocabs-prompt-history nil)
 
@@ -195,7 +203,7 @@ interacting with a factor listener is at your disposal.
 (fuel-mode--key ?e ?e 'fuel-eval-extended-region)
 (fuel-mode--key ?e ?r 'fuel-eval-region)
 (fuel-mode--key ?e ?v 'fuel-edit-vocabulary)
-(fuel-mode--key ?e ?w 'fuel-edit-word-at-point)
+(fuel-mode--key ?e ?w 'fuel-edit-word)
 (fuel-mode--key ?e ?x 'fuel-eval-definition)
 
 (fuel-mode--key ?d ?a 'fuel-autodoc-mode)