Skip to content

Commit

Permalink
define keys with a keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
vindarel committed Mar 23, 2024
1 parent 815476b commit 277436a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions content/en/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Otherwise, be sure to refer to Lem functions with the `lem:` prefix.

## Binding keys

### `define-key`

Use the `define-key` function:

~~~lisp
Expand All @@ -29,6 +31,8 @@ the autocompletion), and for every other tool: there is a keymap for
`grep` mode, for the directory mode, for the different vi mode states,
etc.

### `define-keys`

You can also use `lem:define-keys` to define more than one key at once:

~~~lisp
Expand All @@ -41,6 +45,40 @@ You can also use `lem:define-keys` to define more than one key at once:
("C-a f" 'lem-lisp-mode:lisp-describe-symbol))
~~~

But wait, there is more.

### Defining a keymap

Did you notice that all the above commands have
the `C-a` prefix? We can refactor this.

First, we define a keymap object. Let's take another example, the
frame-multiplexer (aka tabs):

~~~lisp
(defvar *keymap*
(make-keymap :name '*frame-multiplexer-keymap*)
"Keymap for commands related to the frame-multiplexer.")
~~~

Now we can use `(define-key *keymap* key command)` (singular), like this:

~~~lisp
(define-key *keymap* "c" 'frame-multiplexer-create-with-new-buffer-list)
(define-key *keymap* "d" 'frame-multiplexer-delete)
(define-key *keymap* "p" 'frame-multiplexer-prev)
(define-key *keymap* "n" 'frame-multiplexer-next)
(define-key *keymap* "r" 'frame-mulitplexer-rename)
~~~

And now we can define the prefix key for our keymap and all its sub-keys commands:

~~~lisp
(define-key *global-keymap* "C-z" *keymap*)
~~~

As a result, we defined `C-z c` for `'frame-mulitplexer-create-with-new-buffer-list`.


## Writing one's own commands

Expand Down

0 comments on commit 277436a

Please sign in to comment.