| README.org | Updated to reflect recent changes to TempLisp semantics | |
| templisp.el | Rewrote everything. It actually works now. | |
- Running a Templisp program
- The statements of a Templisp program
- Built-in special symbols
- Built-in special forms
Templisp is a miniature Lisp language comparable to the PHP language. It is an Embedded Domain Specific Language (EDSL) for generating text.
Running a Templisp program
-
(templisp init forms...) -
macro runs a Templisp program.
-
Arguments:
- INIT
- a Lisp form that is the Templisp program, typically given as a quoted form.
- FORMS
- forms written in the Templisp language. Ordinary strings are inserted into the current buffer. Numbers are formatted with (format "%g"). There are several other forms, all described below.
-
Typically you use quote to quote the form that is your Templisp
program, for example:
(templisp "Hello, today is " :d:)
; ...or, equivalently...
(templisp "Hello, today is " :d:)
You of course may use backquote and the unquote notation to insert
Emacs Lisp values into the Templisp form, however the Templisp
interpreter does allow you to evaluate Emacs Lisp forms with
char, math, eval, and apply, so backquote is usually not
necessary unless you want to create a Templisp macro.
The statements of a Templisp program
- Strings
- any strings in the form are written to the output stream.
- Numbers
- any numbers are formatted using
(format "%g" n)then the result offormatis written to the output stream. The "%g" format code will print integers without decimal points, and will print floats with decimal points. - Symbols
- unless it is a special symbol (see below), the symbol
is eavluated in Emacs Lisp using
evalto produce a value which is then printed to the output stream. -
nilandt - are both ignored.
-
(subform args) - if are special Templisp forms (see below),
are used to print the
argsvalues differently than the default, for example, formatting integers in hexadecimal. Non-special forms are evaluated as Emacs Lisp forms usingevaland the resulting value is printed to the output stream according to the semantics of the Templisp language.
Built-in special symbols
-
:dt:or:date-time:– writes the date and time at whichtemplispwas evaluated, using the date and time format defined in thetemplisp-date-timeglobal variable.Never use
setqto settemplisp-date-time, override this symbol with aletbinding, like so:(let ((templisp-date-time (date-to-time "2026年04月17日T09:35:07"))) (templisp '("So the exact time it occurred was: " :dt:)) )) :d:or:date:– like:dt:except only write the date, not the time. Uses the value of the global variabletemplisp-date-only-formatto write the date.:t:or:time:– like:dt:except only write the time, not the date.:nl:or:newline:or:new-line:or:linebreak:or:line-break:, calls theterpriEmacs Lisp function to insert a line break into the output stream. See the documentation forterprito see how this works.:sp:or:space:inserts a space.
Built-in special forms
-
(cond <CONDITIONS>...) - Templisp special form, works much
like Emacs Lisp
cond, where<CONDITIONS>are of the form:(<ELISP-FORM> <TEMPLISP-FORM>)The<ELISP-FORM>is evaluated using Emacs Lispevalto produce a boolean result. If the boolean result is non-nil, then<TEMPLISP-FORM>is evaluated using thetemplisp~eval. Only the first<ELISP-FORM>to return non-nilwill evaluate the templisp form, all others will be ignored. -
(when <CONDITION> <BODY>...) - Templisp special form, works
much like Emacs Lisp
when. The<CONDITION>is evaluated with the Emacs Lispevalfunction, the<BODY>is evaluated with thetemplisp-evalfunction only if<CONDITION>evaluates to non-nil. -
(unless <CONIDITION> <BODY>...) - Templisp special form, like
whenbut the<BODY>is evaluated only if<CONDITION>evaluates tonil. -
(* N form) - Templisp special form, where N is an integer,
repeats computing
formN times. -
(char forms...)or(ch forms...) - Templisp special form,
evaluates each form of
formsusing Emacs Lispevalto produce a sequence of numbers, each number's associated UTF character is inserted into the buffer. This is necessary because Emacs Lisp has no distinction between character and integer values. Anyformsthat are special symbols like:nl:and:dt:behave the same. -
(bool forms...) - Templisp special form, evaluates each form of
formsusing Emacs Lispevalto produce a sequence of values, each value that is notnilprints"t"to the output stream, eachnilprints "nil" to the output stream. Anyformsthat are special symbols like:nl:and:dt:behave the same. -
(math expr) - Templisp special form, where
exprmay be a string, or another quoted form. Theexpris evaluated usingcalc-evalto produce a number, and the number is written to the output stream using Emacs Lisp(format "%g" n). -
(eval forms...) - Templisp function, Evaluate Emacs Lisp
forms, the result of evaluation is then evaluated by
templisp-eval, so forms that result in strings are inserted into the output string. -
(print forms...)or(pp forms...) - Templisp function,
Evaluates Templisp forms using
templisp-eval. This is useful when you want to evaluate forms using Templisp from within a Templisp special form such asmath,bool, orcharthat evaluate their forms differently. -
sym - Templisp form, where
symis an Emacs Lisp symbol, if not a special symbol (see above), will be looked-up in the Emacs Lisp environment as a variable, and the result will be evaluated usingtemplisp-eval.