* Preferred way to add commands to a foreign keymap?
@ 2010-09-17 0:36 Sean McAfee
2010-09-17 19:37 ` Xah Lee
0 siblings, 1 reply; 2+ messages in thread
From: Sean McAfee @ 2010-09-17 0:36 UTC (permalink / raw)
To: help-gnu-emacs
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?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Preferred way to add commands to a foreign keymap?
2010-09-17 0:36 Preferred way to add commands to a foreign keymap? Sean McAfee
@ 2010-09-17 19:37 ` Xah Lee
0 siblings, 0 replies; 2+ messages in thread
From: Xah Lee @ 2010-09-17 19:37 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-09-17 19:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-17 0:36 Preferred way to add commands to a foreign keymap? Sean McAfee
2010-09-17 19:37 ` Xah Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).