What tool are you using for file templates?

I’m curious as to what packages are used currently for file templates.

I’m currently using org-generate, but I’m considering learning about https://www.gnu.org/software/emacs/manual/html_mono/srecode.html or maybe just using yasnippets and create a function that generate files and then just expand the snippets.

I often use tempel for simple file templates and snippets (see also tempel-collection).

Would you describe how to create files using tempel? , I haven’t use it before and there doesn’t seem to be any examples in the documentation of how to create files.

My use case is to create files quickly, for example an html, css and js file with the same name with just a single template expansion. I’ve been using org-generate for this and it works fine but the templates are simple org files so the template expansion can’t be done programmatically. I could just add some glue code and create files using yasnippet but I was wondering if there was some useful package I wasn’t aware of.

I use it to insert templates in an empty file when I need an Org header or a package skeleton.

I’m not familiar with org-generate, but I guess you could do something like this with tempel:

(defun my/new-file (file template-name)
  (make-empty-file file t)
  (with-current-buffer (find-file-noselect file)
    (tempel-insert template-name)))

(defun my/make-files (dir file)
  (let ((f (file-name-concat dir file)))
    (my/new-file (concat f ".html") 'skeleton)
    (my/new-file (concat f ".css") 'other-skeleton)
    (my/new-file (concat f ".js") 'something-else)))

(my/make-files "/tmp/test-dir" "my-file-name")
2 Likes

Thanks a lot @cryptk!. I tried tempel and your code examples and it turns out it is pretty easy to create file templates that way.

dired-mode
(component (let ((file (read-string "File name: " ) ))
	       (my/new-file file "html")      
	       (my/new-file file "css" )      
	       (my/new-file file "js" )))
1 Like