* How to build a conditional keymap?
@ 2008-12-05 10:06 rejeep
2008-12-06 6:43 ` Ian Eure
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: rejeep @ 2008-12-05 10:06 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I'm trying to create a minor mode. But I get stuck on the mode-map.
I'm trying to set the keybindings depending on some condition.
I created this minor example to illustrate what I've tried to do so
far.
(defvar mm-minor-mode-map (make-sparse-keymap)
"...")
(defun mm-a()
(interactive)
(print "a"))
(defun mm-b()
(interactive)
(print "b"))
(defun mm-keys()
(define-key mm-minor-mode-map "\C-n" 'mm-a)
(if (< 3 -1)
(define-key mm-minor-mode-map "\C-m" 'mm-b))
mm-minor-mode-map)
;;;###autoload
(define-minor-mode mm-mode
"..."
:init-value nil
:lighter " ..."
:keymap (mm-keys))
;;;###autoload
(provide 'mm)
But this will not work. So basically my question is: How do I best
build a conditional keymap?
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to build a conditional keymap?
2008-12-05 10:06 How to build a conditional keymap? rejeep
@ 2008-12-06 6:43 ` Ian Eure
[not found] ` <mailman.2040.1228545839.26697.help-gnu-emacs@gnu.org>
2008-12-06 14:49 ` Andreas Politz
2 siblings, 0 replies; 5+ messages in thread
From: Ian Eure @ 2008-12-06 6:43 UTC (permalink / raw)
To: rejeep; +Cc: help-gnu-emacs
On Dec 5, 2008, at 2:06 AM, rejeep wrote:
> Hi,
>
> I'm trying to create a minor mode. But I get stuck on the mode-map.
> I'm trying to set the keybindings depending on some condition.
>
> But this will not work. So basically my question is: How do I best
> build a conditional keymap?
>
What's wrong with:
(define-key mm-minor-mode-map "\C-m" 'mm-b))
(defun mm-b ()
(interactive)
(and (< 3 -1) (print "b")))
- Ian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to build a conditional keymap?
[not found] ` <mailman.2040.1228545839.26697.help-gnu-emacs@gnu.org>
@ 2008-12-06 9:16 ` rejeep
0 siblings, 0 replies; 5+ messages in thread
From: rejeep @ 2008-12-06 9:16 UTC (permalink / raw)
To: help-gnu-emacs
On Dec 6, 7:43 am, Ian Eure <i...@digg.com> wrote:
> On Dec 5, 2008, at 2:06 AM, rejeep wrote:
>
> > Hi,
>
> > I'm trying to create a minor mode. But I get stuck on the mode-map.
> > I'm trying to set the keybindings depending on some condition.
>
> > But this will not work. So basically my question is: How do I best
> > build a conditional keymap?
>
> What's wrong with:
>
> (define-key mm-minor-mode-map "\C-m" 'mm-b))
> (defun mm-b ()
> (interactive)
> (and (< 3 -1) (print "b")))
>
> - Ian
That will still bind C-m to mm-b. The condition is to decide whether
or not the binding should be set. So if the condition is true I want C-
m to be set to mm-b. But if it's false I don't want C-m to change.
Sorry if I was unclear about that!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to build a conditional keymap?
2008-12-05 10:06 How to build a conditional keymap? rejeep
2008-12-06 6:43 ` Ian Eure
[not found] ` <mailman.2040.1228545839.26697.help-gnu-emacs@gnu.org>
@ 2008-12-06 14:49 ` Andreas Politz
2008-12-06 15:39 ` rejeep
2 siblings, 1 reply; 5+ messages in thread
From: Andreas Politz @ 2008-12-06 14:49 UTC (permalink / raw)
To: help-gnu-emacs
rejeep wrote:
> Hi,
>
> I'm trying to create a minor mode. But I get stuck on the mode-map.
> I'm trying to set the keybindings depending on some condition.
>
> I created this minor example to illustrate what I've tried to do so
> far.
>
> (defvar mm-minor-mode-map (make-sparse-keymap)
> "...")
>
The keymap should be named MODE-map.
> (defun mm-a()
> (interactive)
> (print "a"))
>
> (defun mm-b()
> (interactive)
> (print "b"))
>
> (defun mm-keys()
> (define-key mm-minor-mode-map "\C-n" 'mm-a)
> (if (< 3 -1)
> (define-key mm-minor-mode-map "\C-m" 'mm-b))
> mm-minor-mode-map)
>
> ;;;###autoload
> (define-minor-mode mm-mode
> "..."
> :init-value nil
> :lighter " ..."
> :keymap (mm-keys))
> ;;;###autoload
>
> (provide 'mm)
>
> But this will not work. So basically my question is: How do I best
> build a conditional keymap?
>
> Thanks!
(define-minor-mode mm-mode
"..."
:init-value nil
:lighter " ..."
:keymap mm-minor-mode-map
(if mm-mode
(setq mm-minor-mode-map (mm-keys))))
-ap
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to build a conditional keymap?
2008-12-06 14:49 ` Andreas Politz
@ 2008-12-06 15:39 ` rejeep
0 siblings, 0 replies; 5+ messages in thread
From: rejeep @ 2008-12-06 15:39 UTC (permalink / raw)
To: help-gnu-emacs
On Dec 6, 3:49 pm, Andreas Politz <poli...@fh-trier.de> wrote:
> rejeep wrote:
> > Hi,
>
> > I'm trying to create a minor mode. But I get stuck on the mode-map.
> > I'm trying to set the keybindings depending on some condition.
>
> > I created this minor example to illustrate what I've tried to do so
> > far.
>
> > (defvar mm-minor-mode-map (make-sparse-keymap)
> > "...")
>
> The keymap should be named MODE-map.
>
>
>
> > (defun mm-a()
> > (interactive)
> > (print "a"))
>
> > (defun mm-b()
> > (interactive)
> > (print "b"))
>
> > (defun mm-keys()
> > (define-key mm-minor-mode-map "\C-n" 'mm-a)
> > (if (< 3 -1)
> > (define-key mm-minor-mode-map "\C-m" 'mm-b))
> > mm-minor-mode-map)
>
> > ;;;###autoload
> > (define-minor-mode mm-mode
> > "..."
> > :init-value nil
> > :lighter " ..."
> > :keymap (mm-keys))
> > ;;;###autoload
>
> > (provide 'mm)
>
> > But this will not work. So basically my question is: How do I best
> > build a conditional keymap?
>
> > Thanks!
>
> (define-minor-mode mm-mode
> "..."
> :init-value nil
> :lighter " ..."
> :keymap mm-minor-mode-map
> (if mm-mode
> (setq mm-minor-mode-map (mm-keys))))
>
> -ap
Ahh, I see. Thanks Andreas!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-12-06 15:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-05 10:06 How to build a conditional keymap? rejeep
2008-12-06 6:43 ` Ian Eure
[not found] ` <mailman.2040.1228545839.26697.help-gnu-emacs@gnu.org>
2008-12-06 9:16 ` rejeep
2008-12-06 14:49 ` Andreas Politz
2008-12-06 15:39 ` rejeep
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).