Prioritize private snippets over built-in ones
In the case of snippet conflicts, you'd normally be prompted to select which snippet you want. Built-in snippets are now disregarded if conflicting private ones exist. This makes it easier for users to add overriding snippets to DOOMDIR/snippets.
This commit is contained in:
parent
735e14270e
commit
1490b9ec8d
2 changed files with 22 additions and 4 deletions
|
@ -1,8 +1,20 @@
|
||||||
;;; feature/snippets/autoload/snippets.el -*- lexical-binding: t; -*-
|
;;; feature/snippets/autoload/snippets.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;
|
;;;###autoload
|
||||||
;; Commands
|
(defun +snippets-prompt-private (prompt choices &optional fn)
|
||||||
;;
|
"Prioritize private snippets (in `+snippets-dir') over built-in ones if there
|
||||||
|
are multiple choices."
|
||||||
|
(when-let*
|
||||||
|
((choices
|
||||||
|
(or (cl-loop for tpl in choices
|
||||||
|
if (file-in-directory-p (yas--template-get-file tpl)
|
||||||
|
+snippets-dir)
|
||||||
|
collect tpl)
|
||||||
|
choices)))
|
||||||
|
(if (cdr choices)
|
||||||
|
(let ((prompt-functions (remq '+snippets-prompt-private yas-prompt-functions)))
|
||||||
|
(run-hook-with-args-until-success 'prompt-functions prompt choices fn))
|
||||||
|
(car choices))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +snippets/goto-start-of-field ()
|
(defun +snippets/goto-start-of-field ()
|
||||||
|
|
|
@ -22,11 +22,17 @@
|
||||||
:config
|
:config
|
||||||
(setq yas-verbosity (if doom-debug-mode 3 0)
|
(setq yas-verbosity (if doom-debug-mode 3 0)
|
||||||
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-triggers-in-field t) ; Allow nested snippets
|
yas-triggers-in-field t) ; Allow nested snippets
|
||||||
|
|
||||||
|
;; Allow private snippets in DOOMDIR/snippets
|
||||||
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
|
(add-to-list 'yas-snippet-dirs '+snippets-dir nil #'eq)
|
||||||
|
|
||||||
|
;; Remove GUI dropdown prompt (prefer ivy/helm)
|
||||||
|
(delq #'yas-dropdown-prompt yas-prompt-functions)
|
||||||
|
;; Prioritize private snippets in `+snippets-dir' over built-in ones if there
|
||||||
|
;; are multiple choices.
|
||||||
|
(add-to-list 'yas-prompt-functions #'+snippets-prompt-private nil #'eq)
|
||||||
|
|
||||||
;; Register `def-project-mode!' modes with yasnippet. This enables project
|
;; Register `def-project-mode!' modes with yasnippet. This enables project
|
||||||
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
|
;; 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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue