Skip to content
Batuhan Basmaz Ölmez edited this page May 13, 2023 · 2 revisions

Prefix keys with user mode local key sequence

With following code, I can bind keys to mode maps without specifying a prefix key and all will be under my local-leader-prefix, unless an optional key is given.

  (defvar local-leader-prefix "C-c")

  (defun keys-make-local-prefix (&optional key)
    (concat local-leader-prefix (if key " ") key))

  (defun bind-local (&optional key &rest bindings)
    (declare (indent 1))
    (if (eq (type-of key) (type-of (car bindings)))
        (progn
          (apply #'bind-prefix (keys-make-local-prefix key) bindings))
      (apply #'bind-prefix (keys-make-local-prefix) (cons key bindings))))
Clone this wiki locally