Created
December 23, 2017 06:32
-
-
Save aijony/74b8dd54eba739203884fb4879a765de to your computer and use it in GitHub Desktop.
Notmuch keybindings fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun notmuch/switch-keys (keymap keyslist) | |
"Swaps OLDKEY with NEWKEY in KEYMAP without changing the | |
key's definition" | |
(dolist (keys keyslist) | |
(let ((oldkey (car keys)) | |
(newkey (car (cdr keys)))) | |
(define-key keymap (kbd newkey) (lookup-key keymap (kbd oldkey))) | |
(define-key keymap (kbd oldkey) nil)))) | |
(defun notmuch/add-key (keymap keybindlist) | |
"Adds NEWKEY to KEYMAP to call FUNC" | |
(dolist (keybind keybindlist) | |
(let ((newkey (car keybind)) | |
(func (car (cdr keybind)))) | |
(define-key keymap (kbd newkey) func)))) | |
;; Evilify the default notmuch modes | |
(dolist (mode notmuch-evilify-mode-list) | |
(evil-set-initial-state mode 'evilified)) | |
;; Remaps all conficting keybindings. | |
;; TODO Don't use eval-after-load (maybe) | |
(with-eval-after-load 'notmuch | |
(notmuch/switch-keys notmuch-common-keymap '(("j" ";"))) | |
(notmuch/switch-keys notmuch-hello-mode-map '(("v" "_"))) | |
(notmuch/switch-keys notmuch-tree-mode-map '(("A" "O") | |
("a" "o") | |
("v" "a") | |
("V" "A") | |
("n" "J") | |
("N" "H") | |
("p" "K") | |
("P" "L") | |
("k" ":") | |
("SPC" "C-L") | |
("DEL" "C-H"))) | |
(notmuch/switch-keys notmuch-search-mode-map '(("SPC" "C-L") | |
("DEL" "C-H") | |
("n" "J") | |
("p" "K") | |
("l" "\"") | |
("k" ":") | |
("a" "o"))) | |
(notmuch/switch-keys notmuch-show-mode-map '(("SPC" "C-L") | |
("n" "J") | |
("p" "K") | |
("l" "\"") | |
("k" ":") | |
("a" "o"))) | |
(notmuch/add-key notmuch-tree-mode-map '(("d" spacemacs/notmuch-message-delete-down) | |
("D" spacemacs/notmuch-message-delete-up) | |
("M" compose-mail-other-frame))) | |
(notmuch/add-key notmuch-search-mode-map '(("a" spacemacs/notmuch-search-archive-thread-down) | |
("A" spacemacs/notmuch-search-archive-thread-up) | |
("d" spacemacs/notmuch-message-delete-down) | |
("D" spacemacs/notmuch-message-delete-up) | |
("J" notmuch-jump-search) | |
("L" notmuch-search-filter) | |
("gg" notmuch-search-first-thread) | |
("gr" notmuch-refresh-this-buffer) | |
("gR" notmuch-refresh-all-buffers) | |
("G" notmuch-search-last-thread) | |
("M" compose-mail-other-frame)))) | |
;; Dynamic evil-states based off of text property | |
;; Treats text-boxes like regular text files | |
;; This is seperate from the fix, it's just another fix to an evil/notmuch issue. | |
(add-hook | |
'notmuch-hello-mode-hook | |
(lambda () | |
(add-hook | |
'post-command-hook | |
(lambda () | |
(let ( | |
;; Everything else that isn't `editable' for notmuch-hello should be read-only | |
(editable (get-char-property (point) 'field)) | |
(is-evilified (string= evil-state "evilified")) | |
(is-normal (string= evil-state "normal")) | |
(is-insert (string= evil-state "insert"))) | |
(cond ((and is-evilified editable) | |
(evil-normal-state) | |
(define-key evil-motion-state-map (kbd "RET") 'widget-field-activate)) | |
((and (or is-normal is-insert) (not editable)) | |
(evil-evilified-state))))) | |
nil t))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment