diff options
| author | Juri Linkov | 2010-08-23 00:27:59 +0100 |
|---|---|---|
| committer | Juri Linkov | 2010-08-23 00:27:59 +0100 |
| commit | 7133b7ee629457053e63db2a7f192037407da57b (patch) | |
| tree | 3f3fe53c4a3233abfa0aec4e4c64516627236e74 | |
| parent | 198a7a97ff99b96523f7c0736aa303d305595094 (diff) | |
| download | emacs-7133b7ee629457053e63db2a7f192037407da57b.tar.gz emacs-7133b7ee629457053e63db2a7f192037407da57b.zip | |
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).
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/simple.el | 34 | ||||
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/keyboard.c | 27 |
4 files changed, 49 insertions, 25 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9452ac294dd..c1fae3283ac 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2010-08-22 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * simple.el (read-extended-command): New function with the logic | ||
| 4 | for `completing-read' moved to Elisp from `execute-extended-command'. | ||
| 5 | Use `function-called-at-point' in `minibuffer-default-add-function' | ||
| 6 | to get a command name for M-n (bug#5364, bug#5214). | ||
| 7 | |||
| 1 | 2010-08-22 Chong Yidong <cyd@stupidchicken.com> | 8 | 2010-08-22 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 9 | ||
| 3 | * startup.el (command-line-1): Issue warning for ignored arguments | 10 | * 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." | |||
| 1301 | (if command-history | 1301 | (if command-history |
| 1302 | (error "Argument %d is beyond length of command history" arg) | 1302 | (error "Argument %d is beyond length of command history" arg) |
| 1303 | (error "There are no previous complex commands to repeat"))))) | 1303 | (error "There are no previous complex commands to repeat"))))) |
| 1304 | |||
| 1305 | (defun read-extended-command () | ||
| 1306 | "Read command name to invoke in `execute-extended-command'." | ||
| 1307 | (minibuffer-with-setup-hook | ||
| 1308 | (lambda () | ||
| 1309 | (set (make-local-variable 'minibuffer-default-add-function) | ||
| 1310 | (lambda () | ||
| 1311 | ;; Get a command name at point in the original buffer | ||
| 1312 | ;; to propose it after M-n. | ||
| 1313 | (with-current-buffer (window-buffer (minibuffer-selected-window)) | ||
| 1314 | (and (commandp (function-called-at-point)) | ||
| 1315 | (format "%S" (function-called-at-point))))))) | ||
| 1316 | ;; Read a string, completing from and restricting to the set of | ||
| 1317 | ;; all defined commands. Don't provide any initial input. | ||
| 1318 | ;; Save the command read on the extended-command history list. | ||
| 1319 | (completing-read | ||
| 1320 | (concat (cond | ||
| 1321 | ((eq current-prefix-arg '-) "- ") | ||
| 1322 | ((and (consp current-prefix-arg) | ||
| 1323 | (eq (car current-prefix-arg) 4)) "C-u ") | ||
| 1324 | ((and (consp current-prefix-arg) | ||
| 1325 | (integerp (car current-prefix-arg))) | ||
| 1326 | (format "%d " (car current-prefix-arg))) | ||
| 1327 | ((integerp current-prefix-arg) | ||
| 1328 | (format "%d " current-prefix-arg))) | ||
| 1329 | ;; This isn't strictly correct if `execute-extended-command' | ||
| 1330 | ;; is bound to anything else (e.g. [menu]). | ||
| 1331 | ;; It could use (key-description (this-single-command-keys)), | ||
| 1332 | ;; but actually a prompt other than "M-x" would be confusing, | ||
| 1333 | ;; because "M-x" is a well-known prompt to read a command | ||
| 1334 | ;; and it serves as a shorthand for "Extended command: ". | ||
| 1335 | "M-x ") | ||
| 1336 | obarray 'commandp t nil 'extended-command-history))) | ||
| 1337 | |||
| 1304 | 1338 | ||
| 1305 | (defvar minibuffer-history nil | 1339 | (defvar minibuffer-history nil |
| 1306 | "Default minibuffer history list. | 1340 | "Default minibuffer history list. |
diff --git a/src/ChangeLog b/src/ChangeLog index a1e67df99e2..624cddb6fa7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2010-08-22 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * keyboard.c (Fexecute_extended_command): Move reading a command name | ||
| 4 | with `completing-read' to a new Elisp function `read-extended-command'. | ||
| 5 | Call it to read a command to `function' (bug#5364, bug#5214). | ||
| 6 | |||
| 1 | 2010-08-22 Chong Yidong <cyd@stupidchicken.com> | 7 | 2010-08-22 Chong Yidong <cyd@stupidchicken.com> |
| 2 | 8 | ||
| 3 | * emacs.c (main): Remove handling of --unibyte arg (Bug#6886). | 9 | * emacs.c (main): Remove handling of --unibyte arg (Bug#6886). |
diff --git a/src/keyboard.c b/src/keyboard.c index 269e52988eb..b4a5d4e060f 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -10345,13 +10345,12 @@ give to the command you invoke, if it asks for an argument. */) | |||
| 10345 | (Lisp_Object prefixarg) | 10345 | (Lisp_Object prefixarg) |
| 10346 | { | 10346 | { |
| 10347 | Lisp_Object function; | 10347 | Lisp_Object function; |
| 10348 | char buf[40]; | ||
| 10349 | int saved_last_point_position; | 10348 | int saved_last_point_position; |
| 10350 | Lisp_Object saved_keys, saved_last_point_position_buffer; | 10349 | Lisp_Object saved_keys, saved_last_point_position_buffer; |
| 10351 | Lisp_Object bindings, value; | 10350 | Lisp_Object bindings, value; |
| 10352 | struct gcpro gcpro1, gcpro2, gcpro3; | 10351 | struct gcpro gcpro1, gcpro2, gcpro3; |
| 10353 | #ifdef HAVE_WINDOW_SYSTEM | 10352 | #ifdef HAVE_WINDOW_SYSTEM |
| 10354 | /* The call to Fcompleting_read wil start and cancel the hourglass, | 10353 | /* The call to Fcompleting_read will start and cancel the hourglass, |
| 10355 | but if the hourglass was already scheduled, this means that no | 10354 | but if the hourglass was already scheduled, this means that no |
| 10356 | hourglass will be shown for the actual M-x command itself. | 10355 | hourglass will be shown for the actual M-x command itself. |
| 10357 | So we restart it if it is already scheduled. Note that checking | 10356 | So we restart it if it is already scheduled. Note that checking |
| @@ -10364,31 +10363,9 @@ give to the command you invoke, if it asks for an argument. */) | |||
| 10364 | XVECTOR (this_command_keys)->contents); | 10363 | XVECTOR (this_command_keys)->contents); |
| 10365 | saved_last_point_position_buffer = last_point_position_buffer; | 10364 | saved_last_point_position_buffer = last_point_position_buffer; |
| 10366 | saved_last_point_position = last_point_position; | 10365 | saved_last_point_position = last_point_position; |
| 10367 | buf[0] = 0; | ||
| 10368 | GCPRO3 (saved_keys, prefixarg, saved_last_point_position_buffer); | 10366 | GCPRO3 (saved_keys, prefixarg, saved_last_point_position_buffer); |
| 10369 | 10367 | ||
| 10370 | if (EQ (prefixarg, Qminus)) | 10368 | function = call0 (intern ("read-extended-command")); |
| 10371 | strcpy (buf, "- "); | ||
| 10372 | else if (CONSP (prefixarg) && XINT (XCAR (prefixarg)) == 4) | ||
| 10373 | strcpy (buf, "C-u "); | ||
| 10374 | else if (CONSP (prefixarg) && INTEGERP (XCAR (prefixarg))) | ||
| 10375 | sprintf (buf, "%ld ", (long) XINT (XCAR (prefixarg))); | ||
| 10376 | else if (INTEGERP (prefixarg)) | ||
| 10377 | sprintf (buf, "%ld ", (long) XINT (prefixarg)); | ||
| 10378 | |||
| 10379 | /* This isn't strictly correct if execute-extended-command | ||
| 10380 | is bound to anything else. Perhaps it should use | ||
| 10381 | this_command_keys? */ | ||
| 10382 | strcat (buf, "M-x "); | ||
| 10383 | |||
| 10384 | /* Prompt with buf, and then read a string, completing from and | ||
| 10385 | restricting to the set of all defined commands. Don't provide | ||
| 10386 | any initial input. Save the command read on the extended-command | ||
| 10387 | history list. */ | ||
| 10388 | function = Fcompleting_read (build_string (buf), | ||
| 10389 | Vobarray, Qcommandp, | ||
| 10390 | Qt, Qnil, Qextended_command_history, Qnil, | ||
| 10391 | Qnil); | ||
| 10392 | 10369 | ||
| 10393 | #ifdef HAVE_WINDOW_SYSTEM | 10370 | #ifdef HAVE_WINDOW_SYSTEM |
| 10394 | if (hstarted) start_hourglass (); | 10371 | if (hstarted) start_hourglass (); |