unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Sean McAfee <eefacm@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Preferred way to add commands to a foreign keymap?
Date: Thu, 16 Sep 2010 17:36:38 -0700	[thread overview]
Message-ID: <m262y5xl2h.fsf@gmail.com> (raw)

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?


             reply	other threads:[~2010-09-17  0:36 UTC|newest]

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

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=m262y5xl2h.fsf@gmail.com \
    --to=eefacm@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).