minad / tempel

:classical_building: TempEl - Simple templates for Emacs
GNU General Public License v3.0
506 stars 24 forks source link

tempel-eval function #114

Closed ispringle closed 1 year ago

ispringle commented 1 year ago

Hello, thanks for this great project. I'm wondering how to go about writing a tempel-eval/eval-tempel function. The idea here is a function that can evaluate the region highlighted, similar to eval-region but the evaluated region is consumed by tempel as a new snippet, or overwriting the previously defined snippet.

I'd be happy to do the work to get this implemented, but I was hoping for some guidance here. My lisp skills are pretty subpar and while I've read tempel.el I'm a bit confused how to get about this. I know it's possible since there is an auto reload function to reload the tempel files on save.

minad commented 1 year ago

Something like this?

(defun tempel-eval ()
  (interactive)
  (let ((template (read (buffer-substring-no-properties
                         (region-beginning) (region-end)))))
    (delete-region (region-beginning) (region-end))
    (tempel-insert template)))

EDIT: After rereading your issue again, I think you want something else, which redefines a template? You can define a variable which holds a list of templates, see https://github.com/minad/tempel#adding-template-sources. Then your tempel-eval command could add to this list.

ispringle commented 1 year ago

Thanks for the help, I'll get a look at this tomorrow at work. Really appreciate it.