feat(file-templates): improve registration UI

This commit is contained in:
Kiana Sheibani 2024-07-22 12:43:20 -04:00
parent 221b4fa145
commit 608d469102
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -2145,6 +2145,24 @@ Doom's command to create a new snippet, ~+snippets/new~, defines a template insi
(find-file snippet-file-name)))) (find-file snippet-file-name))))
#+end_src #+end_src
*** File Templates
Doom's =file-templates= module extends =yasnippet= to provide a nice file template system. The idea is simple: the variable ~+file-templates-alist~ maps file predicates to snippets. If a file that matches a predicate is created, the corresponding snippet is automatically expanded inside of it.
This system works well for the most part, but there's a serious issue with its UI: the function that registers file templates, ~set-file-templates!~, takes a plist to configure the template. If this list is empty, an existing template is removed instead. This is not only unintuitive, but it prevents you from having an empty property list, which is often necessary! We'll advise the function to remove this issue with a =:remove= key, as well as to have templates appended to the alist instead of prepended to→
#+begin_src emacs-lisp
(defadvice! ~/file-templates-set (pred plist)
:override #'+file-templates--set
(if (plist-member plist :remove)
(setq +file-templates-alist
(assoc-delete-all pred +file-templates-alist))
(setq +file-templates-alist
(nconc +file-templates-alist `((,pred ,@plist))))))
#+end_src
Now that we have our new-and-improved template registry system, we can add new file templates as we please.
** Spell Checking ** Spell Checking
#+call: confpkg("Pkg: ispell") #+call: confpkg("Pkg: ispell")