* key binding only for minor mode
@ 2009-08-28 2:01 Ryo Furue
2009-08-28 5:37 ` Ivan Kanis
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ryo Furue @ 2009-08-28 2:01 UTC (permalink / raw)
To: help-gnu-emacs
Hi emacs users,
I'm quite new to emacs lisp and using it in a learn-as-you-go way.
I'm now trying to disable C-x C-q (normally bound to toggle-read-only)
in the view mode, but I haven't been entirely successful. So far,
I've
been using local-set-key in the view-mode-hook:
(add-hook 'view-mode-hook
(lambda ()
(local-set-key "\C-x\C-q"
(lambda () (interactive) (message "C-x C-q disabled.") (ding)))))
which woks---until you toggle off the view-mode by "M-x view-mode".
Once
I exit from the view mode, I want C-x C-q back, but the key binding is
still
disabled. As I understand, the code above doesn't quite work because
the view mode isn't a major mode. (local-set-key is local to the
major
mode, if I understand it correctly.)
So, my question is how to solve this problem? What's the standard
procedure
to disable keys for a minor mode?
Thank you for your attention,
Ryo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key binding only for minor mode
2009-08-28 2:01 key binding only for minor mode Ryo Furue
@ 2009-08-28 5:37 ` Ivan Kanis
2009-08-28 6:14 ` Teemu Likonen
[not found] ` <mailman.5564.1251441387.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 6+ messages in thread
From: Ivan Kanis @ 2009-08-28 5:37 UTC (permalink / raw)
To: Ryo Furue; +Cc: help-gnu-emacs
Ryo Furue <furue@hawaii.edu> wrote:
> (add-hook 'view-mode-hook
> (lambda ()
> (local-set-key "\C-x\C-q"
> (lambda () (interactive) (message "C-x C-q disabled.") (ding)))))
Nested lambda, nice going!
> So, my question is how to solve this problem? What's the standard
> procedure to disable keys for a minor mode?
Find the keymap for view-mode and set the key to nil.
(add-hook 'view-mode-hook
(lambda () (define-key view-mode-map (kbd "C-x C-q") nil)))
Kind regards,
--
Ivan
Kanis http://kanis.fr
In a room full of top software designers, if any two of them agree,
that is a majority.
-- Bill Curtis
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key binding only for minor mode
2009-08-28 2:01 key binding only for minor mode Ryo Furue
2009-08-28 5:37 ` Ivan Kanis
@ 2009-08-28 6:14 ` Teemu Likonen
[not found] ` <mailman.5564.1251441387.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 6+ messages in thread
From: Teemu Likonen @ 2009-08-28 6:14 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-08-27 19:01 (-0700), Ryo Furue wrote:
> I'm now trying to disable C-x C-q (normally bound to toggle-read-only)
> in the view mode, but I haven't been entirely successful. So far, I've
> been using local-set-key in the view-mode-hook:
>
> (add-hook 'view-mode-hook
> (lambda ()
> (local-set-key "\C-x\C-q"
> (lambda () (interactive) (message "C-x C-q disabled.") (ding)))))
>
> which woks---until you toggle off the view-mode by "M-x view-mode".
It's better to change the needed keymap (i.e., view-mode-map) directly:
(add-hook 'view-mode-hook #'my-view-mode-hook)
(defun my-view-mode-hook ()
(define-key view-mode-map (kbd "C-x C-q")
#'(lambda ()
(interactive)
(message "C-x C-q is disabled")
(ding))))
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.5564.1251441387.2239.help-gnu-emacs@gnu.org>]
* Re: key binding only for minor mode
[not found] ` <mailman.5564.1251441387.2239.help-gnu-emacs@gnu.org>
@ 2009-08-29 0:05 ` Ryo Furue
2009-08-29 8:04 ` Bernardo
[not found] ` <mailman.5621.1251533091.2239.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 6+ messages in thread
From: Ryo Furue @ 2009-08-29 0:05 UTC (permalink / raw)
To: help-gnu-emacs
Thank you, Teemu and Ivan. Your solutions work. Except . . .
On Aug 27, 7:37 pm, Ivan Kanis <expire-by-2009-09...@kanis.fr> wrote:
> > So, my question is how to solve this problem? What's the standard
> > procedure to disable keys for a minor mode?
>
> Find the keymap for view-mode and set the key to nil.
>
> (add-hook 'view-mode-hook
> (lambda () (define-key view-mode-map (kbd "C-x C-q") nil)))
This one doesn't appear to have any effect. I guess: This one removes
the key C-x C-q from the local keymap (view-mode-map). Therefore,
when you pressthe key combination, the global binding is invoked which
is toggle-read-only. So, I guess we have to bind C-x C-q to something
rather than to undefine it, as in Teemu's example.
By the way, I'm wondering what #' is. I vaguely know what a single
quote means (quote or don't evaluate it now) but I don't remember
seeing #' . I tried the official emacs lisp reference manual, but
unless I read it from the top, I wouldn't find it. (Google isn't of
much use when you want to search for something like '# . . . ).
Anyway, I'm completely happy with the solution you showed.
Thanks again,
Ryo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: key binding only for minor mode
2009-08-29 0:05 ` Ryo Furue
@ 2009-08-29 8:04 ` Bernardo
[not found] ` <mailman.5621.1251533091.2239.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 6+ messages in thread
From: Bernardo @ 2009-08-29 8:04 UTC (permalink / raw)
To: help-gnu-emacs
Ryo Furue said the following on 29/08/09 10:05:
>
> By the way, I'm wondering what #' is. I vaguely know what a single
> quote means (quote or don't evaluate it now) but I don't remember
> seeing #' . I tried the official emacs lisp reference manual, but
> unless I read it from the top, I wouldn't find it. (Google isn't of
> much use when you want to search for something like '# . . . ).
>
look up (info "(elisp)Anonymous Functions")
(or "Quoting" where this is linked from)
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <mailman.5621.1251533091.2239.help-gnu-emacs@gnu.org>]
* Re: key binding only for minor mode
[not found] ` <mailman.5621.1251533091.2239.help-gnu-emacs@gnu.org>
@ 2009-09-01 19:10 ` Ryo Furue
0 siblings, 0 replies; 6+ messages in thread
From: Ryo Furue @ 2009-09-01 19:10 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 28, 10:04 pm, Bernardo <bernardo.ba...@pobox.com> wrote:
> Ryo Furue said the following on 29/08/09 10:05:
[. . .]
> > By the way, I'm wondering what #' is. I vaguely know what a single
> > quote means (quote or don't evaluate it now) but I don't remember
> > seeing #' . I tried the official emacs lisp reference manual, but
> > unless I read it from the top, I wouldn't find it. (Google isn't of
> > much use when you want to search for something like '# . . . ).
>
> look up (info "(elisp)Anonymous Functions")
Thank you! That info page explains it clearly.
Cheers,
Ryo
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-09-01 19:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-28 2:01 key binding only for minor mode Ryo Furue
2009-08-28 5:37 ` Ivan Kanis
2009-08-28 6:14 ` Teemu Likonen
[not found] ` <mailman.5564.1251441387.2239.help-gnu-emacs@gnu.org>
2009-08-29 0:05 ` Ryo Furue
2009-08-29 8:04 ` Bernardo
[not found] ` <mailman.5621.1251533091.2239.help-gnu-emacs@gnu.org>
2009-09-01 19:10 ` Ryo Furue
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).