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:
Henrik Lissner 2018-08-11 16:48:31 +02:00
parent 735e14270e
commit 1490b9ec8d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 22 additions and 4 deletions

View file

@ -1,8 +1,20 @@
;;; feature/snippets/autoload/snippets.el -*- lexical-binding: t; -*-
;;
;; Commands
;;
;;;###autoload
(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
(defun +snippets/goto-start-of-field ()

View file

@ -22,11 +22,17 @@
:config
(setq yas-verbosity (if doom-debug-mode 3 0)
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
;; Allow private snippets in DOOMDIR/snippets
(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
;; specific snippet libraries (e.g. for Laravel, React or Jekyll projects).
(add-hook 'doom-project-hook #'+snippets|enable-project-modes)