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))
|
(save-silently t))
|
||||||
,@forms)))
|
,@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)
|
(defmacro add-hook! (&rest args)
|
||||||
"A convenience macro for `add-hook'. Takes, in order:
|
"A convenience macro for `add-hook'. Takes, in order:
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,7 @@
|
||||||
:init
|
:init
|
||||||
;; Ensure `yas-reload-all' is called as late as possible. Other modules could
|
;; Ensure `yas-reload-all' is called as late as possible. Other modules could
|
||||||
;; have additional configuration for yasnippet. For example, file-templates.
|
;; have additional configuration for yasnippet. For example, file-templates.
|
||||||
(add-hook 'yas-minor-mode-hook '+snippets|load)
|
(add-transient-hook! yas-minor-mode-hook (yas-reload-all))
|
||||||
(defun +snippets|load (&rest _)
|
|
||||||
(yas-reload-all)
|
|
||||||
(remove-hook 'yas-minor-mode-hook '+snippets|load))
|
|
||||||
|
|
||||||
(add-hook! (text-mode prog-mode snippet-mode markdown-mode org-mode)
|
(add-hook! (text-mode prog-mode snippet-mode markdown-mode org-mode)
|
||||||
'yas-minor-mode-on)
|
'yas-minor-mode-on)
|
||||||
|
|
|
@ -33,10 +33,8 @@
|
||||||
;; mode-line.
|
;; mode-line.
|
||||||
(def-package! evil-anzu
|
(def-package! evil-anzu
|
||||||
:init
|
:init
|
||||||
(defun +evil*lazy-load-evil-anzu (&rest _) (require 'evil-anzu))
|
(add-transient-hook! evil-ex-start-search (require 'evil-anzu))
|
||||||
(advice-add 'evil-ex-start-search :before '+evil*lazy-load-evil-anzu)
|
|
||||||
:config
|
:config
|
||||||
(advice-remove 'evil-ex-start-search '+evil*lazy-load-evil-anzu)
|
|
||||||
(setq anzu-cons-mode-line-p nil
|
(setq anzu-cons-mode-line-p nil
|
||||||
anzu-minimum-input-length 1
|
anzu-minimum-input-length 1
|
||||||
anzu-search-threshold 250))
|
anzu-search-threshold 250))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue