Refactor feature/snippets
+ Don't clear yas-minor-mode-map; the default keybinds can be useful, esp to non-evil users. + Moved +snippets|enable-project-modes hook to autoloads file. + Reformat yasnippet config.
This commit is contained in:
parent
ae6c3cacf2
commit
8f76ee9a8a
2 changed files with 19 additions and 19 deletions
|
@ -66,3 +66,15 @@ buggy behavior when <delete> is pressed in an empty field."
|
||||||
(let ((sof (marker-position (yas--field-start field))))
|
(let ((sof (marker-position (yas--field-start field))))
|
||||||
(when (and field (> (point) sof))
|
(when (and field (> (point) sof))
|
||||||
(delete-region sof (point))))))
|
(delete-region sof (point))))))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Hooks
|
||||||
|
;;
|
||||||
|
|
||||||
|
(defun +snippets|enable-project-modes (mode &rest _)
|
||||||
|
"Automatically enable snippet libraries for project minor modes defined with
|
||||||
|
`def-project-mode!'."
|
||||||
|
(if (symbol-value mode)
|
||||||
|
(yas-activate-extra-mode mode)
|
||||||
|
(yas-deactivate-extra-mode mode)))
|
||||||
|
|
|
@ -11,13 +11,6 @@
|
||||||
(def-package! yasnippet
|
(def-package! yasnippet
|
||||||
:commands (yas-minor-mode-on yas-expand yas-expand-snippet yas-lookup-snippet
|
:commands (yas-minor-mode-on yas-expand yas-expand-snippet yas-lookup-snippet
|
||||||
yas-insert-snippet yas-new-snippet yas-visit-snippet-file)
|
yas-insert-snippet yas-new-snippet yas-visit-snippet-file)
|
||||||
:preface
|
|
||||||
(defvar yas-minor-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(when (featurep! :feature evil)
|
|
||||||
(define-key map [remap yas-insert-snippet] #'+snippets/expand-on-region))
|
|
||||||
map))
|
|
||||||
|
|
||||||
: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.
|
||||||
|
@ -31,23 +24,18 @@
|
||||||
yas-also-auto-indent-first-line t
|
yas-also-auto-indent-first-line t
|
||||||
yas-prompt-functions (delq #'yas-dropdown-prompt yas-prompt-functions)
|
yas-prompt-functions (delq #'yas-dropdown-prompt yas-prompt-functions)
|
||||||
yas-triggers-in-field t) ; Allow nested snippets
|
yas-triggers-in-field t) ; Allow nested snippets
|
||||||
|
|
||||||
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
|
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
|
||||||
|
;; Register `def-project-mode!' modes with yasnippet. This enables project
|
||||||
(defun +snippets|enable-project-modes (mode &rest _)
|
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
|
||||||
"Automatically enable snippet libraries for project minor modes defined with
|
|
||||||
`def-project-mode!'."
|
|
||||||
(if (symbol-value mode)
|
|
||||||
(yas-activate-extra-mode mode)
|
|
||||||
(yas-deactivate-extra-mode mode)))
|
|
||||||
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
|
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)
|
||||||
|
|
||||||
;; Exit snippets on ESC from normal mode
|
;; Exit snippets on ESC from normal mode
|
||||||
(add-hook 'doom-escape-hook #'yas-abort-snippet)
|
(add-hook 'doom-escape-hook #'yas-abort-snippet)
|
||||||
|
;; Fix an error caused by smartparens interfering with yasnippet bindings
|
||||||
(after! smartparens
|
(after! smartparens
|
||||||
;; fix an error caused by smartparens interfering with yasnippet bindings
|
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay))
|
||||||
(advice-add #'yas-expand :before #'sp-remove-active-pair-overlay)))
|
;; Better `yas-insert-snippet' for evil users
|
||||||
|
(when (featurep! :feature evil)
|
||||||
|
(define-key yas-minor-mode-map [remap yas-insert-snippet] #'+snippets/expand-on-region)))
|
||||||
|
|
||||||
|
|
||||||
;; `auto-yasnippet'
|
;; `auto-yasnippet'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue