diff --git a/modules/feature/snippets/autoload/snippets.el b/modules/feature/snippets/autoload/snippets.el index bc7e4b75f..aeeb52720 100644 --- a/modules/feature/snippets/autoload/snippets.el +++ b/modules/feature/snippets/autoload/snippets.el @@ -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 () diff --git a/modules/feature/snippets/config.el b/modules/feature/snippets/config.el index bbc3a4eeb..29b1f3fd2 100644 --- a/modules/feature/snippets/config.el +++ b/modules/feature/snippets/config.el @@ -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)