bbatsov / adoc-mode

A major-mode for editing AsciiDoc files in Emacs
68 stars 8 forks source link

tempo-template functions accept optional arg but fail when one is passed #26

Open pierre-rouleau opened 1 year ago

pierre-rouleau commented 1 year ago

Most interactive functions are tempo-template functions. Help on these functions report that they support the optional arg but if one uses the optional arg (by typing C-u, for example) the function reports:

Wrong type argument: number-or-market-p nil

For example, I bound <f12> b to tempo-template-adoc-strong. The help shows:

<f12> b runs the command tempo-template-adoc-strong (found in adoc-mode-map),
which is an interactive Lisp function.

It is bound to <f12> b, <menu-bar> <AsciiDoc> <Templates / cheat
sheet> <Text formatting - constrained quotes> <*Strong*>.

(tempo-template-adoc-strong &optional ARG)

Usually rendered bold

This is not really a big deal, but it'd be interesting to see a solution given that the code uses tempo templates.

bbatsov commented 1 year ago

I never got to playing with tempo, as I wasn't sure if that's still relevant today given there are a few newer alternatives around (e.g. https://github.com/bbatsov/adoc-mode/issues/19)

pierre-rouleau commented 1 year ago

As I said, the issue is not a priority. There's no need to use arguments for these simple templates anyway. And I did not look at the code more than to see what was available.

tempo templates, if someone knows elisp, are quite nice once you need to be able to provide templates that 'auto-adjust' to various situations and have logic in them. For simple text insertion it's overkill IMO. But that's the way it was written. I'm using tempo templates in various ways to create programmable file headers for several languages. It could probably be done with the more popular templating system, but doing it with tempo allows writing them in elisp.

I wrote some for C, C++, Erlang. In Erlang it's quite useful to create the boiler plate code while leaving control via some user-options. I provide these in the PEL project I wrote (mainly as a way to learn Emacs and to keep my environment free from corporate swallowing):
See:

For the code:

I normally bind the templates I use often to key bindings so I can create the boiler plate code quickly. Once a template is created and there's several areas to fill, there are key bindings to navigate through the locations that must be filled.

For the Erlang tempo templates, you can take a look at the PDF-based documentation for the key bidings in my ststem at: https://raw.githubusercontent.com/pierre-rouleau/pel/master/doc/pdf/pl-erlang.pdf#page=13 . It's best to look at it on a browser that renders the PDF.

BTW, thanks for mentioning tempel, it does look good.