>> Max Nikulin writes: >> >>>>> For others, if we are at it, I think it is much better to type >>>>> (princ default-directory) than (eval default-directory) >>> [...] >>>> Maybe simply identity? (although it feels long) >>> >>> I would avoid `eval' besides cases where it is strictly necessary. That >>> is why I think `identity' or its shorter alias limited to template >>> expansion will be better. >> >> Why? %(...) is passed through org-eval anyway. > > I believe, we should not encourage unnecessary calls of `eval' by using > it in docs. Users may add this dangerous function to their code just > because they see it too often.
That was what I thought as well when I wrote eval should not be used. > By the way, what about `or'? Overhead in comparison to `identity' should > not be noticeable for capture templates. Yeah, it is only two letter indeed. Both eval and or, suffer from the same problem, as long as the original inserting function expects string: they will work only with strings. Also, while I have no problems with such code, I don't think it is very idiomatic use of 'or' so to say. It is quite unconventional, and frankly, is rather treating a symptom than the problem. > (org-capture-fill-template "System name %(or system-name)") > > For me 3 extra characters for variables is better than nested Considering Emacs convention, those three characters would turn into 7: "org-var". > parenthesis for function call. Of course, it is a kind of hack and it > signals error for non-string values (just like `eval'). Perhaps %(format > "%s" system-type) should be mentioned as well. Yeah, format and prin1-to-string should work. They are just so lengthy. But again, it does not matter for small templates, like as they are used in ordinary org-capture. > What I do not like is that error is not signaled in the case of > > (org-capture-fill-template "Non-existing function %(sometypo 10)") > "Non-existing function %![Error: (void-function sometypo)] > " An error is signaled, but its not very pretty: (org-capture-fill-template "%(eval blah)") Debugger entered--Lisp error: (void-function org-capture-expand-embedded-elisp) (org-capture-expand-embedded-elisp 'mark) (progn (switch-to-buffer-other-window (get-buffer-create "*Capture*")) (erase-buffer) (setq buffer-file-name nil) (setq mark-active nil) (insert template) (org-mode) (goto-char (point-min)) .... That is the current behaviour. Do you mean, the error is not catched, and some error text not inserted into the template? I believe that one is actually fixable. I haven't had time to look at the fill-template function, but as certainly doable.
