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:
parent
dff6e44635
commit
3359d351f5
2 changed files with 70 additions and 44 deletions
|
@ -153,6 +153,18 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
|
|||
(defvar doom--defer 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)
|
||||
"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
|
||||
|
|
|
@ -716,56 +716,70 @@
|
|||
;; This section is dedicated to "fixing" certain keys so that they behave
|
||||
;; properly, more like vim, or how I like it.
|
||||
|
||||
(map! (:map input-decode-map
|
||||
[S-iso-lefttab] [backtab]
|
||||
(:unless window-system "TAB" [tab])) ; Fix TAB in terminal
|
||||
(define-key input-decode-map [S-iso-lefttab] [backtab])
|
||||
|
||||
;; I want C-a and C-e to be a little smarter. C-a will jump to
|
||||
;; indentation. Pressing it again will send you to the true bol. Same goes
|
||||
;; for C-e, except it will ignore comments and trailing whitespace before
|
||||
;; 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
|
||||
;; Fix TAB in terminal
|
||||
(unless window-system
|
||||
(define-key input-decode-map "TAB" [tab]))
|
||||
|
||||
;; textmate-esque newline insertion
|
||||
:i [M-return] #'evil-open-below
|
||||
:i [S-M-return] #'evil-open-above
|
||||
;; textmate-esque deletion
|
||||
:ig [M-backspace] #'doom/backward-kill-to-bol-and-indent
|
||||
;; Emacsien motions for insert mode
|
||||
:i "C-b" #'backward-word
|
||||
:i "C-f" #'forward-word
|
||||
(after! evil
|
||||
(evil-define-key* 'insert 'global
|
||||
;; I want C-a and C-e to be a little smarter. C-a will jump to indentation.
|
||||
;; Pressing it again will send you to the true bol. Same goes for C-e,
|
||||
;; except it will ignore comments and trailing whitespace before jumping to
|
||||
;; eol.
|
||||
"C-a" #'doom/backward-to-bol-or-indent
|
||||
"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
|
||||
(:map (minibuffer-local-map
|
||||
minibuffer-local-ns-map
|
||||
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))))
|
||||
(evil-define-key* 'insert 'global
|
||||
;; textmate-esque deletion
|
||||
[M-backspace] #'doom/backward-kill-to-bol-and-indent)
|
||||
|
||||
(:after evil
|
||||
(:map evil-ex-completion-map
|
||||
"C-a" #'move-beginning-of-line
|
||||
"C-b" #'backward-word
|
||||
"C-f" #'forward-word))
|
||||
(define-key! evil-ex-completion-map
|
||||
"C-a" #'move-beginning-of-line
|
||||
"C-b" #'backward-word
|
||||
"C-f" #'forward-word))
|
||||
|
||||
(:after tabulated-list
|
||||
(:map tabulated-list-mode-map
|
||||
"q" #'quit-window))
|
||||
(after! tabulated-list
|
||||
(define-key tabulated-list-mode-map "q" #'quit-window))
|
||||
|
||||
(:after view
|
||||
(:map view-mode-map "<escape>" #'View-quit-all)))
|
||||
(after! view
|
||||
(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))
|
||||
|
||||
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue