[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Interactive Keymaps

Interactive keymaps are a special type of command that basically pushes another keymap on top of the current one. The new keymap will only be removed after an exit command is run. An example is iresize.

The macro define-interactive-keymap is used to define an interactive keymap. The first argument is the same as defcommand. The second argument is a list of extra configurations that can be used for controlling the command and the rest are the key bindings for the new command.

For instance, a simple interactive keymap:

 
(define-interactive-keymap my-new-command nil
  ((kbd "a") "execute-a-command")
  ((kbd "b") "execute-b-command"))

This creates a command called my-new-command that, when called, will activate the interactive keymap mode. In this mode, the user can press “a” or “b” repeatedly, omitting any prefix. The default exit commands are RET, C-g and ESC.

The available configuration is on-enter, on-exit and abort-if:

 
(defun before-foo () (message "start foo"))
(defun after-foo () (message "end foo"))
(defun foo-p () (and *bar* *bhaz*))

(define-interactive-keymap foo (:on-enter #'before-foo
                                :on-exit #'after-foo
                                :abort-if #'foo-p))

In the above example, the message “start foo” will appear before starting the interactive keymap, “end foo” will appear right after the command exits. Also, the command executes only if the variables *bar* and *bhaz* are true.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on January 28, 2024 using texi2html 1.82.