From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Preferred way to add commands to a foreign keymap? Date: Fri, 17 Sep 2010 12:37:36 -0700 (PDT) Organization: http://groups.google.com Message-ID: <790e4851-3577-446e-a1a0-6b0e9bb014e9@u5g2000prn.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291867634 3995 80.91.229.12 (9 Dec 2010 04:07:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 04:07:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 05:07:10 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQXmg-00031l-AE for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 05:07:10 +0100 Original-Received: from localhost ([127.0.0.1]:50132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQXmf-0007GX-NI for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 23:07:09 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!u5g2000prn.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 36 Original-NNTP-Posting-Host: 67.180.85.8 Original-X-Trace: posting.google.com 1284752256 27213 127.0.0.1 (17 Sep 2010 19:37:36 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 17 Sep 2010 19:37:36 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u5g2000prn.googlegroups.com; posting-host=67.180.85.8; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.59 Safari/534.3, gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:181359 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76610 Archived-At: On Sep 16, 5:36=A0pm, Sean McAfee wrote: > I want to add the following command to Dired mode: > > (defun mac-open-files (arg) > =A0 (interactive "P") > =A0 (dired-do-shell-command "/usr/bin/open" arg (dired-get-marked-files))= ) > > I can think of two ways to do it: > > 1. =A0Twiddle dired-mode's keymap directly: > > =A0 =A0 (define-key dired-mode-map [(super o)] 'mac-open-files) > > 2. =A0Use local-set-key in a hook: > > =A0 =A0 (add-hook 'dired-mode-hook > =A0 =A0 =A0 =A0 =A0 =A0 =A0 (lambda () (local-set-key [(super o)] 'mac-op= en-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? =A0O= r > 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