117 |
(defcustom tempo-interactive nil |
(defcustom tempo-interactive nil |
118 |
"*Prompt user for strings in templates. |
"*Prompt user for strings in templates. |
119 |
If this variable is non-nil, `tempo-insert' prompts the |
If this variable is non-nil, `tempo-insert' prompts the |
120 |
user for text to insert in the templates" |
user for text to insert in the templates." |
121 |
:type 'boolean |
:type 'boolean |
122 |
:group 'tempo) |
:group 'tempo) |
123 |
|
|
133 |
|
|
134 |
(defcustom tempo-show-completion-buffer t |
(defcustom tempo-show-completion-buffer t |
135 |
"*If non-nil, show a buffer with possible completions, when only |
"*If non-nil, show a buffer with possible completions, when only |
136 |
a partial completion can be found" |
a partial completion can be found." |
137 |
:type 'boolean |
:type 'boolean |
138 |
:group 'tempo) |
:group 'tempo) |
139 |
|
|
148 |
(defvar tempo-insert-string-functions nil |
(defvar tempo-insert-string-functions nil |
149 |
"List of functions to run when inserting a string. |
"List of functions to run when inserting a string. |
150 |
Each function is called with a single arg, STRING and should return |
Each function is called with a single arg, STRING and should return |
151 |
another string. This could be used for making all strings upcase by |
another string. This could be used for making all strings upcase by |
152 |
setting it to '(upcase), for example.") |
setting it to '(upcase), for example.") |
153 |
|
|
154 |
(defvar tempo-tags nil |
(defvar tempo-tags nil |
155 |
"An association list with tags and corresponding templates") |
"An association list with tags and corresponding templates.") |
156 |
|
|
157 |
(defvar tempo-local-tags '((tempo-tags . nil)) |
(defvar tempo-local-tags '((tempo-tags . nil)) |
158 |
"A list of locally installed tag completion lists. |
"A list of locally installed tag completion lists. |
159 |
It is a association list where the car of every element is a symbol |
It is a association list where the car of every element is a symbol |
160 |
whose variable value is a template list. The cdr part, if non-nil, is a |
whose variable value is a template list. The cdr part, if non-nil, |
161 |
function or a regexp that defines the string to match. See the |
is a function or a regexp that defines the string to match. See the |
162 |
documentation for the function `tempo-complete-tag' for more info. |
documentation for the function `tempo-complete-tag' for more info. |
163 |
|
|
164 |
`tempo-tags' is always in the last position in this list.") |
`tempo-tags' is always in the last position in this list.") |
175 |
(defvar tempo-match-finder "\\b\\([[:word:]]+\\)\\=" |
(defvar tempo-match-finder "\\b\\([[:word:]]+\\)\\=" |
176 |
"The regexp or function used to find the string to match against tags. |
"The regexp or function used to find the string to match against tags. |
177 |
|
|
178 |
If `tempo-match-finder is a string, it should contain a regular |
If `tempo-match-finder' is a string, it should contain a regular |
179 |
expression with at least one \\( \\) pair. When searching for tags, |
expression with at least one \\( \\) pair. When searching for tags, |
180 |
`tempo-complete-tag' calls `re-search-backward' with this string, and |
`tempo-complete-tag' calls `re-search-backward' with this string, and |
181 |
the string between the first \\( and \\) is used for matching against |
the string between the first \\( and \\) is used for matching against |
182 |
each string in the tag list. If one is found, the whole text between |
each string in the tag list. If one is found, the whole text between |
229 |
list of elements in the template, TAG is the tag used for completion, |
list of elements in the template, TAG is the tag used for completion, |
230 |
DOCUMENTATION is the documentation string for the insertion command |
DOCUMENTATION is the documentation string for the insertion command |
231 |
created, and TAGLIST (a symbol) is the tag list that TAG (if provided) |
created, and TAGLIST (a symbol) is the tag list that TAG (if provided) |
232 |
should be added to). If TAGLIST is nil and TAG is non-nil, TAG is |
should be added to. If TAGLIST is nil and TAG is non-nil, TAG is |
233 |
added to `tempo-tags' |
added to `tempo-tags'. |
234 |
|
|
235 |
The elements in ELEMENTS can be of several types: |
The elements in ELEMENTS can be of several types: |
236 |
|
|
237 |
- A string. It is sent to the hooks in `tempo-insert-string-functions', |
- A string: It is sent to the hooks in `tempo-insert-string-functions', |
238 |
and the result is inserted. |
and the result is inserted. |
239 |
- The symbol 'p. This position is saved in `tempo-marks'. |
- The symbol `p': This position is saved in `tempo-marks'. |
240 |
- The symbol 'r. If `tempo-insert' is called with ON-REGION non-nil |
- The symbol `r': If `tempo-insert' is called with ON-REGION non-nil |
241 |
the current region is placed here. Otherwise it works like 'p. |
the current region is placed here. Otherwise it works like `p'. |
242 |
- (p PROMPT <NAME> <NOINSERT>) If `tempo-interactive' is non-nil, the |
- (p PROMPT <NAME> <NOINSERT>): If `tempo-interactive' is non-nil, the |
243 |
user is prompted in the minibuffer with PROMPT for a string to be |
user is prompted in the minibuffer with PROMPT for a string to be |
244 |
inserted. If the optional parameter NAME is non-nil, the text is |
inserted. If the optional parameter NAME is non-nil, the text is |
245 |
saved for later insertion with the `s' tag. If there already is |
saved for later insertion with the `s' tag. If there already is |
246 |
something saved under NAME that value is used instead and no |
something saved under NAME that value is used instead and no |
247 |
prompting is made. If NOINSERT is provided and non-nil, nothing is |
prompting is made. If NOINSERT is provided and non-nil, nothing is |
248 |
inserted, but text is still saved when a NAME is provided. For |
inserted, but text is still saved when a NAME is provided. For |
249 |
clarity, the symbol 'noinsert should be used as argument. |
clarity, the symbol `noinsert' should be used as argument. |
250 |
- (P PROMPT <NAME> <NOINSERT>) Works just like the previous tag, but |
- (P PROMPT <NAME> <NOINSERT>): Works just like the previous tag, but |
251 |
forces tempo-interactive to be true. |
forces `tempo-interactive' to be true. |
252 |
- (r PROMPT <NAME> <NOINSERT>) like the previous, but if |
- (r PROMPT <NAME> <NOINSERT>): Like the previous tag, but if |
253 |
`tempo-interactive' is nil and `tempo-insert' is called with |
`tempo-interactive' is nil and `tempo-insert' is called with |
254 |
ON-REGION non-nil, the current region is placed here. This usually |
ON-REGION non-nil, the current region is placed here. This usually |
255 |
happens when you call the template function with a prefix argument. |
happens when you call the template function with a prefix argument. |
256 |
- (s NAME) Inserts text previously read with the (p ..) construct. |
- (s NAME): Inserts text previously read with the (p ..) construct. |
257 |
Finds the insertion saved under NAME and inserts it. Acts like 'p |
Finds the insertion saved under NAME and inserts it. Acts like `p' |
258 |
if tempo-interactive is nil. |
if tempo-interactive is nil. |
259 |
- '& If there is only whitespace between the line start and point, |
- `&': If there is only whitespace between the line start and point, |
260 |
nothing happens. Otherwise a newline is inserted. |
nothing happens. Otherwise a newline is inserted. |
261 |
- '% If there is only whitespace between point and end-of-line |
- `%': If there is only whitespace between point and end of line, |
262 |
nothing happens. Otherwise a newline is inserted. |
nothing happens. Otherwise a newline is inserted. |
263 |
- 'n inserts a newline. |
- `n': Inserts a newline. |
264 |
- '> The line is indented using `indent-according-to-mode'. Note that |
- `>': The line is indented using `indent-according-to-mode'. Note |
265 |
you often should place this item after the text you want on the |
that you often should place this item after the text you want on |
266 |
line. |
the line. |
267 |
- 'r> Like r, but it also indents the region. |
- `r>': Like `r', but it also indents the region. |
268 |
- 'n> Inserts a newline and indents line. |
- `n>': Inserts a newline and indents line. |
269 |
- 'o Like '% but leaves the point before the newline. |
- `o': Like `%' but leaves the point before the newline. |
270 |
- nil. It is ignored. |
- nil: It is ignored. |
271 |
- Anything else. It is evaluated and the result is treated as an |
- Anything else: It is evaluated and the result is treated as an |
272 |
element to be inserted. One additional tag is useful for these |
element to be inserted. One additional tag is useful for these |
273 |
cases. If an expression returns a list '(l foo bar), the elements |
cases. If an expression returns a list '(l foo bar), the elements |
274 |
after 'l will be inserted according to the usual rules. This makes |
after `l' will be inserted according to the usual rules. This makes |
275 |
it possible to return several elements from one expression." |
it possible to return several elements from one expression." |
|
|
|
276 |
(let* ((template-name (intern (concat "tempo-template-" |
(let* ((template-name (intern (concat "tempo-template-" |
277 |
name))) |
name))) |
278 |
(command-name template-name)) |
(command-name template-name)) |
295 |
(defun tempo-insert-template (template on-region) |
(defun tempo-insert-template (template on-region) |
296 |
"Insert a template. |
"Insert a template. |
297 |
TEMPLATE is the template to be inserted. If ON-REGION is non-nil the |
TEMPLATE is the template to be inserted. If ON-REGION is non-nil the |
298 |
`r' elements are replaced with the current region. In Transient Mark |
`r' elements are replaced with the current region. In Transient Mark |
299 |
mode, ON-REGION is ignored and assumed true if the region is active." |
mode, ON-REGION is ignored and assumed true if the region is active." |
300 |
(unwind-protect |
(unwind-protect |
301 |
(progn |
(progn |
398 |
;;; tempo-insert-prompt |
;;; tempo-insert-prompt |
399 |
|
|
400 |
(defun tempo-insert-prompt-compat (prompt) |
(defun tempo-insert-prompt-compat (prompt) |
401 |
"Compatibility hack for tempo-insert-prompt. |
"Compatibility hack for `tempo-insert-prompt'. |
402 |
PROMPT can be either a prompt string, or a list of arguments to |
PROMPT can be either a prompt string, or a list of arguments to |
403 |
tempo-insert-prompt, or nil." |
`tempo-insert-prompt', or nil." |
404 |
(if (consp prompt) ; not nil either |
(if (consp prompt) ; not nil either |
405 |
(apply 'tempo-insert-prompt prompt) |
(apply 'tempo-insert-prompt prompt) |
406 |
(tempo-insert-prompt prompt))) |
(tempo-insert-prompt prompt))) |
409 |
"Prompt for a text string and insert it in the current buffer. |
"Prompt for a text string and insert it in the current buffer. |
410 |
If the variable `tempo-interactive' is non-nil the user is prompted |
If the variable `tempo-interactive' is non-nil the user is prompted |
411 |
for a string in the minibuffer, which is then inserted in the current |
for a string in the minibuffer, which is then inserted in the current |
412 |
buffer. If `tempo-interactive' is nil, the current point is placed on |
buffer. If `tempo-interactive' is nil, the current point is placed on |
413 |
`tempo-mark'. |
`tempo-mark'. |
414 |
|
|
415 |
PROMPT is the prompt string, SAVE-NAME is a name to save the inserted |
PROMPT is the prompt string, SAVE-NAME is a name to save the inserted |
416 |
text under. If the optional argument NO-INSERT is non-nil, no text i |
text under. If the optional argument NO-INSERT is non-nil, no text is |
417 |
inserted. This can be useful when there is a SAVE-NAME. |
inserted. This can be useful when there is a SAVE-NAME. |
418 |
|
|
419 |
If there already is a value for SAVE-NAME, it is used and the user is |
If there already is a value for SAVE-NAME, it is used and the user is |
420 |
never prompted." |
never prompted." |
447 |
;;; tempo-is-user-element |
;;; tempo-is-user-element |
448 |
|
|
449 |
(defun tempo-is-user-element (element) |
(defun tempo-is-user-element (element) |
450 |
"Tries all the user-defined element handlers in |
"Tries all the user-defined element handlers in `tempo-user-elements'." |
|
`tempo-user-elements'" |
|
451 |
;; Sigh... I need (some list) |
;; Sigh... I need (some list) |
452 |
(catch 'found |
(catch 'found |
453 |
(mapcar (function (lambda (handler) |
(mapcar (function (lambda (handler) |
529 |
;;; tempo-insert-mark |
;;; tempo-insert-mark |
530 |
|
|
531 |
(defun tempo-insert-mark (mark) |
(defun tempo-insert-mark (mark) |
532 |
"Insert a mark `tempo-marks' while keeping it sorted" |
"Insert a mark `tempo-marks' while keeping it sorted." |
533 |
(cond ((null tempo-marks) (setq tempo-marks (list mark))) |
(cond ((null tempo-marks) (setq tempo-marks (list mark))) |
534 |
((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks))) |
((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks))) |
535 |
(t (let ((lp tempo-marks)) |
(t (let ((lp tempo-marks)) |
601 |
|
|
602 |
COMPLETION-FUNCTION is an obsolete option for specifying an optional |
COMPLETION-FUNCTION is an obsolete option for specifying an optional |
603 |
function or string that is used by `\\[tempo-complete-tag]' to find a |
function or string that is used by `\\[tempo-complete-tag]' to find a |
604 |
string to match the tag against. It has the same definition as the |
string to match the tag against. It has the same definition as the |
605 |
variable `tempo-match-finder'. In this version, supplying a |
variable `tempo-match-finder'. In this version, supplying a |
606 |
COMPLETION-FUNCTION just sets `tempo-match-finder' locally." |
COMPLETION-FUNCTION just sets `tempo-match-finder' locally." |
607 |
(let ((old (assq tag-list tempo-local-tags))) |
(let ((old (assq tag-list tempo-local-tags))) |
608 |
(if old |
(if old |
645 |
|
|
646 |
(defun tempo-find-match-string (finder) |
(defun tempo-find-match-string (finder) |
647 |
"Find a string to be matched against a tag list. |
"Find a string to be matched against a tag list. |
648 |
FINDER is a function or a string. Returns (STRING . POS), or nil |
FINDER is a function or a string. Returns (STRING . POS), or nil |
649 |
if no reasonable string is found." |
if no reasonable string is found." |
650 |
(cond ((stringp finder) |
(cond ((stringp finder) |
651 |
(let (successful) |
(let (successful) |
669 |
All the tags in the tag lists in `tempo-local-tags' |
All the tags in the tag lists in `tempo-local-tags' |
670 |
\(this includes `tempo-tags') are searched for a match for the text |
\(this includes `tempo-tags') are searched for a match for the text |
671 |
before the point. The way the string to match for is determined can |
before the point. The way the string to match for is determined can |
672 |
be altered with the variable `tempo-match-finder'. If |
be altered with the variable `tempo-match-finder'. If |
673 |
`tempo-match-finder' returns nil, then the results are the same as |
`tempo-match-finder' returns nil, then the results are the same as |
674 |
no match at all. |
no match at all. |
675 |
|
|