emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/tempel da6bcf80d5: README: Document how user elements c


From: ELPA Syncer
Subject: [elpa] externals/tempel da6bcf80d5: README: Document how user elements can be defined
Date: Wed, 19 Oct 2022 06:58:15 -0400 (EDT)

branch: externals/tempel
commit da6bcf80d525afc599360cf2e4cf2c403a0da1a4
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    README: Document how user elements can be defined
    
    We show how to define a user element, which allows you to include templates 
by
    name in other templates.
---
 README.org | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/README.org b/README.org
index cf6b34eb37..2f46d2bdf0 100644
--- a/README.org
+++ b/README.org
@@ -244,6 +244,32 @@ Furthermore Tempel supports syntax extensions:
 
 Use caution with templates which execute arbitrary code!
 
+* Defining custom elements
+
+Tempel supports custom user elements via the configuration variable
+=tempel-user-elements=. As a demonstration we add the element =(i template)= to
+include templates by name in another template.
+
+#+begin_src emacs-lisp
+  (defun tempel-include (elt)
+    (when (eq (car-safe elt) 'i)
+      (if-let (template (alist-get (cadr elt) (tempel--templates)))
+          (cons 'l template)
+        (message "Template %s not found" (cadr elt))
+        nil)))
+  (add-to-list 'tempel-user-elements #'tempel-include)
+#+end_src
+
+The following example templates uses the newly defined include element.
+
+#+begin_src emacs-lisp
+  (header ";;; " (or (buffer-file-name) (buffer-name)) " -- " p
+          " -*- lexical-binding: t -*-" n n)
+  (provide "(provide '" (file-name-base (or (buffer-file-name) (buffer-name))) 
")" n
+           ";;; " (file-name-nondirectory (or (buffer-file-name) 
(buffer-name))) " ends here" n)
+  (package (i header) r n n (i provide))
+#+end_src
+
 * Adding template sources
 
 Tempel offers a flexible mechanism for providing the templates, which are



reply via email to

[Prev in Thread] Current Thread [Next in Thread]