help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to build a conditional keymap?


From: Andreas Politz
Subject: Re: How to build a conditional keymap?
Date: Sat, 06 Dec 2008 15:49:17 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]