help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Preferred way to add commands to a foreign keymap?


From: Xah Lee
Subject: Re: Preferred way to add commands to a foreign keymap?
Date: Wed, 08 Dec 2010 15:28:52 -0000
User-agent: G2/1.0

On Sep 16, 5:36 pm, Sean McAfee <eef...@gmail.com> wrote:
> I want to add the following command to Dired mode:
>
> (defun mac-open-files (arg)
>   (interactive "P")
>   (dired-do-shell-command "/usr/bin/open" arg (dired-get-marked-files)))
>
> I can think of two ways to do it:
>
> 1.  Twiddle dired-mode's keymap directly:
>
>     (define-key dired-mode-map [(super o)] 'mac-open-files)
>
> 2.  Use local-set-key in a hook:
>
>     (add-hook 'dired-mode-hook
>               (lambda () (local-set-key [(super o)] 'mac-open-files)
>
> #1 seems like the (very, very slightly) more efficient appoach, but I
> worry that I'm potentially trampling on a dired-mode implementation
> detail.
>
> Is there any practical reason to prefer one approach over the other?  Or
> is there another way?

don't think it matters practically speaking.
The latter is probably better, since it's more general n more higher
level.

The first solution you have to be sure the mode is loaded first, in
the case of dired i think it's always loaded when emacs starts.

 Xah


reply via email to

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