unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Preferred way to add commands to a foreign keymap?
Date: Fri, 17 Sep 2010 12:37:36 -0700 (PDT)	[thread overview]
Message-ID: <790e4851-3577-446e-a1a0-6b0e9bb014e9@u5g2000prn.googlegroups.com> (raw)
In-Reply-To: m262y5xl2h.fsf@gmail.com

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	other threads:[~2010-09-17 19:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-17  0:36 Preferred way to add commands to a foreign keymap? Sean McAfee
2010-09-17 19:37 ` Xah Lee [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=790e4851-3577-446e-a1a0-6b0e9bb014e9@u5g2000prn.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
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).