Add define-key! macro; refactor config/default key fixes

I'd like to phase out map! where it isn't absolutely necessary, since it
isn't very well optimized.
This commit is contained in:
Henrik Lissner 2018-06-01 02:15:19 +02:00
parent dff6e44635
commit 3359d351f5
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 70 additions and 44 deletions

View file

@ -153,6 +153,18 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
(defvar doom--defer nil) (defvar doom--defer nil)
(defvar doom--local nil) (defvar doom--local nil)
(defmacro define-key! (keymap key def &rest rest)
"TODO"
(declare (indent defun))
`(progn
(define-key ,keymap ,key ,def)
,@(let (forms)
(while rest
(let ((key (pop rest))
(def (pop rest)))
(push `(define-key ,keymap ,key ,def) forms)))
(nreverse forms))))
(defmacro map! (&rest rest) (defmacro map! (&rest rest)
"A nightmare of a key-binding macro that will use `evil-define-key*', "A nightmare of a key-binding macro that will use `evil-define-key*',
`define-key', `local-set-key' and `global-set-key' depending on context and `define-key', `local-set-key' and `global-set-key' depending on context and

View file

@ -716,56 +716,70 @@
;; This section is dedicated to "fixing" certain keys so that they behave ;; This section is dedicated to "fixing" certain keys so that they behave
;; properly, more like vim, or how I like it. ;; properly, more like vim, or how I like it.
(map! (:map input-decode-map (define-key input-decode-map [S-iso-lefttab] [backtab])
[S-iso-lefttab] [backtab]
(:unless window-system "TAB" [tab])) ; Fix TAB in terminal
;; I want C-a and C-e to be a little smarter. C-a will jump to ;; Fix TAB in terminal
;; indentation. Pressing it again will send you to the true bol. Same goes (unless window-system
;; for C-e, except it will ignore comments and trailing whitespace before (define-key input-decode-map "TAB" [tab]))
;; jumping to eol.
:i "C-a" #'doom/backward-to-bol-or-indent
:i "C-e" #'doom/forward-to-last-non-comment-or-eol
:i "C-u" #'doom/backward-kill-to-bol-and-indent
;; textmate-esque newline insertion (after! evil
:i [M-return] #'evil-open-below (evil-define-key* 'insert 'global
:i [S-M-return] #'evil-open-above ;; I want C-a and C-e to be a little smarter. C-a will jump to indentation.
;; textmate-esque deletion ;; Pressing it again will send you to the true bol. Same goes for C-e,
:ig [M-backspace] #'doom/backward-kill-to-bol-and-indent ;; except it will ignore comments and trailing whitespace before jumping to
;; Emacsien motions for insert mode ;; eol.
:i "C-b" #'backward-word "C-a" #'doom/backward-to-bol-or-indent
:i "C-f" #'forward-word "C-e" #'doom/forward-to-last-non-comment-or-eol
"C-u" #'doom/backward-kill-to-bol-and-indent
;; textmate-esque newline insertion
[M-return] #'evil-open-below
[S-M-return] #'evil-open-above
;; Emacsien motions for insert mode
"C-b" #'backward-word
"C-f" #'forward-word)
;; Restore common editing keys (and ESC) in minibuffer (evil-define-key* 'insert 'global
(:map (minibuffer-local-map ;; textmate-esque deletion
minibuffer-local-ns-map [M-backspace] #'doom/backward-kill-to-bol-and-indent)
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map
read-expression-map)
[escape] #'abort-recursive-edit
(:when (featurep 'evil)
"C-r" #'evil-paste-from-register)
"C-a" #'move-beginning-of-line
"C-w" #'backward-kill-word
"C-u" #'backward-kill-sentence
"C-b" #'backward-word
"C-f" #'forward-word
"C-z" (λ! (ignore-errors (call-interactively #'undo))))
(:after evil (define-key! evil-ex-completion-map
(:map evil-ex-completion-map "C-a" #'move-beginning-of-line
"C-a" #'move-beginning-of-line "C-b" #'backward-word
"C-b" #'backward-word "C-f" #'forward-word))
"C-f" #'forward-word))
(:after tabulated-list (after! tabulated-list
(:map tabulated-list-mode-map (define-key tabulated-list-mode-map "q" #'quit-window))
"q" #'quit-window))
(:after view (after! view
(:map view-mode-map "<escape>" #'View-quit-all))) (define-key view-mode-map (kbd "<escape>") #'View-quit-all))
;; Restore common editing keys (and ESC) in minibuffer
(defun +default|fix-minibuffer-in-map (map)
(evil-define-key* nil map
[escape] #'abort-recursive-edit
"\C-a" #'move-beginning-of-line
"\C-w" #'backward-kill-word
"\C-u" #'backward-kill-sentence
"\C-b" #'backward-word
"\C-f" #'forward-word
"\C-z" (λ! (ignore-errors (call-interactively #'undo))))
(when (featurep! :feature evil +everywhere)
(evil-define-key* nil map
"\C-r" #'abort-recursive-edit
"\C-j" #'next-line
"\C-k" #'previous-line
"\C-d" #'scroll-down-command
"\C-u" #'scroll-up-command)))
(mapc #'+default|fix-minibuffer-in-map
(list minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map
read-expression-map))
(after! ivy (+default|fix-minibuffer-in-map ivy-minibuffer-map))
;; ;;