- 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
(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))
(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."
;;; Code:
-(require 'fuel-base)
-(require 'fuel-font-lock)
(require 'fuel-eval)
+(require 'fuel-completion)
+(require 'fuel-font-lock)
+(require 'fuel-base)
\f
;;; Customization:
(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)
"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)
(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)