From 7133b7ee629457053e63db2a7f192037407da57b Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 23 Aug 2010 00:27:59 +0100 Subject: Move reading an extended command to Elisp (bug#5364, bug#5214). * lisp/simple.el (read-extended-command): New function with the logic for `completing-read' moved to Elisp from `execute-extended-command'. Use `function-called-at-point' in `minibuffer-default-add-function' to get a command name for M-n (bug#5364, bug#5214). * src/keyboard.c (Fexecute_extended_command): Move reading a command name with `completing-read' to a new Elisp function `read-extended-command'. Call it to read a command to `function' (bug#5364, bug#5214). --- lisp/ChangeLog | 7 +++++++ lisp/simple.el | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'lisp') diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9452ac294dd..c1fae3283ac 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2010-08-22 Juri Linkov + + * simple.el (read-extended-command): New function with the logic + for `completing-read' moved to Elisp from `execute-extended-command'. + Use `function-called-at-point' in `minibuffer-default-add-function' + to get a command name for M-n (bug#5364, bug#5214). + 2010-08-22 Chong Yidong * startup.el (command-line-1): Issue warning for ignored arguments diff --git a/lisp/simple.el b/lisp/simple.el index 5f62b9d9e73..c1ec78da7b9 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -1301,6 +1301,40 @@ to get different commands to edit and resubmit." (if command-history (error "Argument %d is beyond length of command history" arg) (error "There are no previous complex commands to repeat"))))) + +(defun read-extended-command () + "Read command name to invoke in `execute-extended-command'." + (minibuffer-with-setup-hook + (lambda () + (set (make-local-variable 'minibuffer-default-add-function) + (lambda () + ;; Get a command name at point in the original buffer + ;; to propose it after M-n. + (with-current-buffer (window-buffer (minibuffer-selected-window)) + (and (commandp (function-called-at-point)) + (format "%S" (function-called-at-point))))))) + ;; Read a string, completing from and restricting to the set of + ;; all defined commands. Don't provide any initial input. + ;; Save the command read on the extended-command history list. + (completing-read + (concat (cond + ((eq current-prefix-arg '-) "- ") + ((and (consp current-prefix-arg) + (eq (car current-prefix-arg) 4)) "C-u ") + ((and (consp current-prefix-arg) + (integerp (car current-prefix-arg))) + (format "%d " (car current-prefix-arg))) + ((integerp current-prefix-arg) + (format "%d " current-prefix-arg))) + ;; This isn't strictly correct if `execute-extended-command' + ;; is bound to anything else (e.g. [menu]). + ;; It could use (key-description (this-single-command-keys)), + ;; but actually a prompt other than "M-x" would be confusing, + ;; because "M-x" is a well-known prompt to read a command + ;; and it serves as a shorthand for "Extended command: ". + "M-x ") + obarray 'commandp t nil 'extended-command-history))) + (defvar minibuffer-history nil "Default minibuffer history list. -- cgit v1.2.1