Generalize +evil-esc-hook into doom-escape-hook
This lets vanilla Emacs users in on having a universal "escape" key.
This commit is contained in:
parent
c8768f512d
commit
3cbddbfd88
8 changed files with 34 additions and 28 deletions
|
@ -21,6 +21,30 @@
|
|||
(?g . global))
|
||||
"A list of cons cells that map a letter to a evil state symbol.")
|
||||
|
||||
;;
|
||||
(defvar doom-escape-hook nil
|
||||
"A hook run after C-g is pressed (or ESC in normal mode, for evil users). Both
|
||||
keys trigger `doom/escape'.
|
||||
|
||||
If any hook returns non-nil, all hooks after it are ignored.")
|
||||
|
||||
(defun doom/escape ()
|
||||
"Run the `doom-escape-hook'."
|
||||
(interactive)
|
||||
(cond ((minibuffer-window-active-p (minibuffer-window))
|
||||
;; quit the minibuffer if open.
|
||||
(abort-recursive-edit))
|
||||
((and (featurep 'evil) (evil-ex-hl-active-p 'evil-ex-search))
|
||||
;; disable ex search buffer highlights.
|
||||
(evil-ex-nohighlight))
|
||||
;; Run all escape hooks. If any returns non-nil, then stop there.
|
||||
((run-hook-with-args-until-success 'doom-escape-hook))
|
||||
;; Back to the default
|
||||
(t (keyboard-quit))))
|
||||
|
||||
(global-set-key [remap keyboard-quit] #'doom/escape)
|
||||
(advice-add #'evil-force-normal-state :after #'doom/escape)
|
||||
|
||||
|
||||
;;
|
||||
(def-package! which-key
|
||||
|
|
|
@ -88,24 +88,6 @@
|
|||
|
||||
|
||||
;; --- evil hacks -------------------------
|
||||
(defvar +evil-esc-hook '(t)
|
||||
"A hook run after ESC is pressed in normal mode (invoked by
|
||||
`evil-force-normal-state'). If any hook returns non-nil, all hooks after it are
|
||||
ignored.")
|
||||
|
||||
(defun +evil*attach-escape-hook ()
|
||||
"Run the `+evil-esc-hook'."
|
||||
(cond ((minibuffer-window-active-p (minibuffer-window))
|
||||
;; quit the minibuffer if open.
|
||||
(abort-recursive-edit))
|
||||
((evil-ex-hl-active-p 'evil-ex-search)
|
||||
;; disable ex search buffer highlights.
|
||||
(evil-ex-nohighlight))
|
||||
(t
|
||||
;; Run all escape hooks. If any returns non-nil, then stop there.
|
||||
(run-hook-with-args-until-success '+evil-esc-hook))))
|
||||
(advice-add #'evil-force-normal-state :after #'+evil*attach-escape-hook)
|
||||
|
||||
(defun +evil*restore-normal-state-on-windmove (orig-fn &rest args)
|
||||
"If in anything but normal or motion mode when moving to another window,
|
||||
restore normal mode. This prevents insert state from bleeding into other modes
|
||||
|
@ -246,7 +228,7 @@ across windows."
|
|||
(when evil-exchange--overlays
|
||||
(evil-exchange-cancel)
|
||||
t))
|
||||
(add-hook '+evil-esc-hook #'+evil|escape-exchange))
|
||||
(add-hook 'doom-escape-hook #'+evil|escape-exchange))
|
||||
|
||||
|
||||
(def-package! evil-matchit
|
||||
|
@ -309,7 +291,7 @@ the new algorithm is confusing, like in python or ruby."
|
|||
(evil-mc-undo-all-cursors)
|
||||
(evil-mc-resume-cursors)
|
||||
t))
|
||||
(add-hook '+evil-esc-hook #'+evil|escape-multiple-cursors))
|
||||
(add-hook 'doom-escape-hook #'+evil|escape-multiple-cursors))
|
||||
|
||||
|
||||
(def-package! evil-snipe
|
||||
|
|
|
@ -139,14 +139,14 @@ current buffer."
|
|||
:keymap +popup-mode-map
|
||||
(cond (+popup-mode
|
||||
(add-hook 'doom-unreal-buffer-functions #'+popup-p)
|
||||
(add-hook '+evil-esc-hook #'+popup|close-on-escape t)
|
||||
(add-hook 'doom-escape-hook #'+popup|close-on-escape t)
|
||||
(setq +popup--old-display-buffer-alist display-buffer-alist
|
||||
display-buffer-alist +popup--display-buffer-alist)
|
||||
(dolist (prop +popup-window-parameters)
|
||||
(push (cons prop 'writeable) window-persistent-parameters)))
|
||||
(t
|
||||
(remove-hook 'doom-unreal-buffer-functions #'+popup-p)
|
||||
(remove-hook '+evil-esc-hook #'+popup|close-on-escape)
|
||||
(remove-hook 'doom-escape-hook #'+popup|close-on-escape)
|
||||
(setq display-buffer-alist +popup--old-display-buffer-alist)
|
||||
(dolist (prop +popup-window-parameters)
|
||||
(assq-delete-all prop window-persistent-parameters)))))
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay)
|
||||
|
||||
;; Exit snippets on ESC from normal mode
|
||||
(add-hook '+evil-esc-hook #'yas-abort-snippet))
|
||||
(add-hook 'doom-escape-hook #'yas-abort-snippet))
|
||||
|
||||
|
||||
(def-package! auto-yasnippet
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
(when flycheck-mode
|
||||
(ignore-errors (flycheck-buffer))
|
||||
nil))
|
||||
(add-hook '+evil-esc-hook #'+syntax-checkers|flycheck-buffer t)
|
||||
(add-hook 'doom-escape-hook #'+syntax-checkers|flycheck-buffer t)
|
||||
|
||||
;; With the option of flychecking the buffer on escape, so we don't need
|
||||
;; auto-flychecking on idle-change:
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
(after! evil
|
||||
(defun +version-control|update-git-gutter ()
|
||||
"Refresh git-gutter on ESC. Return nil to prevent shadowing other
|
||||
`+evil-esc-hook' hooks."
|
||||
`doom-escape-hook' hooks."
|
||||
(when git-gutter-mode
|
||||
(ignore (git-gutter))))
|
||||
(add-hook '+evil-esc-hook #'+version-control|update-git-gutter t))
|
||||
(add-hook 'doom-escape-hook #'+version-control|update-git-gutter t))
|
||||
|
||||
(def-hydra! +version-control@git-gutter
|
||||
(:body-pre (git-gutter-mode 1) :hint nil)
|
||||
|
|
|
@ -256,7 +256,7 @@ between the two."
|
|||
(when (and (derived-mode-p 'org-mode)
|
||||
org-occur-highlights)
|
||||
(org-remove-occur-highlights)))
|
||||
(add-hook '+evil-esc-hook #'+org|remove-occur-highlights)
|
||||
(add-hook 'doom-escape-hook #'+org|remove-occur-highlights)
|
||||
|
||||
(after! recentf
|
||||
;; Don't clobber recentf with agenda files
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
anzu--last-isearch-string anzu--overflow-p))
|
||||
;; Ensure anzu state is cleared when searches & iedit are done
|
||||
(add-hook 'isearch-mode-end-hook #'anzu--reset-status t)
|
||||
(add-hook '+evil-esc-hook #'anzu--reset-status t)
|
||||
(add-hook 'doom-escape-hook #'anzu--reset-status t)
|
||||
(add-hook 'iedit-mode-end-hook #'anzu--reset-status))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue