Mercurial > emacs
annotate lisp/tempo.el @ 11208:18107abf5df3
(tempo-build-collection): Clear flag after computing
return value.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 05 Apr 1995 19:32:55 +0000 |
parents | 577f71dad5c3 |
children | e6bdaaa6ce1b |
rev | line source |
---|---|
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
1 ;;; tempo.el --- Flexible template insertion |
7267 | 2 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
3 | |
7296 | 4 ;; Author: David K}gedal <davidk@lysator.liu.se > |
7267 | 5 ;; Created: 16 Feb 1994 |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
6 ;; Version: 1.2.2 |
7267 | 7 ;; Keywords: extensions, languages, tools |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
8 ;; $Revision: 1.6 $ |
7267 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; This file provides a simple way to define powerful templates, or | |
29 ;; macros, if you wish. It is mainly intended for, but not limited to, | |
30 ;; other programmers to be used for creating shortcuts for editing | |
31 ;; certain kind of documents. It was originally written to be used by | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
32 ;; a HTML editing mode written by Nelson Minar <nelson@santafe.edu>, |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
33 ;; and his html-helper-mode.el is probably the best example of how to |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
34 ;; use this program. |
7267 | 35 |
36 ;; A template is defined as a list of items to be inserted in the | |
37 ;; current buffer at point. Some of the items can be simple strings, | |
38 ;; while other can control formatting or define special points of | |
39 ;; interest in the inserted text. | |
40 | |
41 ;; If a template defines a "point of interest" that point is inserted | |
42 ;; in a buffer-local list of "points of interest" that the user can | |
43 ;; jump between with the commands `tempo-backward-mark' and | |
44 ;; `tempo-forward-mark'. If the template definer provides a prompt for | |
45 ;; the point, and the variable `tempo-interactive' is non-nil, the | |
46 ;; user will be prompted for a string to be inserted in the buffer, | |
47 ;; using the minibuffer. | |
48 | |
49 ;; The template can also define one point to be replaced with the | |
50 ;; current region if the template command is called with a prefix (or | |
51 ;; a non-nil argument). | |
52 | |
53 ;; More flexible templates can be created by including lisp symbols, | |
54 ;; which will be evaluated as variables, or lists, which will will be | |
55 ;; evaluated as lisp expressions. | |
56 | |
57 ;; See the documentation for tempo-define-template for the different | |
58 ;; items that can be used to define a tempo template. | |
59 | |
60 ;; One of the more powerful features of tempo templates are automatic | |
61 ;; completion. With every template can be assigned a special tag that | |
62 ;; should be recognized by `tempo-complete-tag' and expanded to the | |
63 ;; complete template. By default the tags are added to a global list | |
64 ;; of template tags, and are matched against the last word before | |
65 ;; point. But if you assign your tags to a specific list, you can also | |
66 ;; specify another method for matching text in the buffer against the | |
67 ;; tags. In the HTML mode, for instance, the tags are matched against | |
68 ;; the text between the last `<' and point. | |
69 | |
70 ;; When defining a template named `foo', a symbol named | |
71 ;; `tempo-template-foo' will be created whose value as a variable will | |
72 ;; be the template definition, and its function value will be an | |
73 ;; interactive function that inserts the template at the point. | |
74 | |
75 ;; The latest tempo.el distribution can be fetched from | |
76 ;; ftp.lysator.liu.se in the directory /pub/emacs | |
77 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
78 ;;; Known bugs: |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
79 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
80 ;; If the 'o is the first element in a template, strange things can |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
81 ;; happen when the template is inserted at the beginning of a |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
82 ;; line. This is due to strange behaviour in open-line. But it should |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
83 ;; be easily avoided. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
84 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
85 ;; The 'o tag is also a problem when including the region. This will |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
86 ;; be looked into. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
87 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
88 ;; Clicking mouse-2 in the completion buffer gives strange results. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
89 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
90 ;; There is a bug in some emacs versions that prevents completion from |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
91 ;; working. If it doesn't work for you, send me a note indicating your |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
92 ;; emacs version and your problems. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
93 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
94 ;;; Contributors: |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
95 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
96 ;; These people have given me importand feedback and new ideas for |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
97 ;; tempo.el. Thanks. |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
98 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
99 ;; Nelson Minar <nelson@santafe.edu> |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
100 ;; Richard Stallman <rms@gnu.ai.mit.edu> |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
101 ;; Lars Lindberg <Lars.Lindberg@sypro.cap.se> |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
102 ;; Glen Whitney <Glen.Whitney@math.lsa.umich.edu> |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
103 |
7267 | 104 ;;; Code: |
105 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
106 ;; (provide 'tempo) |
7267 | 107 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
108 ;;; User options |
7267 | 109 |
110 (defvar tempo-interactive nil | |
111 "*Prompt user for strings in templates. | |
112 If this variable is non-nil, `tempo-insert' prompts the | |
113 user for text to insert in the templates") | |
114 | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
115 (defvar tempo-insert-region nil |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
116 "*Automatically insert current region when there is a `r' in the template |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
117 If this variable is NIL, `r' elements will be treated just like `p' |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
118 elements, unless the template function is given a prefix (or a non-nil |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
119 argument). If this variable is non-NIL, the behaviour is reversed. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
120 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
121 In Transient Mark mode, this option is unused.") |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
122 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
123 (defvar tempo-show-completion-buffer t |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
124 "*If non-NIL, show a buffer with possible completions, when only |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
125 a partial completion can be found") |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
126 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
127 (defvar tempo-leave-completion-buffer nil |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
128 "*If NIL, a completion buffer generated by \\[tempo-complete-tag] |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
129 disappears at the next keypress; otherwise, it remains forever.") |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
130 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
131 ;;; Internal variables |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
132 |
7267 | 133 (defvar tempo-insert-string-functions nil |
134 "List of functions to run when inserting a string. | |
135 Each function is called with a single arg, STRING." ) | |
136 | |
137 (defvar tempo-tags nil | |
138 "An association list with tags and corresponding templates") | |
139 | |
140 (defvar tempo-local-tags '((tempo-tags . nil)) | |
141 "A list of locally installed tag completion lists. | |
142 It is a association list where the car of every element is a symbol | |
143 whose varable value is a template list. The cdr part, if non-nil, is a | |
144 function or a regexp that defines the string to match. See the | |
145 documentation for the function `tempo-complete-tag' for more info. | |
146 | |
147 `tempo-tags' is always in the last position in this list.") | |
148 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
149 (defvar tempo-collection nil |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
150 "A collection of all the tags defined for the current buffer.") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
151 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
152 (defvar tempo-dirty-collection t |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
153 "Indicates if the tag collection needs to be rebuilt.") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
154 |
7267 | 155 (defvar tempo-marks nil |
156 "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.") | |
157 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
158 (defvar tempo-match-finder "\\b\\([^\\b]+\\)\\=" |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
159 "The regexp or function used to find the string to match against tags. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
160 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
161 If `tempo-match-finder is a string, it should contain a regular |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
162 expression with at least one \\( \\) pair. When searching for tags, |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
163 `tempo-complete-tag' calls `re-search-backward' with this string, and |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
164 the string between the first \\( and \\) is used for matching against |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
165 each string in the tag list. If one is found, the whole text between |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
166 the first \\( and the point is replaced with the inserted template. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
167 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
168 You will probably want to include \\ \= at the end of the regexp to |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
169 make sure that the string is matched only against text adjacent to the |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
170 point. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
171 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
172 If `tempo-match-finder' is a symbol, it should be a function that |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
173 returns a pair of the form (STRING . POS), where STRING is the string |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
174 used for matching and POS is the buffer position after which text |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
175 should be replaced with a template.") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
176 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
177 (defvar tempo-user-elements nil |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
178 "Element handlers for user-defined elements. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
179 A list of symbols which are bound to functions that take one argument. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
180 This function should return somthing to be sent to `tempo-insert' if |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
181 it recognizes the argument, and NIL otherwise") |
7267 | 182 |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
183 (defvar tempo-named-insertions nil |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
184 "Temporary storage for named insertions") |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
185 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
186 (defvar tempo-region-start (make-marker) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
187 "Region start when inserting around the region") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
188 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
189 (defvar tempo-region-stop (make-marker) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
190 "Region stop when inserting around the region") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
191 |
7267 | 192 ;; Make some variables local to every buffer |
193 | |
194 (make-variable-buffer-local 'tempo-marks) | |
195 (make-variable-buffer-local 'tempo-local-tags) | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
196 (make-variable-buffer-local 'tempo-match-finder) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
197 (make-variable-buffer-local 'tempo-collection) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
198 (make-variable-buffer-local 'tempo-dirty-collection) |
7267 | 199 |
200 ;;; Functions | |
201 | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
202 ;;; First some useful functions and macros |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
203 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
204 (defun tempo-mapc (fun lst) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
205 (if (null lst) nil |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
206 (funcall fun (car lst)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
207 (tempo-mapc fun (cdr lst)))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
208 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
209 (defmacro tempo-dolist (il &rest forms) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
210 (let ((i (car il)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
211 (l (car (cdr il)))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
212 (list 'tempo-mapc |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
213 (list 'function (append (list 'lambda |
11202
577f71dad5c3
(tempo-dolist): Don't use `cadr'.
Karl Heuer <kwzh@gnu.org>
parents:
11196
diff
changeset
|
214 (list i)) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
215 forms)) |
11202
577f71dad5c3
(tempo-dolist): Don't use `cadr'.
Karl Heuer <kwzh@gnu.org>
parents:
11196
diff
changeset
|
216 l))) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
217 (put 'tempo-dolist 'lisp-indent-function 1) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
218 |
7267 | 219 ;; |
220 ;; tempo-define-template | |
221 | |
222 (defun tempo-define-template (name elements &optional tag documentation taglist) | |
223 "Define a template. | |
224 This function creates a template variable `tempo-template-NAME' and an | |
225 interactive function `tempo-template-NAME' that inserts the template | |
226 at the point. The created function is returned. | |
227 | |
228 NAME is a string that contains the name of the template, ELEMENTS is a | |
229 list of elements in the template, TAG is the tag used for completion, | |
230 DOCUMENTATION is the documentation string for the insertion command | |
231 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 | |
233 added to `tempo-tags' | |
234 | |
235 The elements in ELEMENTS can be of several types: | |
236 | |
237 - A string. It is sent to the hooks in `tempo-insert-string-functions', | |
238 and the result is inserted. | |
239 - The symbol 'p. This position is saved in `tempo-marks'. | |
240 - 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. | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
242 - (p PROMPT <NAME>) If `tempo-interactive' is non-nil, the user is |
7267 | 243 prompted in the minbuffer with PROMPT for a string to be inserted. |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
244 If the optional parameter NAME is non-nil, the text is saved for |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
245 later insertion with the `s' tag. |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
246 If `tempo-interactive' is nil, it works like 'p. |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
247 - (r PROMPT) like the previous, but if `tempo-interactive' is nil |
7267 | 248 and `tempo-insert' is called with ON-REGION non-nil, the current |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
249 region is placed here. This usually happens when you call the |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
250 template function with a prefix argument. |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
251 - (s NAME) Inserts text previously read with the (p ..) construct. |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
252 Finds the insertion saved under NAME and inserts it. Acts like 'p |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
253 if tempo-interactive is nil. |
7267 | 254 - '& If there is only whitespace between the line start and point, |
255 nothing happens. Otherwise a newline is inserted. | |
256 - '% If there is only whitespace between point and end-of-line | |
257 nothing happens. Otherwise a newline is inserted. | |
258 - 'n inserts a newline. | |
259 - '> The line is indented using `indent-according-to-mode'. Note that | |
260 you often should place this item after the text you want on the | |
261 line. | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
262 - 'n> Inserts a newline and indents line. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
263 - 'o Like '% but leaves the point before the newline. |
7267 | 264 - nil. It is ignored. |
265 - Anything else. It is evaluated and the result is parsed again." | |
266 | |
267 (let* ((template-name (intern (concat "tempo-template-" | |
268 name))) | |
269 (command-name template-name)) | |
270 (set template-name elements) | |
271 (fset command-name (list 'lambda (list '&optional 'arg) | |
272 (or documentation | |
273 (concat "Insert a " name ".")) | |
274 (list 'interactive "*P") | |
275 (list 'tempo-insert-template (list 'quote | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
276 template-name) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
277 (list 'if 'tempo-insert-region |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
278 (list 'not 'arg) 'arg)))) |
7267 | 279 (and tag |
280 (tempo-add-tag tag template-name taglist)) | |
281 command-name)) | |
282 | |
283 ;;; | |
284 ;;; tempo-insert-template | |
285 | |
286 (defun tempo-insert-template (template on-region) | |
287 "Insert a template. | |
288 TEMPLATE is the template to be inserted. If ON-REGION is non-nil the | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
289 `r' elements are replaced with the current region. In Transient Mark |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
290 mode, ON-REGION is ignored and assumed true if the region is active." |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
291 (if (and (boundp 'transient-mark-mode) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
292 transient-mark-mode |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
293 mark-active) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
294 (setq on-region t)) |
7267 | 295 (and on-region |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
296 (set-marker tempo-region-start (min (mark) (point))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
297 (set-marker tempo-region-stop (max (mark) (point)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
298 (if on-region |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
299 (goto-char tempo-region-start)) |
7267 | 300 (save-excursion |
301 (tempo-insert-mark (point-marker)) | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
302 (mapcar (function (lambda (elt) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
303 (tempo-insert elt on-region))) |
7267 | 304 (symbol-value template)) |
305 (tempo-insert-mark (point-marker))) | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
306 (tempo-forward-mark) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
307 (tempo-forget-insertions) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
308 (and (boundp 'transient-mark-mode) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
309 transient-mark-mode |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
310 (deactivate-mark))) |
7267 | 311 |
312 ;;; | |
313 ;;; tempo-insert | |
314 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
315 (defun tempo-insert (element on-region) |
7267 | 316 "Insert a template element. |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
317 Insert one element from a template. If ON-REGION is non-nil the `r' |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
318 elements are replaced with the current region. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
319 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
320 See documentation for `tempo-define-template' for the kind of elements |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
321 possible." |
7267 | 322 (cond ((stringp element) (tempo-process-and-insert-string element)) |
323 ((and (consp element) (eq (car element) 'p)) | |
324 (tempo-insert-prompt (cdr element))) | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
325 ((and (consp element) (eq (car element) 'P)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
326 (let ((tempo-interactive t)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
327 (tempo-insert-prompt (cdr element)))) |
7267 | 328 ((and (consp element) (eq (car element) 'r)) |
329 (if on-region | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
330 (goto-char tempo-region-stop) |
7267 | 331 (tempo-insert-prompt (cdr element)))) |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
332 ((and (consp element) (eq (car element) 's)) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
333 (tempo-insert-named (car (cdr element)))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
334 ((and (consp element) (eq (car element) 'l)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
335 (mapcar (function (lambda (elt) (tempo-insert elt on-region))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
336 (cdr element))) |
7267 | 337 ((eq element 'p) (tempo-insert-mark (point-marker))) |
338 ((eq element 'r) (if on-region | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
339 (goto-char tempo-region-stop) |
7267 | 340 (tempo-insert-mark (point-marker)))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
341 ((eq element 'r>) (if on-region |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
342 (progn |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
343 (goto-char tempo-region-stop) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
344 (indent-region (mark) (point) nil)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
345 (tempo-insert-mark (point-marker)))) |
7267 | 346 ((eq element '>) (indent-according-to-mode)) |
347 ((eq element '&) (if (not (or (= (current-column) 0) | |
348 (save-excursion | |
349 (re-search-backward | |
350 "^\\s-*\\=" nil t)))) | |
351 (insert "\n"))) | |
352 ((eq element '%) (if (not (or (eolp) | |
353 (save-excursion | |
354 (re-search-forward | |
355 "\\=\\s-*$" nil t)))) | |
356 (insert "\n"))) | |
357 ((eq element 'n) (insert "\n")) | |
358 ((eq element 'n>) (insert "\n") (indent-according-to-mode)) | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
359 ;; Bug: If the 'o is the first element in a template, strange |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
360 ;; things can happen when the template is inserted at the |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
361 ;; beginning of a line. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
362 ((eq element 'o) (if (not (or on-region |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
363 (eolp) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
364 (save-excursion |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
365 (re-search-forward |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
366 "\\=\\s-*$" nil t)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
367 (open-line 1))) |
7267 | 368 ((null element)) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
369 (t (tempo-insert (or (tempo-is-user-element element) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
370 (eval element)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
371 on-region)))) |
7267 | 372 |
373 ;;; | |
374 ;;; tempo-insert-prompt | |
375 | |
376 (defun tempo-insert-prompt (prompt) | |
377 "Prompt for a text string and insert it in the current buffer. | |
378 If the variable `tempo-interactive' is non-nil the user is prompted | |
379 for a string in the minibuffer, which is then inserted in the current | |
380 buffer. If `tempo-interactive' is nil, the current point is placed on | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
381 `tempo-mark'. |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
382 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
383 PROMPT is the prompt string or a list containing the prompt string and |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
384 a name to save the inserted text under." |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
385 (if tempo-interactive |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
386 (let ((prompt-string (if (listp prompt) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
387 (car prompt) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
388 prompt)) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
389 (save-name (and (listp prompt) (nth 1 prompt))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
390 inserted-text) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
391 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
392 (progn |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
393 (setq inserted-text (read-string prompt-string)) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
394 (insert inserted-text) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
395 (if save-name |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
396 (tempo-remember-insertion save-name inserted-text)))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
397 (tempo-insert-mark (point-marker)))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
398 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
399 ;;; |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
400 ;;; tempo-is-user-element |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
401 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
402 (defun tempo-is-user-element (element) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
403 "Tries all the user-defined element handlers in |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
404 `tempo-user-elements'" |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
405 ;; Sigh... I need (some list) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
406 (catch 'found |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
407 (mapcar (function (lambda (handler) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
408 (let ((result (funcall handler element))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
409 (if result (throw 'found result))))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
410 tempo-user-elements) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
411 (throw 'found nil))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
412 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
413 ;;; |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
414 ;;; tempo-remember-insertion |
7267 | 415 |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
416 (defun tempo-remember-insertion (save-name string) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
417 "Save the text in STRING under the name SAVE-NAME for later retrieval." |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
418 (setq tempo-named-insertions (cons (cons save-name string) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
419 tempo-named-insertions))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
420 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
421 ;;; |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
422 ;;; tempo-forget-insertions |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
423 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
424 (defun tempo-forget-insertions () |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
425 "Forget all the saved named insertions." |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
426 (setq tempo-named-insertions nil)) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
427 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
428 ;;; |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
429 ;;; tempo-insert-named |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
430 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
431 (defun tempo-insert-named (name) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
432 "Insert the previous insertion saved under a named specified in NAME. |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
433 If there is no such name saved, a tempo mark is inserted." |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
434 (let* ((insertion (cdr (assq name tempo-named-insertions)))) |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
435 (if insertion |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
436 (insert insertion) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
437 (tempo-insert-mark (point-marker))))) |
7267 | 438 |
439 ;;; | |
440 ;;; tempo-process-and-insert-string | |
441 | |
442 (defun tempo-process-and-insert-string (string) | |
443 "Insert a string from a template. | |
444 Run a string through the preprocessors in `tempo-insert-string-functions' | |
445 and insert the results." | |
446 (cond ((null tempo-insert-string-functions) | |
447 nil) | |
448 ((symbolp tempo-insert-string-functions) | |
449 (setq string | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
450 (funcall tempo-insert-string-functions string))) |
7267 | 451 ((listp tempo-insert-string-functions) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
452 (tempo-dolist (fn tempo-insert-string-functions) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
453 (setq string (funcall fn string)))) |
7267 | 454 (t |
455 (error "Bogus value in tempo-insert-string-functions: %s" | |
456 tempo-insert-string-functions))) | |
457 (insert string)) | |
458 | |
459 ;;; | |
460 ;;; tempo-insert-mark | |
461 | |
462 (defun tempo-insert-mark (mark) | |
463 "Insert a mark `tempo-marks' while keeping it sorted" | |
464 (cond ((null tempo-marks) (setq tempo-marks (list mark))) | |
465 ((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks))) | |
466 (t (let ((lp tempo-marks)) | |
467 (while (and (cdr lp) | |
468 (<= (car (cdr lp)) mark)) | |
469 (setq lp (cdr lp))) | |
470 (if (not (= mark (car lp))) | |
471 (setcdr lp (cons mark (cdr lp)))))))) | |
472 | |
473 ;;; | |
474 ;;; tempo-forward-mark | |
475 | |
476 (defun tempo-forward-mark () | |
477 "Jump to the next mark in `tempo-forward-mark-list'." | |
478 (interactive) | |
479 (let ((next-mark (catch 'found | |
480 (mapcar | |
481 (function | |
482 (lambda (mark) | |
483 (if (< (point) mark) | |
484 (throw 'found mark)))) | |
485 tempo-marks) | |
486 ;; return nil if not found | |
487 nil))) | |
488 (if next-mark | |
489 (goto-char next-mark)))) | |
490 | |
491 ;;; | |
492 ;;; tempo-backward-mark | |
493 | |
494 (defun tempo-backward-mark () | |
495 "Jump to the previous mark in `tempo-back-mark-list'." | |
496 (interactive) | |
497 (let ((prev-mark (catch 'found | |
498 (let (last) | |
499 (mapcar | |
500 (function | |
501 (lambda (mark) | |
502 (if (<= (point) mark) | |
503 (throw 'found last)) | |
504 (setq last mark))) | |
505 tempo-marks) | |
506 last)))) | |
507 (if prev-mark | |
508 (goto-char prev-mark)))) | |
509 | |
510 ;;; | |
511 ;;; tempo-add-tag | |
512 | |
513 (defun tempo-add-tag (tag template &optional tag-list) | |
514 "Add a template tag. | |
515 Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, | |
516 or to `tempo-tags' if TAG-LIST is nil." | |
517 | |
518 (interactive "sTag: \nCTemplate: ") | |
519 (if (null tag-list) | |
520 (setq tag-list 'tempo-tags)) | |
521 (if (not (assoc tag (symbol-value tag-list))) | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
522 (set tag-list (cons (cons tag template) (symbol-value tag-list)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
523 (tempo-invalidate-collection)) |
7267 | 524 |
525 ;;; | |
526 ;;; tempo-use-tag-list | |
527 | |
528 (defun tempo-use-tag-list (tag-list &optional completion-function) | |
529 "Install TAG-LIST to be used for template completion in the current buffer. | |
530 TAG-LIST is a symbol whose variable value is a tag list created with | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
531 `tempo-add-tag'. |
7267 | 532 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
533 COMPLETION-FUNCTION is an obsolete option for specifyingis an optional |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
534 function or string that is used by `\\[tempo-complete-tag]' to find a |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
535 string to match the tag against. It has the same definition as the |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
536 variable `tempo-match-finder'. In this version, supplying a |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
537 COMPLETION-FUNCTION just sets `tempo-match-finder' locally." |
7267 | 538 (let ((old (assq tag-list tempo-local-tags))) |
539 (if old | |
540 (setcdr old completion-function) | |
541 (setq tempo-local-tags (cons (cons tag-list completion-function) | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
542 tempo-local-tags)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
543 (if completion-function |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
544 (setq tempo-match-finder completion-function)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
545 (tempo-invalidate-collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
546 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
547 ;;; |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
548 ;;; tempo-invalidate-collection |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
549 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
550 (defun tempo-invalidate-collection () |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
551 "Marks the tag collection as obsolete. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
552 Whenever it is needed again it will be rebuilt." |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
553 (setq tempo-dirty-collection t)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
554 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
555 ;;; |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
556 ;;; tempo-build-collection |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
557 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
558 (defun tempo-build-collection () |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
559 "Build a collection of all the tags and return it. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
560 If `tempo-dirty-collection' is NIL, the old collection is reused." |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
561 (prog1 |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
562 (or (and (not tempo-dirty-collection) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
563 tempo-collection) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
564 (setq tempo-collection |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
565 (apply (function append) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
566 (mapcar (function (lambda (tag-list) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
567 ; If the format for |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
568 ; tempo-local-tags changes, |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
569 ; change this |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
570 (eval (car tag-list)))) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
571 tempo-local-tags)))) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
572 (setq tempo-dirty-collection nil))) |
7267 | 573 |
574 ;;; | |
575 ;;; tempo-find-match-string | |
576 | |
577 (defun tempo-find-match-string (finder) | |
578 "Find a string to be matched against a tag list. | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
579 FINDER is a function or a string. Returns (STRING . POS), or nil |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
580 if no reasonable string is found." |
7267 | 581 (cond ((stringp finder) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
582 (let (successful) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
583 (save-excursion |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
584 (or (setq successful (re-search-backward finder nil t)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
585 0)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
586 (if successful |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
587 (cons (buffer-substring (match-beginning 1) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
588 (match-end 1)) ; This seems to be a |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
589 ; bug in emacs |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
590 (match-beginning 1)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
591 nil))) |
7267 | 592 (t |
593 (funcall finder)))) | |
594 | |
595 ;;; | |
596 ;;; tempo-complete-tag | |
597 | |
598 (defun tempo-complete-tag (&optional silent) | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
599 "Look for a tag and expand it. |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
600 All the tags in the tag lists in `tempo-local-tags' |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
601 \(this includes `tempo-tags') are searched for a match for the text |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
602 before the point. The way the string to match for is determined can |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
603 be altered with the variable `tempo-match-finder'. If |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
604 `tempo-match-finder' returns nil, then the results are the same as |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
605 no match at all. |
7267 | 606 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
607 If a single match is found, the corresponding template is expanded in |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
608 place of the matching string. |
7267 | 609 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
610 If a partial completion or no match at all is found, and SILENT is |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
611 non-NIL, the function will give a signal. |
7267 | 612 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
613 If a partial completion is found and `tempo-show-completion-buffer' is |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
614 non-NIL, a buffer containing possible completions is displayed." |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
615 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
616 ;; This function may look like a hack, but this is how I want it to |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
617 ;; work. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
618 (interactive "*") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
619 (let* ((collection (tempo-build-collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
620 (match-info (tempo-find-match-string tempo-match-finder)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
621 (match-string (car match-info)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
622 (match-start (cdr match-info)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
623 (exact (assoc match-string collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
624 (compl (or (car exact) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
625 (and match-info (try-completion match-string collection))))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
626 (if compl (delete-region match-start (point))) |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
627 (cond ((null match-info) (or silent (ding))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
628 ((null compl) (or silent (ding))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
629 ((eq compl t) (tempo-insert-template |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
630 (cdr (assoc match-string |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
631 collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
632 nil)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
633 (t (if (setq exact (assoc compl collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
634 (tempo-insert-template (cdr exact) nil) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
635 (insert compl) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
636 (or silent (ding)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
637 (if tempo-show-completion-buffer |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
638 (tempo-display-completions match-string |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
639 collection))))))) |
7267 | 640 |
641 | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
642 ;;; |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
643 ;;; tempo-display-completions |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
644 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
645 (defun tempo-display-completions (string tag-list) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
646 "Show a buffer containing possible completions for STRING." |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
647 (if tempo-leave-completion-buffer |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
648 (with-output-to-temp-buffer "*Completions*" |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
649 (display-completion-list |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
650 (all-completions string tag-list))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
651 (save-window-excursion |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
652 (with-output-to-temp-buffer "*Completions*" |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
653 (display-completion-list |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
654 (all-completions string tag-list))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
655 (sit-for 32767)))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
656 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
657 ;;; |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
658 ;;; tempo-expand-if-complete |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
659 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
660 (defun tempo-expand-if-complete () |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
661 "Expand the tag before point if it is complete. |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
662 Returns non-nil if an expansion was made and nil otherwise. |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
663 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
664 This could as an example be used in a command that is bound to the |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
665 space bar, and looks something like this: |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
666 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
667 (defun tempo-space () |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
668 (interactive \"*\") |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
669 (or (tempo-expand-if-complete) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
670 (insert \" \")))" |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
671 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
672 (interactive "*") |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
673 (let* ((collection (tempo-build-collection)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
674 (match-info (tempo-find-match-string tempo-match-finder)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
675 (match-string (car match-info)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
676 (match-start (cdr match-info)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
677 (exact (assoc match-string collection))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
678 (if exact |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
679 (progn |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
680 (delete-region match-start (point)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
681 (tempo-insert-template (cdr exact) nil) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
682 t) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
683 nil))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
684 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
685 (provide 'tempo) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
686 |
7267 | 687 ;;; tempo.el ends here |