* elisp programming questions
@ 2012-10-25 4:39 Evan Driscoll
0 siblings, 0 replies; 4+ messages in thread
From: Evan Driscoll @ 2012-10-25 4:39 UTC (permalink / raw
To: help-gnu-emacs
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
))
(define-derived-mode say-hi-mode
special-mode "Trace"
"Major mode for viewing IO traces"
(use-local-map say-hi-mode-map))
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp programming questions
[not found] <mailman.11660.1351139989.855.help-gnu-emacs@gnu.org>
@ 2012-10-25 9:24 ` Barry Margolin
2012-10-29 14:21 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Barry Margolin @ 2012-10-25 9:24 UTC (permalink / raw
To: help-gnu-emacs
In article <mailman.11660.1351139989.855.help-gnu-emacs@gnu.org>,
Evan Driscoll <driscoll@cs.wisc.edu> 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 ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp programming questions
2012-10-25 9:24 ` elisp programming questions Barry Margolin
@ 2012-10-29 14:21 ` Stefan Monnier
2012-11-03 3:18 ` Pascal J. Bourguignon
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2012-10-29 14:21 UTC (permalink / raw
To: help-gnu-emacs
>> (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.
That's right.
> Change it to:
> (defvar say-hi-mode-map (make-keymap))
> (define-key map [left] 'say-hi)
> (define-key map [right] 'say-hi)
No, this is bad style. Instead, just use C-M-x with point within
the defvar (or use defconst).
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: elisp programming questions
2012-10-29 14:21 ` Stefan Monnier
@ 2012-11-03 3:18 ` Pascal J. Bourguignon
0 siblings, 0 replies; 4+ messages in thread
From: Pascal J. Bourguignon @ 2012-11-03 3:18 UTC (permalink / raw
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> (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.
>
> That's right.
I use defparameter instead.
(defmacro defparameter (symbol &optional initvalue docstring)
`(progn
(defvar ,symbol nil ,docstring)
(setq ,symbol ,initvalue)))
--
__Pascal Bourguignon__
http://www.informatimago.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-03 3:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.11660.1351139989.855.help-gnu-emacs@gnu.org>
2012-10-25 9:24 ` elisp programming questions Barry Margolin
2012-10-29 14:21 ` Stefan Monnier
2012-11-03 3:18 ` Pascal J. Bourguignon
2012-10-25 4:39 Evan Driscoll
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.