parent
6f5b853cc2
commit
5057db93f1
2 changed files with 30 additions and 29 deletions
|
@ -49,17 +49,15 @@
|
||||||
(which-key-add-key-based-replacements key desc)))
|
(which-key-add-key-based-replacements key desc)))
|
||||||
|
|
||||||
|
|
||||||
(defun doom--keyword-to-states (keyword &optional ignore)
|
(defun doom--keyword-to-states (keyword)
|
||||||
"Convert a KEYWORD into a list of evil state symbols.
|
"Convert a KEYWORD into a list of evil state symbols.
|
||||||
|
|
||||||
IGNORE is a list of keyword letters that should be ignored.
|
|
||||||
|
|
||||||
For example, :nvi will map to (list 'normal 'visual 'insert). See
|
For example, :nvi will map to (list 'normal 'visual 'insert). See
|
||||||
`doom-evil-state-alist' to customize this."
|
`doom-evil-state-alist' to customize this."
|
||||||
(cl-loop for l across (substring (symbol-name keyword) 1)
|
(cl-loop for l across (substring (symbol-name keyword) 1)
|
||||||
if (cdr (assq l doom-evil-state-alist))
|
if (cdr (assq l doom-evil-state-alist))
|
||||||
collect it
|
collect it
|
||||||
else if (not (or (eq ignore t) (member l ignore)))
|
else
|
||||||
do (error "not a valid state: %s" l)))
|
do (error "not a valid state: %s" l)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +71,7 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
|
||||||
(put ':unless 'lisp-indent-function 'defun)
|
(put ':unless 'lisp-indent-function 'defun)
|
||||||
(put ':desc 'lisp-indent-function 'defun)
|
(put ':desc 'lisp-indent-function 'defun)
|
||||||
(put ':leader 'lisp-indent-function 'defun)
|
(put ':leader 'lisp-indent-function 'defun)
|
||||||
|
(put ':local 'lisp-indent-function 'defun)
|
||||||
(put ':localleader 'lisp-indent-function 'defun)
|
(put ':localleader 'lisp-indent-function 'defun)
|
||||||
(put ':textobj 'lisp-indent-function 'defun)
|
(put ':textobj 'lisp-indent-function 'defun)
|
||||||
|
|
||||||
|
@ -80,6 +79,7 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See
|
||||||
(defvar doom--keymaps nil)
|
(defvar doom--keymaps nil)
|
||||||
(defvar doom--prefix nil)
|
(defvar doom--prefix nil)
|
||||||
(defvar doom--defer nil)
|
(defvar doom--defer nil)
|
||||||
|
(defvar doom--local nil)
|
||||||
|
|
||||||
(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*',
|
||||||
|
@ -97,7 +97,6 @@ States
|
||||||
:o operator
|
:o operator
|
||||||
:m motion
|
:m motion
|
||||||
:r replace
|
:r replace
|
||||||
:L local
|
|
||||||
|
|
||||||
These can be combined (order doesn't matter), e.g. :nvi will apply to
|
These can be combined (order doesn't matter), e.g. :nvi will apply to
|
||||||
normal, visual and insert mode. The state resets after the following
|
normal, visual and insert mode. The state resets after the following
|
||||||
|
@ -107,17 +106,16 @@ States
|
||||||
|
|
||||||
This can be customized with `doom-evil-state-alist'.
|
This can be customized with `doom-evil-state-alist'.
|
||||||
|
|
||||||
:L cannot be in a :map.
|
|
||||||
|
|
||||||
:textobj is a special state that takes a key and two commands, one for the
|
:textobj is a special state that takes a key and two commands, one for the
|
||||||
inner binding, another for the outer.
|
inner binding, another for the outer.
|
||||||
|
|
||||||
Flags
|
Flags
|
||||||
(:mode [MODE(s)] [...]) ; inner keybinds are applied to major MODE(s)
|
(:mode [MODE(s)] [...]) inner keybinds are applied to major MODE(s)
|
||||||
(:map [KEYMAP(s)] [...]) ; inner keybinds are applied to KEYMAP(S)
|
(:map [KEYMAP(s)] [...]) inner keybinds are applied to KEYMAP(S)
|
||||||
(:map* [KEYMAP(s)] [...]) ; same as :map, but deferred
|
(:map* [KEYMAP(s)] [...]) same as :map, but deferred
|
||||||
(:prefix [PREFIX] [...]) ; assign prefix to all inner keybindings
|
(:prefix [PREFIX] [...]) assign prefix to all inner keybindings
|
||||||
(:after [FEATURE] [...]) ; apply keybinds when [FEATURE] loads
|
(:after [FEATURE] [...]) apply keybinds when [FEATURE] loads
|
||||||
|
(:local [...]) make bindings buffer local; incompatible with keymaps!
|
||||||
|
|
||||||
Conditional keybinds
|
Conditional keybinds
|
||||||
(:when [CONDITION] [...])
|
(:when [CONDITION] [...])
|
||||||
|
@ -135,7 +133,8 @@ Example
|
||||||
(let ((doom--keymaps doom--keymaps)
|
(let ((doom--keymaps doom--keymaps)
|
||||||
(doom--prefix doom--prefix)
|
(doom--prefix doom--prefix)
|
||||||
(doom--defer doom--defer)
|
(doom--defer doom--defer)
|
||||||
local key def states forms desc modes)
|
(doom--local doom--local)
|
||||||
|
key def states forms desc modes)
|
||||||
(while rest
|
(while rest
|
||||||
(setq key (pop rest))
|
(setq key (pop rest))
|
||||||
(cond
|
(cond
|
||||||
|
@ -186,15 +185,10 @@ Example
|
||||||
,desc ',modes)
|
,desc ',modes)
|
||||||
forms)
|
forms)
|
||||||
(setq desc nil))))
|
(setq desc nil))))
|
||||||
|
(:local
|
||||||
|
(setq doom--local t))
|
||||||
(_ ; might be a state doom--prefix
|
(_ ; might be a state doom--prefix
|
||||||
(setq states (doom--keyword-to-states key '("L")))
|
(setq states (doom--keyword-to-states key)))))
|
||||||
(let (case-fold-search)
|
|
||||||
(when (string-match-p "L" (symbol-name key))
|
|
||||||
(setq local t)
|
|
||||||
(cond ((= (length states) 0)
|
|
||||||
(user-error "local keybinding for %s must accompany another state" key))
|
|
||||||
((> (length doom--keymaps) 0)
|
|
||||||
(user-error "local keybinding for %s cannot accompany a keymap" key))))))))
|
|
||||||
|
|
||||||
;; It's a key-def pair
|
;; It's a key-def pair
|
||||||
((or (stringp key)
|
((or (stringp key)
|
||||||
|
@ -216,7 +210,13 @@ Example
|
||||||
(push `(doom--keybind-register ,(key-description (eval key))
|
(push `(doom--keybind-register ,(key-description (eval key))
|
||||||
,desc ',modes)
|
,desc ',modes)
|
||||||
forms))
|
forms))
|
||||||
(cond ((and doom--keymaps states)
|
(cond ((and doom--local doom--keymaps)
|
||||||
|
(push `(lwarn 'doom-map :warning
|
||||||
|
"Can't local bind '%s' key to a keymap; skipped"
|
||||||
|
,key)
|
||||||
|
forms)
|
||||||
|
(throw 'skip 'local))
|
||||||
|
((and doom--keymaps states)
|
||||||
(unless (featurep 'evil) (throw 'skip 'evil))
|
(unless (featurep 'evil) (throw 'skip 'evil))
|
||||||
(dolist (keymap doom--keymaps)
|
(dolist (keymap doom--keymaps)
|
||||||
(push `(,(if doom--defer 'evil-define-key 'evil-define-key*)
|
(push `(,(if doom--defer 'evil-define-key 'evil-define-key*)
|
||||||
|
@ -226,17 +226,17 @@ Example
|
||||||
(unless (featurep 'evil) (throw 'skip 'evil))
|
(unless (featurep 'evil) (throw 'skip 'evil))
|
||||||
(dolist (state states)
|
(dolist (state states)
|
||||||
(push `(define-key
|
(push `(define-key
|
||||||
,(intern (format "evil-%s-state-%smap" state (if local "local-" "")))
|
,(intern (format "evil-%s-state-%smap" state (if doom--local "local-" "")))
|
||||||
,key ,def)
|
,key ,def)
|
||||||
forms)))
|
forms)))
|
||||||
(doom--keymaps
|
(doom--keymaps
|
||||||
(dolist (keymap doom--keymaps)
|
(dolist (keymap doom--keymaps)
|
||||||
(push `(define-key ,keymap ,key ,def) forms)))
|
(push `(define-key ,keymap ,key ,def) forms)))
|
||||||
(t
|
(t
|
||||||
(push `(,(if local 'local-set-key 'global-set-key) ,key ,def)
|
(push `(,(if doom--local 'local-set-key 'global-set-key) ,key ,def)
|
||||||
forms))))
|
forms))))
|
||||||
(setq states '()
|
(setq states '()
|
||||||
local nil
|
doom--local nil
|
||||||
desc nil)))
|
desc nil)))
|
||||||
|
|
||||||
(t (user-error "Invalid key %s" key))))
|
(t (user-error "Invalid key %s" key))))
|
||||||
|
|
|
@ -59,10 +59,11 @@
|
||||||
(add-hook! 'reftex-toc-mode-hook
|
(add-hook! 'reftex-toc-mode-hook
|
||||||
(reftex-toc-rescan)
|
(reftex-toc-rescan)
|
||||||
(doom-hide-modeline-mode +1)
|
(doom-hide-modeline-mode +1)
|
||||||
(map! :Le "j" #'next-line
|
(map! :local
|
||||||
:Le "k" #'previous-line
|
:e "j" #'next-line
|
||||||
:Le "q" #'kill-buffer-and-window
|
:e "k" #'previous-line
|
||||||
:Le "ESC" #'kill-buffer-and-window)))
|
:e "q" #'kill-buffer-and-window
|
||||||
|
:e "ESC" #'kill-buffer-and-window)))
|
||||||
|
|
||||||
|
|
||||||
(def-package! bibtex ; built-in
|
(def-package! bibtex ; built-in
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue