1
1
Fork
You've already forked templisp
0
An Emacs Lisp template and PHP-like mini-language
  • Emacs Lisp 100%
2026年04月17日 16:36:15 +02:00
README.org Updated to reflect recent changes to TempLisp semantics 2026年04月17日 16:36:15 +02:00
templisp.el Rewrote everything. It actually works now. 2026年04月17日 16:33:58 +02:00

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 of format is 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 eval to produce a value which is then printed to the output stream.
nil and t
are both ignored.
(subform args)
if are special Templisp forms (see below), are used to print the args values differently than the default, for example, formatting integers in hexadecimal. Non-special forms are evaluated as Emacs Lisp forms using eval and 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 which templisp was evaluated, using the date and time format defined in the templisp-date-time global variable.

    Never use setq to set templisp-date-time, override this symbol with a let binding, 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 variable templisp-date-only-format to 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 the terpri Emacs Lisp function to insert a line break into the output stream. See the documentation for terpri to 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 Lisp eval to produce a boolean result. If the boolean result is non-nil, then <TEMPLISP-FORM> is evaluated using the templisp~eval. Only the first <ELISP-FORM> to return non-nil will 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 Lisp eval function, the <BODY> is evaluated with the templisp-eval function only if <CONDITION> evaluates to non-nil.
(unless <CONIDITION> <BODY>...)
Templisp special form, like when but the <BODY> is evaluated only if <CONDITION> evaluates to nil.
(* N form)
Templisp special form, where N is an integer, repeats computing form N times.
(char forms...) or (ch forms...)
Templisp special form, evaluates each form of forms using Emacs Lisp eval to 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. Any forms that are special symbols like :nl: and :dt: behave the same.
(bool forms...)
Templisp special form, evaluates each form of forms using Emacs Lisp eval to produce a sequence of values, each value that is not nil prints "t" to the output stream, each nil prints "nil" to the output stream. Any forms that are special symbols like :nl: and :dt: behave the same.
(math expr)
Templisp special form, where expr may be a string, or another quoted form. The expr is evaluated using calc-eval to 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 as math, bool, or char that evaluate their forms differently.
sym
Templisp form, where sym is 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 using templisp-eval.