all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 5364@debbugs.gnu.org, jidanni@jidanni.org
Subject: bug#5364: 23.1.91; execute-extended-command should do like FFAP
Date: Fri, 15 Jan 2010 03:12:05 +0200	[thread overview]
Message-ID: <87wrzki0zy.fsf@mail.jurta.org> (raw)
In-Reply-To: <jwv8wc0wbzj.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 14 Jan 2010 17:40:42 -0500")

> The behavior is OK, but the implementation sucks too much.  I think we
> can do better via minibuffer-with-setup-hook.  That might require to
> turn M-x's interactive spec into Elisp (moving the whole of M-x to Elisp
> would be good as well, but it's a much bigger effort).

This patch moves interactive spec into Elisp and also implements
the following task from comments in execute-extended-command:

  /* This isn't strictly correct if execute-extended-command
     is bound to anything else.  Perhaps it should use
     this_command_keys?  */

It uses `(key-description (this-single-command-keys))' to do this.

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2010-01-13 08:35:10 +0000
+++ src/keyboard.c	2010-01-15 01:09:18 +0000
@@ -10512,7 +10512,30 @@
 
 \f
 DEFUN ("execute-extended-command", Fexecute_extended_command, Sexecute_extended_command,
-       1, 1, "P",
+       2, 2,
+       "(list current-prefix-arg \
+    (minibuffer-with-setup-hook \
+        (lambda () \
+          (set (make-local-variable 'minibuffer-default-add-function) \
+               (lambda () \
+                 (with-current-buffer (window-buffer \
+                                       (minibuffer-selected-window)) \
+                   (and (commandp (function-called-at-point)) \
+                        (format \"%S\" (function-called-at-point))))))) \
+      (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))) \
+                        (key-description (this-single-command-keys)) \
+                        \" \") \
+                       obarray 'commandp t nil \
+                       'extended-command-history)))",
        doc: /* Read function name, then read its arguments and call it.
 
 To pass a numeric argument to the command you are invoking with, specify
@@ -10520,11 +10543,9 @@ (at your option) any later version.
 
 Noninteractively, the argument PREFIXARG is the prefix argument to
 give to the command you invoke, if it asks for an argument.  */)
-     (prefixarg)
-     Lisp_Object prefixarg;
+     (prefixarg, function)
+     Lisp_Object prefixarg, function;
 {
-  Lisp_Object function;
-  char buf[40];
   int saved_last_point_position;
   Lisp_Object saved_keys, saved_last_point_position_buffer;
   Lisp_Object bindings, value;
@@ -10543,32 +10564,8 @@ (at your option) any later version.
 			XVECTOR (this_command_keys)->contents);
   saved_last_point_position_buffer = last_point_position_buffer;
   saved_last_point_position = last_point_position;
-  buf[0] = 0;
   GCPRO3 (saved_keys, prefixarg, saved_last_point_position_buffer);
 
-  if (EQ (prefixarg, Qminus))
-    strcpy (buf, "- ");
-  else if (CONSP (prefixarg) && XINT (XCAR (prefixarg)) == 4)
-    strcpy (buf, "C-u ");
-  else if (CONSP (prefixarg) && INTEGERP (XCAR (prefixarg)))
-    sprintf (buf, "%ld ", (long) XINT (XCAR (prefixarg)));
-  else if (INTEGERP (prefixarg))
-    sprintf (buf, "%ld ", (long) XINT (prefixarg));
-
-  /* This isn't strictly correct if execute-extended-command
-     is bound to anything else.  Perhaps it should use
-     this_command_keys?  */
-  strcat (buf, "M-x ");
-
-  /* Prompt with buf, and then 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. */
-  function = Fcompleting_read (build_string (buf),
-			       Vobarray, Qcommandp,
-			       Qt, Qnil, Qextended_command_history, Qnil,
-			       Qnil);
-
 #ifdef HAVE_WINDOW_SYSTEM
   if (hstarted) start_hourglass ();
 #endif

-- 
Juri Linkov
http://www.jurta.org/emacs/






  reply	other threads:[~2010-01-15  1:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-12 12:52 bug#5364: 23.1.91; execute-extended-command should do like FFAP jidanni
2010-01-12 20:54 ` Juri Linkov
2010-01-12 22:46   ` jidanni
2010-01-13  0:32     ` Juri Linkov
2010-01-13  1:17       ` jidanni
2010-01-13  1:21     ` Stefan Monnier
2010-01-13  2:00       ` jidanni
2010-01-13  4:12         ` Stefan Monnier
2010-01-14  3:33           ` jidanni
2010-01-14 15:12             ` Stefan Monnier
2010-01-14 21:07               ` Juri Linkov
2010-01-14 22:40                 ` Stefan Monnier
2010-01-15  1:12                   ` Juri Linkov [this message]
2010-01-15  2:20                     ` Stefan Monnier
2010-01-15  3:06                       ` Chong Yidong
2010-01-15  7:49                         ` Stefan Monnier
2010-01-15  9:19                       ` Juri Linkov
2010-08-22 23:32                     ` Juri Linkov
2010-01-13  7:26   ` Jan D.
2010-01-14  5:29     ` jidanni
2010-01-14 21:01       ` Juri Linkov
2010-01-15  3:04 ` jidanni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wrzki0zy.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=5364@debbugs.gnu.org \
    --cc=jidanni@jidanni.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.