💥 Refactor add-hook! macro & change arg order
This update may potentially break your usage of add-hook! if you pass the :local or :append properties to it. This is how they used to work: (add-hook! :append 'some-mode-hook #'do-something) Thsoe properties must now follow the hooks, e.g. (add-hook! 'some-mode-hook :append #'do-something) Other changes: - Various add-hook calls have been renamed to add-hook! because I incorrectly assumed `defun` always returned its definition's symbol, when in fact, its return value is "undefined" (so sayeth the documentation). This should fix #1597. - This update adds the ability to add multiple functions to hooks without a list: (add-hook! 'some-mode-hook #'do-something #'do-something-else) - The indentation logic has been changed so that consecutive function symbols at indented at the same level as the first argument, but forms are indent like a defun. (add-hook! 'some-mode-hook #'do-something #'do-something-else) (add-hook! 'some-mode-hook (message "Hello"))
This commit is contained in:
parent
c2ae6f30a5
commit
a3e262c7ac
42 changed files with 248 additions and 225 deletions
|
@ -256,7 +256,7 @@ shadow the default snippet)."
|
|||
+snippets-dir))))))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets|show-hints-in-header-line ()
|
||||
(defun +snippets-show-hints-in-header-line-h ()
|
||||
(setq header-line-format
|
||||
(substitute-command-keys
|
||||
(concat "\\[yas-load-snippet-buffer-and-close] to finish, "
|
||||
|
@ -268,7 +268,7 @@ shadow the default snippet)."
|
|||
;;; Hooks
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets|enable-project-modes (mode &rest _)
|
||||
(defun +snippets-enable-project-modes-h (mode &rest _)
|
||||
"Automatically enable snippet libraries for project minor modes defined with
|
||||
`def-project-mode!'."
|
||||
(if (symbol-value mode)
|
||||
|
@ -276,7 +276,7 @@ shadow the default snippet)."
|
|||
(yas-deactivate-extra-mode mode)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets|read-only-maybe ()
|
||||
(defun +snippets-read-only-maybe-h ()
|
||||
"Enable `read-only-mode' if snippet is built-in."
|
||||
(when (file-in-directory-p default-directory doom-local-dir)
|
||||
(read-only-mode 1)
|
||||
|
@ -287,7 +287,7 @@ shadow the default snippet)."
|
|||
;;; Advice
|
||||
|
||||
;;;###autoload
|
||||
(defun +snippets*expand-on-region (orig-fn &optional no-condition)
|
||||
(defun +snippets-expand-on-region-a (orig-fn &optional no-condition)
|
||||
"Fix off-by-one issue with expanding snippets on an evil visual region, and
|
||||
switches to insert mode.
|
||||
|
||||
|
|
|
@ -20,8 +20,11 @@
|
|||
;; have additional configuration for yasnippet. For example, file-templates.
|
||||
(add-transient-hook! 'yas-minor-mode-hook (yas-reload-all))
|
||||
|
||||
(add-hook! (text-mode prog-mode conf-mode snippet-mode)
|
||||
#'yas-minor-mode-on)
|
||||
(add-hook! '(text-mode-hook
|
||||
prog-mode-hook
|
||||
conf-mode-hook
|
||||
snippet-mode-hook)
|
||||
#'yas-minor-mode-on)
|
||||
|
||||
:config
|
||||
(setq yas-verbosity (if doom-debug-mode 3 0)
|
||||
|
@ -44,7 +47,7 @@
|
|||
|
||||
;; Register `def-project-mode!' modes with yasnippet. This enables project
|
||||
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
|
||||
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
|
||||
(add-hook 'doom-project-hook #'+snippets-enable-project-modes-h)
|
||||
|
||||
;; Exit snippets on ESC from normal mode
|
||||
(add-hook 'doom-escape-hook #'yas-abort-snippet)
|
||||
|
@ -54,16 +57,16 @@
|
|||
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay))
|
||||
|
||||
;; Enable `read-only-mode' for built-in snippets (in `doom-local-dir')
|
||||
(add-hook 'snippet-mode-hook #'+snippets|read-only-maybe)
|
||||
(add-hook 'snippet-mode-hook #'+snippets-read-only-maybe-h)
|
||||
|
||||
;; (Evil only) fix off-by-one issue with line-wise visual selections in
|
||||
;; `yas-insert-snippet', and switches to insert mode afterwards.
|
||||
(advice-add #'yas-insert-snippet :around #'+snippets*expand-on-region)
|
||||
(advice-add #'yas-insert-snippet :around #'+snippets-expand-on-region-a)
|
||||
|
||||
(define-key! snippet-mode-map
|
||||
"C-c C-k" #'+snippet--abort
|
||||
"C-c C-e" #'+snippet--edit)
|
||||
(add-hook 'snippet-mode-hook #'+snippets|show-hints-in-header-line)
|
||||
(add-hook 'snippet-mode-hook #'+snippets-show-hints-in-header-line-h)
|
||||
|
||||
;; Replace commands with superior alternatives
|
||||
(define-key! yas-minor-mode-map
|
||||
|
@ -75,7 +78,7 @@
|
|||
:defer t
|
||||
:init (setq aya-persist-snippets-dir (concat doom-etc-dir "auto-snippets/"))
|
||||
:config
|
||||
(defadvice! +snippets--inhibit-yas-global-mode (orig-fn &rest args)
|
||||
(defadvice! +snippets--inhibit-yas-global-mode-a (orig-fn &rest args)
|
||||
"auto-yasnippet enables `yas-global-mode'. This is obnoxious for folks like
|
||||
us who use yas-minor-mode and enable yasnippet more selectively. This advice
|
||||
swaps `yas-global-mode' with `yas-minor-mode'."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue