[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sillyness (was: Menu commands to M-x history?)
From: |
Stefan Monnier |
Subject: |
Sillyness (was: Menu commands to M-x history?) |
Date: |
Tue, 04 Aug 2009 13:31:11 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
>> For those entries which don't have a keyboard shortcut, maybe we could
>> (along the lines of what M-x does) output a message like "You can run
>> this command with M-x foo-bar-baz".
> I do not think that will work. Those messages will very often be
> hidden. And you will forget them - especially if you are new to Emacs
> and have a lot to learn.
Clearly they're more discrete (thus easier to forget or fail to notice),
but they should almost never be hidden.
BTW, on an unrelated note, here is a piece of useless code that some
people who like partial-completion-mode may find funny. It told me
You can run `gnus-read-ephemeral-emacs-bug-group' with M-x -r-em RET
-- Stefan
--- src/keyboard.c 2009-07-03 17:07:02 +0000
+++ src/keyboard.c 2009-07-24 18:45:56 +0000
@@ -10528,6 +10322,7 @@
+/* FIXME: Move to Elisp. */
DEFUN ("execute-extended-command", Fexecute_extended_command,
Sexecute_extended_command,
1, 1, "P",
doc: /* Read function name, then read its arguments and call it.
@@ -10637,7 +10432,10 @@
value = Fcommand_execute (function, Qt, Qnil, Qnil);
/* If the command has a key binding, print it now. */
- if (!NILP (bindings)
+ if (SYMBOLP (Vsuggest_key_bindings)
+ && !NILP (Ffboundp (Vsuggest_key_bindings)))
+ call2 (Vsuggest_key_bindings, function, bindings);
+ else if (!NILP (bindings)
&& ! (VECTORP (bindings) && EQ (Faref (bindings, make_number (0)),
Qmouse_movement)))
{
and then
(defun suggest-key-binding-1 (name length)
(cond
((zerop length) (list ""))
((equal name "") nil)
(t
(nconc (mapcar (lambda (s) (concat (substring name 0 1) s))
(suggest-key-binding-1 (substring name 1) (1- length)))
(when (string-match "\\`\\(-\\)?[^-]*" name)
(suggest-key-binding-1 (substring name (match-end 0)) length))))))
(defun suggest-key-binding (cmd binding)
(unless (or binding executing-kbd-macro (not (symbolp cmd))
(<= (length (symbol-name cmd)) 2))
;; There's no binding for CMD. Let's try and find the shortest
;; string to use in M-x.
(let ((name (symbol-name cmd))
(candidates '())
(len 1))
(while (not binding)
(unless candidates
(setq len (1+ len))
(setq candidates (suggest-key-binding-1 name len)))
(let ((candidate (pop candidates)))
(when (equal name
(car-safe (completion-try-completion
candidate obarray 'commandp len)))
(setq binding candidate))))))
(when (and binding
(sit-for (if (current-message) 2 0))
(null unread-command-events))
(let ((msg (current-message))
(message-log-max nil))
(message "You can run the command `%s' with %s"
cmd (if (stringp binding)
(concat "M-x " binding " RET")
(key-description binding)))
(when (and (sit-for 2) msg)
(message msg)))))
(setq suggest-key-bindings 'suggest-key-binding)