diff --git a/core/core-keybinds.el b/core/core-keybinds.el index 04417cdb0..36d8d69fe 100644 --- a/core/core-keybinds.el +++ b/core/core-keybinds.el @@ -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 diff --git a/modules/config/default/+bindings.el b/modules/config/default/+bindings.el index a44d14db3..e44425ef1 100644 --- a/modules/config/default/+bindings.el +++ b/modules/config/default/+bindings.el @@ -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 "" #'View-quit-all))) +(after! view + (define-key view-mode-map (kbd "") #'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)) ;;