[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Menu commands to M-x history?

From: Lennart Borgman
Subject: Re: Menu commands to M-x history?
Date: Mon, 3 Aug 2009 23:51:57 +0200

On Tue, Jul 21, 2009 at 5:31 PM, Stefan Monnier<address@hidden> wrote:
>> Menu commands are all commands that can be started from M-x.  I think
>> they should be added to M-x history.
> Most of them should have a key shortcut anyway, which the user has seen
> in the menu entry.

I think that is impossible. And many times it is not useful (as has
been discussed for rgrep/lgrep).

> 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 Emac
and have a lot to learn.

I have added a simple recipe for my initial suggestion to nXhtml, see
below. A message is shown (if appropriate) when a command is added to
M-x history. If you want to, just include it in Emacs.

(defun ourcomments-M-x-menu-pre ()
  "Add menu command to M-x history."
  (let ((is-menu-command (equal '(menu-bar)
                                (elt (this-command-keys-vector) 0)))
        (pre-len (length extended-command-history)))
    (when (and is-menu-command
               (not (memq this-command '(ourcomments-M-x-menu-mode))))
      (pushnew (symbol-name this-command) extended-command-history)
      (when (< pre-len (length extended-command-history))
        ;; This message is given pre-command and is therefore likely
        ;; to be overwritten, but that is ok in this case. If the user
        ;; has seen one of these messages s?he knows.
        (message "(Added %s to M-x history so you can run it from
there)" this-command)))))

(define-minor-mode ourcomments-M-x-menu-mode
  "Add commands started from Emacs menus to M-x history.
The purpose of this is to make it easier to redo them and easier
to learn how to do them from the command line \(which is often
faster if you know how to do it).

Only commands that are not already in M-x history are added."
  :global t
  (if ourcomments-M-x-menu-mode
      (add-hook 'pre-command-hook 'ourcomments-M-x-menu-pre)
    (remove-hook 'pre-command-hook 'ourcomments-M-x-menu-pre)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]