Next: compile-dwim, Previous: tabbar-x, Up: Top
tempo.el is a extensible library for abbrevs. It provide more features than skeleton.el, such as move between marks, names for prompt, user elements and so on. tempo-x.el provides some commands and additional elements that may helpful.
A simple command to enable expand tempo like abbrev. The command
tempo-space
given by the author of tempo.el is not compatiable for abbrev-mode.
Reinstall new tempo template for all buffer. If you defined a new tempo-template in certain tag-list, you can't use it intermediately. Call the commands to force build connections for all buffer again.
Here is a list of new elements:
“pi” and “Pi” like standard tempo element “p” except they can have a default value and can be completing read.
The beta version of tempo.el also implement new prompt element, but I still an element that can accept default value. PROMPT can be a string or a list. When it is a string, it is like standard tempo element
p
, but you can give a DEFAULT string. If it is a list, the prompt will be the parameters ofcompleting-read
. But you should give the default value in DEFAULT not in PROMPT.Here is some example:
(pi "variable: " "foo" var) (pi ("variable: " ("foo" "bar")) "foo" var)
skeleton has some handy elements to control recursive expanding. “R” is such tempo elements to do this job. The syntax of the element is:
(R before-test-elements (& condition final-form) after-test-elements)
First it insert BEFORE-TEST-ELEMENTS to buffer. then test the
CONDITION, if the CONDITION is null, eval FINAL-FORM and quit the
loop. Otherwise insert AFTER-TEST-ELEMENTS and back to start. The
CONDITION can be a name saved in BEFORE-TEST-ELEMENTS, it will
automatic clean after test, so you will be prompt again. If you want
use it after test, backup it by yourself. The CONDITION also can be a
list, which CAR is a list of names will be used and will be clean
after test.
A special variable recursion-start
is available is FINAL-FORM,
you can use it to clean up recent insertion in BEFORE-TEST-ELEMENTS.
Here is a example to show how to use it:
(tempo-define-template "sh-if" '("if " (pi "condition: " ("[ ]" . 3)) "; then" > n> p > n> (R "elif " (pi "condition: " ("[ ]" . 3) condition) (& ((condition) (string-match "\\[\\s-*]" condition)) (delete-region recursion-start (point))) "; then" > n> p > n>) "else" > n> p n> "fi" > n>))
Try it by M-x tempo-template-sh-if in sh-mode.
If you want use this only, you can try tempo-snippets.el
,
tempo-x.el
borrow most of functions from there to implement a
new element instead of new template style.
“snippet” enable visualize the template field, and can update form when editing. The syntax of “snippet” is:
(snippet (S name &optional display insert) (F (vars) forms))
“S” insert a field, the first NAME will be the source and other field with the same NAME become mirrors. Change the source will also change mirrors. DISPLAY is the text to insert to the field, default is the `symbol-name' of NAME. INSERT is non-nil means the DISPLAY is the default text, you can make change to the text. Otherwise the text will be erase after any changes in front of field.
“F” insert an form. The VARS is a list of NAME used in fields. the evaled result will insert into the buffer. When any fields in VARS changed, the text of form will change too.
A example will show how to use it easier:
(tempo-define-template "perl-open" '((snippet "open(" (S FH "my $fh" t) ", \"" (S op "<") "\", " (S file "$file") ") or die \"Can't " (F (op) (if (string-match ">" op) "create" "open")) " file " (F (file) (replace-regexp-in-string "['\"]?\\(.*\\)['\"]" "\\1" file)) ": $!\";" n>)))
After expand the template, insert string like:
open([my $fh], "[<]", [$file]) or die "Can't {open} file {$file}: $!";
the text inside “[]” indicate as a field, and text inside “{}” indicate as a form, the when text inside the field changes, the assicated form will update too. For example if you change open mode from “<” to “>”, the form “open” will change to “create”. If change “$file” to “"file"” the form will change to “file” with quote removed.