From 608d469102a3c6ee47562fa2c9456b3b743a05ea Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Mon, 22 Jul 2024 12:43:20 -0400 Subject: [PATCH] feat(file-templates): improve registration UI --- config.org | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config.org b/config.org index 9e8c15e..440a88e 100644 --- a/config.org +++ b/config.org @@ -2145,6 +2145,24 @@ Doom's command to create a new snippet, ~+snippets/new~, defines a template insi (find-file snippet-file-name)))) #+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 #+call: confpkg("Pkg: ispell")