Add & use add-transient-hook! macro
This commit is contained in:
parent
10b4d94627
commit
2d190fe0c5
3 changed files with 15 additions and 7 deletions
|
@ -65,6 +65,19 @@ compilation."
|
|||
(save-silently t))
|
||||
,@forms)))
|
||||
|
||||
(defmacro add-transient-hook! (hook &rest forms)
|
||||
"Attaches transient forms to a hook (can also be a function, which will be
|
||||
advised instead). These forms will be evaluated only once when that
|
||||
function/hook is first invoked, then it detaches itself."
|
||||
(let ((fn (intern (format "doom--transient-hook-%s" hook))))
|
||||
`(progn
|
||||
(defun ,fn (&rest _)
|
||||
,@forms
|
||||
,(cond ((functionp hook) `(advice-remove ',hook ',fn))
|
||||
((symbolp hook) `(remove-hook ',hook ',fn))))
|
||||
,(cond ((functionp hook) `(advice-add ',hook :before ',fn))
|
||||
((symbolp hook) `(add-hook ',hook ',fn))))))
|
||||
|
||||
(defmacro add-hook! (&rest args)
|
||||
"A convenience macro for `add-hook'. Takes, in order:
|
||||
|
||||
|
|
|
@ -13,10 +13,7 @@
|
|||
:init
|
||||
;; Ensure `yas-reload-all' is called as late as possible. Other modules could
|
||||
;; have additional configuration for yasnippet. For example, file-templates.
|
||||
(add-hook 'yas-minor-mode-hook '+snippets|load)
|
||||
(defun +snippets|load (&rest _)
|
||||
(yas-reload-all)
|
||||
(remove-hook 'yas-minor-mode-hook '+snippets|load))
|
||||
(add-transient-hook! yas-minor-mode-hook (yas-reload-all))
|
||||
|
||||
(add-hook! (text-mode prog-mode snippet-mode markdown-mode org-mode)
|
||||
'yas-minor-mode-on)
|
||||
|
|
|
@ -33,10 +33,8 @@
|
|||
;; mode-line.
|
||||
(def-package! evil-anzu
|
||||
:init
|
||||
(defun +evil*lazy-load-evil-anzu (&rest _) (require 'evil-anzu))
|
||||
(advice-add 'evil-ex-start-search :before '+evil*lazy-load-evil-anzu)
|
||||
(add-transient-hook! evil-ex-start-search (require 'evil-anzu))
|
||||
:config
|
||||
(advice-remove 'evil-ex-start-search '+evil*lazy-load-evil-anzu)
|
||||
(setq anzu-cons-mode-line-p nil
|
||||
anzu-minimum-input-length 1
|
||||
anzu-search-threshold 250))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue