This library is to simplify the Emacs keybinding for the commands which have same prefix leading key, so that we don’t need to press the prefix leading key.
Such as, By defining simplied keybindings for winner-undo
(“C-c <left>”) and winner-redo
(“C-c
<right>”), if last command is one of them, it doesn’t need to press “C-c” again to next command.
It is possible to use Hydra
to implement similar functions, but I think the way used here is more simple and clear.
Clone this git repo to “${user-emacs-directory}/packages/simplify-keybinding”, and add folowing lines to Emacs config file:
(use-package simplify-keybinding
:defer t
:ensure nil ; it is github package
;; If the path is relative, it is expanded within `user-emacs-directory'
:load-path "packages/simplify-keybinding"
:init
(let ((pkg-name "simplify-keybinding"))
(ignore-errors
(package-generate-autoloads pkg-name
(expand-file-name (concat "packages/" pkg-name)
user-emacs-directory)))
(load (concat pkg-name "-autoloads.el")))
)
Just use SK-define-keymap
to define the simplified keybindings, please see the examples below.
SK-setup-default-keymap
can setup these example keybindings automatically.
(SK-define-keymap
(("<left>" winner-undo "← undo")
("<right>" winner-redo "→ redo"))
"Winner: ")
(SK-define-keymap
(("<left>" previous-buffer "← prev-buffer")
("<right>" next-buffer "→ next-buffer"))
"Buffer: ")
(with-eval-after-load 'compile
(SK-define-keymap
(("M-n" next-error "M-n next-error")
("M-p" previous-error "M-p prev-error"))
"Compilation error: ")
)
(SK-define-keymap
(("C-n" org-next-visible-heading "C-n next")
("C-p" org-previous-visible-heading "C-p pre")
("C-u" outline-up-heading "C-u up")
("C-f" org-forward-heading-same-level "C-f foward")
("C-b" org-backward-heading-same-level "C-b backward")
)
"Navigate headlines: "
(derived-mode-p 'org-mode))