-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional named field argument for custom user element hooks #153
base: main
Are you sure you want to change the base?
Optional named field argument for custom user element hooks #153
Conversation
Thanks. Can you please provide a simple example in the README which is not artificial, something one would actually want to use, like |
I've added an example. I wish that I have a shorter example better suited for README, but I cannot come up with a clever idea right now. The example is close to my current use case. If you have another suggestion, I'd update accordingly. |
Hmm, I wonder about this example. I think the right way to implement this would be to read the file name via Can we think of something more basic? Something which uses the variables in some more direct way? Maybe some examples which performs some computations? On the other hand we can already embed arbitrary Lisp FORMS in Tempel. Ideally I would want an example which people would want to use directly, similar to the (header ";;; " (file-name-nondirectory (or (buffer-file-name) (buffer-name)))
" --- " p " -*- lexical-binding: t -*-" n
";;; Commentary:" n ";;; Code:" 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)) ;; uses my tempel-include user element To be clear, I think every addition should be justified and if we cannot come up with a reasonable example, I think the addition is not justified and we should maybe not add it. Note that every addition limits our future options and increases complexity. |
I fully agree with keeping the API clean. It's not like I am strongly advocating for this to get merged, and I would've used another option if my use case was covered by it. Let me explain what led me here.
My main goal was to load a source code template from a local file, which may be shared with tools outside Emacs. So I cannot simply migrate it and have it as a tempel template. And I didn't necessarily want to set the file name interactively, as the template files are stored in a vault and wanted to cover the use case in which the file name is inferred from something else (e.g., the tempel template name suffixed with Being a template, variable expansion is obviously useful, so I looked for a way to perform named field expansion on an arbitrary string. It didn't seem it's supported by an existing feature, so I turned to the custom user element with which an "arbitrary" hook can be written with flexibility. If I were to strongly advocate for custom user element hooks to (optionally) take in (Writing the last paragraph, I realized another option might be to write a regular elisp function, and use the "form" extension to achieve similar goals; but then, the explicit access to With all that said, I do wish there was a more compleling, simpler use case to show case in README that strongly justifies the usefulness of named fields being available inside the hooks. In any case, this is where I came from. Thanks for your patience. |
I mean it makes sense to have context access in the custom elements, like we have in form elements. But for forms it is completely obvious that we need it, since the most trivial computations based on other fields require it. This means an Elisp function called in a form works too in many cases. User elements are also a little bit of a different beast, since they return a new template list, which is interpreted again, and not a string. The addition is simple enough, so we could as well merge it. I just don't like the idea of not having a simple example to show, which means that we miss some understanding. Maybe the idea of user elements is wrong and unnecessary in the first place since one could maybe always use forms, except for the verbosity (user elements may be a bit of a legacy concept inherited from tempo)? In any case, it seems there is no urgency to get this merged, so we can as well let this rest for a while until we come up with something. |
Sounds good to me. I'll come back and add a comment if I come up with a simpler demo. (Someone else might also chime in with another use case.) |
This PR
See #152 for the wider context.