From e13adc4db0e9347c3b399fa1470847fb47dfb59b Mon Sep 17 00:00:00 2001 From: "Jose A. Ortega Ruiz" Date: Wed, 17 Dec 2008 01:12:15 +0100 Subject: [PATCH] FUEL: Edit word interactive command; completion in help prompt. --- misc/fuel/README | 3 ++- misc/fuel/fuel-completion.el | 17 +++++++++++++++++ misc/fuel/fuel-help.el | 9 ++++++--- misc/fuel/fuel-mode.el | 34 +++++++++++++++++++++------------- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/misc/fuel/README b/misc/fuel/README index 79c24ec69f..cc938a60ff 100644 --- a/misc/fuel/README +++ b/misc/fuel/README @@ -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 diff --git a/misc/fuel/fuel-completion.el b/misc/fuel/fuel-completion.el index 6b89dbb008..8d2d779b31 100644 --- a/misc/fuel/fuel-completion.el +++ b/misc/fuel/fuel-completion.el @@ -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." diff --git a/misc/fuel/fuel-help.el b/misc/fuel/fuel-help.el index 1b9cd9b121..1b0890ef9b 100644 --- a/misc/fuel/fuel-help.el +++ b/misc/fuel/fuel-help.el @@ -14,9 +14,10 @@ ;;; Code: -(require 'fuel-base) -(require 'fuel-font-lock) (require 'fuel-eval) +(require 'fuel-completion) +(require 'fuel-font-lock) +(require 'fuel-base) ;;; 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) diff --git a/misc/fuel/fuel-mode.el b/misc/fuel/fuel-mode.el index 0f8e600165..b931605183 100644 --- a/misc/fuel/fuel-mode.el +++ b/misc/fuel/fuel-mode.el @@ -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)