From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: elisp programming questions Date: Thu, 25 Oct 2012 05:24:35 -0400 Organization: A noiseless patient Spider Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1351157420 2172 80.91.229.3 (25 Oct 2012 09:30:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Oct 2012 09:30:20 +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 Oct 25 11:30:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TRJlk-0003ZG-4K for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Oct 2012 11:30:28 +0200 Original-Received: from localhost ([::1]:40928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TRJlY-0004Xv-MF for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Oct 2012 05:30:16 -0400 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news1.as3257.net!feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 68 Injection-Info: barmar.motzarella.org; posting-host="78fb7125a45724f15e21604c94a7d968"; logging-data="11629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1905AgjYNPBmeNCqI+c56T8" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:pb3MC51INvqVXGoVbCeWL2JD+uE= Original-Xref: usenet.stanford.edu gnu.emacs.help:195090 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87419 Archived-At: In article , Evan Driscoll wrote: > I have a question: I'm working on a (major) mode, and when I make > changes to the keymap, they don't "stick" until I restart emacs. It'd > be nice to know how to fix this, but as I was typing it, I realized > there may be a better way to solve this problem anyway; see below. > > To demo my problem: > > 1. Save the code below to a file, open in emacs > 2. M-x eval-buffer > 3. M-x say-hi-mode > 4. Press [left]; note how the minibuffer says hi > Press [right]; note how the cursor moves > 5. M-x revert-buffer > 6. Uncomment the second define-key on line 8 > 7. M-x eval-buffer > 8. Repeat steps 3 and 4. Note how [right] still > moves the cursor instead of saying hi > > Can someone tell me if there's a way to make the changes take effect? > > ----- > > ALTERNATELY: is there some hook or something I can use which will get > called whenever (after) the point is moved by any means? I will be > overriding the cursor controls, but really what I want is just to > display some stuff related to the point's new location, and ideally it'd > work whether the user uses arrow keys, C-p/C-n/etc., the mouse, or > anything else. > > Thanks, > Evan > > ----- > > The code: > > (defun say-hi () > (interactive) > (message "Hello!")) > > (defvar say-hi-mode-map > (let ((map (make-keymap))) > (define-key map [left] 'say-hi) > ;;(define-key map [right] 'say-hi) > map > )) DEFVAR only assigns the variable if it doesn't already have a value. So when you run it the second time, it doesn't do anything because the variable is already initialized. Change it to: (defvar say-hi-mode-map (make-keymap)) (define-key map [left] 'say-hi) (define-key map [right] 'say-hi) > > (define-derived-mode say-hi-mode > special-mode "Trace" > "Major mode for viewing IO traces" > (use-local-map say-hi-mode-map)) -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***