Mercurial > emacs
annotate lisp/tempo.el @ 24102:1086aa5db591
Major rewrite to support cleaner method of dumping; a
static "bss" section is used for heap space during preload, and
bss data is now written to the proper section area when dumping.
(need_to_recreate_heap): Renamed to using_dynamic_heap.
(heap_index_in_executable): Obsolete variable removed.
(data_section): New variable.
(data_start_va): Renamed to data_start.
(data_start_file): Obsolete variable removed.
(bss_section):
(extra_bss_size):
(bss_section_static):
(bss_start_static):
(bss_size_static):
(extra_bss_size_static):
(heap_section): New variables.
(_start): Remove code based on old unexec method. Call init_heap
to initialize sbrk heap.
(close_file_data): Update size of file when closing, so that
unexec doesn't have to work out exact size in advance.
(get_bss_info_from_map_file):
(get_section_size): Obsolete functions removed.
(rva_to_section): Fix minor bug, and add a work-around for a bug
in very old linkers.
(offset_to_section):
(relocate_offset): New functions.
(OFFSET_TO_RVA):
(RVA_TO_OFFSET):
(RVA_TO_SECTION_OFFSET):
(PTR_TO_RVA):
(PTR_TO_OFFSET):
(OFFSET_TO_PTR): New macros.
(get_section_info): Modify to support new unexec method;
determines address ranges in process that need dumping, and COFF
sections where data will be dumped. Allows for static and global
bss data to be in separate ranges. No longer relies on knowledge
of section names.
(copy_executable_and_dump_data_section): Renamed
copy_executable_and_dump_data. Completely rewritten to copy
executable section by section, so that raw data areas can be
expanded to hold dumped data as necessary. Allows for bss data to
be in same section as initialized data. Reduces size of static
heap section to that used during preload.
(dump_bss_and_heap):
(w32_fatal_reload_error):
(read_in_bss):
(map_in_heap): Obsolete functions removed.
(unexec): Rounds off preload heap to nearest page rather than
virtual allocation unit. Modified to match other changes.
author | Andrew Innes <andrewi@gnu.org> |
---|---|
date | Sun, 17 Jan 1999 19:21:24 +0000 |
parents | ac1673121774 |
children | cbe304a26771 |
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 |
14169 | 2 |
11235 | 3 ;; Copyright (C) 1994, 1995 Free Software Foundation, Inc. |
7267 | 4 |
7296 | 5 ;; Author: David K}gedal <davidk@lysator.liu.se > |
7267 | 6 ;; Created: 16 Feb 1994 |
12333 | 7 ;; K}gedal's last version number: 1.2.4 |
7267 | 8 ;; Keywords: extensions, languages, tools |
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 | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
7267 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This file provides a simple way to define powerful templates, or | |
30 ;; macros, if you wish. It is mainly intended for, but not limited to, | |
31 ;; other programmers to be used for creating shortcuts for editing | |
32 ;; 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
|
33 ;; 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
|
34 ;; 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
|
35 ;; use this program. |
7267 | 36 |
37 ;; A template is defined as a list of items to be inserted in the | |
38 ;; current buffer at point. Some of the items can be simple strings, | |
39 ;; while other can control formatting or define special points of | |
40 ;; interest in the inserted text. | |
41 | |
42 ;; If a template defines a "point of interest" that point is inserted | |
43 ;; in a buffer-local list of "points of interest" that the user can | |
44 ;; jump between with the commands `tempo-backward-mark' and | |
45 ;; `tempo-forward-mark'. If the template definer provides a prompt for | |
46 ;; the point, and the variable `tempo-interactive' is non-nil, the | |
47 ;; user will be prompted for a string to be inserted in the buffer, | |
48 ;; using the minibuffer. | |
49 | |
50 ;; The template can also define one point to be replaced with the | |
51 ;; current region if the template command is called with a prefix (or | |
52 ;; a non-nil argument). | |
53 | |
54 ;; More flexible templates can be created by including lisp symbols, | |
55 ;; which will be evaluated as variables, or lists, which will will be | |
56 ;; evaluated as lisp expressions. | |
57 | |
58 ;; See the documentation for tempo-define-template for the different | |
59 ;; items that can be used to define a tempo template. | |
60 | |
61 ;; One of the more powerful features of tempo templates are automatic | |
62 ;; completion. With every template can be assigned a special tag that | |
63 ;; should be recognized by `tempo-complete-tag' and expanded to the | |
64 ;; complete template. By default the tags are added to a global list | |
65 ;; of template tags, and are matched against the last word before | |
66 ;; point. But if you assign your tags to a specific list, you can also | |
67 ;; specify another method for matching text in the buffer against the | |
68 ;; tags. In the HTML mode, for instance, the tags are matched against | |
69 ;; the text between the last `<' and point. | |
70 | |
71 ;; When defining a template named `foo', a symbol named | |
72 ;; `tempo-template-foo' will be created whose value as a variable will | |
73 ;; be the template definition, and its function value will be an | |
74 ;; interactive function that inserts the template at the point. | |
75 | |
76 ;; The latest tempo.el distribution can be fetched from | |
77 ;; ftp.lysator.liu.se in the directory /pub/emacs | |
78 | |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
79 ;; There is also a WWW page at |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
80 ;; http://www.lysator.liu.se/~davidk/elisp/ which has some information |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
81 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
82 ;;; Known bugs: |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
83 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
84 ;; 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
|
85 ;; 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
|
86 ;; 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
|
87 ;; be easily avoided. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
88 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
89 ;; 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
|
90 ;; be looked into. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
91 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
92 ;; 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
|
93 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
94 ;; 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
|
95 ;; 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
|
96 ;; emacs version and your problems. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
97 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
98 ;;; Contributors: |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
99 |
14008
f8a4126da2c8
(tempo-local-tags, tempo-user-elements, tempo-use-tag-list):
Karl Heuer <kwzh@gnu.org>
parents:
12333
diff
changeset
|
100 ;; These people have given me important feedback and new ideas for |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
101 ;; 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
|
102 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
103 ;; 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
|
104 ;; 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
|
105 ;; 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
|
106 ;; 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
|
107 |
7267 | 108 ;;; Code: |
109 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
110 ;; (provide 'tempo) |
7267 | 111 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
112 ;;; User options |
7267 | 113 |
21088 | 114 (defgroup tempo nil |
115 "Flexible template insertion." | |
116 :prefix "tempo-" | |
117 :group 'tools) | |
118 | |
119 (defcustom tempo-interactive nil | |
7267 | 120 "*Prompt user for strings in templates. |
121 If this variable is non-nil, `tempo-insert' prompts the | |
21088 | 122 user for text to insert in the templates" |
123 :type 'boolean | |
124 :group 'tempo) | |
7267 | 125 |
21088 | 126 (defcustom tempo-insert-region nil |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
127 "*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
|
128 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
|
129 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
|
130 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
|
131 |
21088 | 132 In Transient Mark mode, this option is unused." |
133 :type 'boolean | |
134 :group 'tempo) | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
135 |
21088 | 136 (defcustom tempo-show-completion-buffer t |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
137 "*If non-NIL, show a buffer with possible completions, when only |
21088 | 138 a partial completion can be found" |
139 :type 'boolean | |
140 :group 'tempo) | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
141 |
21088 | 142 (defcustom tempo-leave-completion-buffer nil |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
143 "*If NIL, a completion buffer generated by \\[tempo-complete-tag] |
21088 | 144 disappears at the next keypress; otherwise, it remains forever." |
145 :type 'boolean | |
146 :group 'tempo) | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
147 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
148 ;;; Internal variables |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
149 |
7267 | 150 (defvar tempo-insert-string-functions nil |
151 "List of functions to run when inserting a string. | |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
152 Each function is called with a single arg, STRING and should return |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
153 another string. This could be used for making all strings upcase by |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
154 setting it to '(upcase), for example.") |
7267 | 155 |
156 (defvar tempo-tags nil | |
157 "An association list with tags and corresponding templates") | |
158 | |
159 (defvar tempo-local-tags '((tempo-tags . nil)) | |
160 "A list of locally installed tag completion lists. | |
161 It is a association list where the car of every element is a symbol | |
14008
f8a4126da2c8
(tempo-local-tags, tempo-user-elements, tempo-use-tag-list):
Karl Heuer <kwzh@gnu.org>
parents:
12333
diff
changeset
|
162 whose variable value is a template list. The cdr part, if non-nil, is a |
7267 | 163 function or a regexp that defines the string to match. See the |
164 documentation for the function `tempo-complete-tag' for more info. | |
165 | |
166 `tempo-tags' is always in the last position in this list.") | |
167 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
168 (defvar tempo-collection nil |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
169 "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
|
170 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
171 (defvar tempo-dirty-collection t |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
172 "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
|
173 |
7267 | 174 (defvar tempo-marks nil |
175 "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.") | |
176 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
177 (defvar tempo-match-finder "\\b\\([^\\b]+\\)\\=" |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
178 "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
|
179 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
180 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
|
181 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
|
182 `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
|
183 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
|
184 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
|
185 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
|
186 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
187 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
|
188 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
|
189 point. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
190 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 should be replaced with a template.") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
195 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
196 (defvar tempo-user-elements nil |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
197 "Element handlers for user-defined elements. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
198 A list of symbols which are bound to functions that take one argument. |
14008
f8a4126da2c8
(tempo-local-tags, tempo-user-elements, tempo-use-tag-list):
Karl Heuer <kwzh@gnu.org>
parents:
12333
diff
changeset
|
199 This function should return something to be sent to `tempo-insert' if |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
200 it recognizes the argument, and NIL otherwise") |
7267 | 201 |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
202 (defvar tempo-named-insertions nil |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
203 "Temporary storage for named insertions") |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
204 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
205 (defvar tempo-region-start (make-marker) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
206 "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
|
207 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
208 (defvar tempo-region-stop (make-marker) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
209 "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
|
210 |
7267 | 211 ;; Make some variables local to every buffer |
212 | |
213 (make-variable-buffer-local 'tempo-marks) | |
214 (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
|
215 (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
|
216 (make-variable-buffer-local 'tempo-collection) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
217 (make-variable-buffer-local 'tempo-dirty-collection) |
7267 | 218 |
219 ;;; Functions | |
220 | |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
221 ;;; 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
|
222 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
223 (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
|
224 (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
|
225 (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
|
226 (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
|
227 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
228 (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
|
229 (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
|
230 (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
|
231 (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
|
232 (list 'function (append (list 'lambda |
11202
577f71dad5c3
(tempo-dolist): Don't use `cadr'.
Karl Heuer <kwzh@gnu.org>
parents:
11196
diff
changeset
|
233 (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
|
234 forms)) |
11202
577f71dad5c3
(tempo-dolist): Don't use `cadr'.
Karl Heuer <kwzh@gnu.org>
parents:
11196
diff
changeset
|
235 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
|
236 (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
|
237 |
7267 | 238 ;; |
239 ;; tempo-define-template | |
240 | |
241 (defun tempo-define-template (name elements &optional tag documentation taglist) | |
242 "Define a template. | |
243 This function creates a template variable `tempo-template-NAME' and an | |
244 interactive function `tempo-template-NAME' that inserts the template | |
245 at the point. The created function is returned. | |
246 | |
247 NAME is a string that contains the name of the template, ELEMENTS is a | |
248 list of elements in the template, TAG is the tag used for completion, | |
249 DOCUMENTATION is the documentation string for the insertion command | |
250 created, and TAGLIST (a symbol) is the tag list that TAG (if provided) | |
251 should be added to). If TAGLIST is nil and TAG is non-nil, TAG is | |
252 added to `tempo-tags' | |
253 | |
254 The elements in ELEMENTS can be of several types: | |
255 | |
256 - A string. It is sent to the hooks in `tempo-insert-string-functions', | |
257 and the result is inserted. | |
258 - The symbol 'p. This position is saved in `tempo-marks'. | |
259 - The symbol 'r. If `tempo-insert' is called with ON-REGION non-nil | |
260 the current region is placed here. Otherwise it works like 'p. | |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
261 - (p PROMPT <NAME> <NOINSERT>) If `tempo-interactive' is non-nil, the |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
262 user is prompted in the minbuffer with PROMPT for a string to be |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
263 inserted. If the optional parameter NAME is non-nil, the text is |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
264 saved for later insertion with the `s' tag. If there already is |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
265 something saved under NAME that value is used instead and no |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
266 prompting is made. If NOINSERT is provided and non-nil, nothing is |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
267 inserted, but text is still saved when a NAME is provided. For |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
268 clarity, the symbol 'noinsert should be used as argument. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
269 - (P PROMPT <NAME> <NOINSERT>) Works just like the previous tag, but |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
270 forces tempo-interactive to be true. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
271 - (r PROMPT <NAME> <NOINSERT>) like the previous, but if |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
272 `tempo-interactive' is nil and `tempo-insert' is called with |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
273 ON-REGION non-nil, the current region is placed here. This usually |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
274 happens when you call the 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
|
275 - (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
|
276 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
|
277 if tempo-interactive is nil. |
7267 | 278 - '& If there is only whitespace between the line start and point, |
279 nothing happens. Otherwise a newline is inserted. | |
280 - '% If there is only whitespace between point and end-of-line | |
281 nothing happens. Otherwise a newline is inserted. | |
282 - 'n inserts a newline. | |
283 - '> The line is indented using `indent-according-to-mode'. Note that | |
284 you often should place this item after the text you want on the | |
285 line. | |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
286 - 'r> Like r, but it also indents the region. |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
287 - '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
|
288 - 'o Like '% but leaves the point before the newline. |
7267 | 289 - nil. It is ignored. |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
290 - Anything else. It is evaluated and the result is treated as an |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
291 element to be inserted. One additional tag is useful for these |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
292 cases. If an expression returns a list '(l foo bar), the elements |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
293 after 'l will be inserted according to the usual rules. This makes |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
294 it possible to return several elements from one expression." |
7267 | 295 |
296 (let* ((template-name (intern (concat "tempo-template-" | |
297 name))) | |
298 (command-name template-name)) | |
299 (set template-name elements) | |
300 (fset command-name (list 'lambda (list '&optional 'arg) | |
301 (or documentation | |
302 (concat "Insert a " name ".")) | |
303 (list 'interactive "*P") | |
304 (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
|
305 template-name) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
306 (list 'if 'tempo-insert-region |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
307 (list 'not 'arg) 'arg)))) |
7267 | 308 (and tag |
309 (tempo-add-tag tag template-name taglist)) | |
310 command-name)) | |
311 | |
312 ;;; | |
313 ;;; tempo-insert-template | |
314 | |
315 (defun tempo-insert-template (template on-region) | |
316 "Insert a template. | |
317 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
|
318 `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
|
319 mode, ON-REGION is ignored and assumed true if the region is active." |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
320 (unwind-protect |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
321 (progn |
12333 | 322 (if (or (and (boundp 'transient-mark-mode) ; For Emacs |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
323 transient-mark-mode |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
324 mark-active) |
12333 | 325 (and (boundp 'zmacs-regions) ; For XEmacs |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
326 zmacs-regions (mark))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
327 (setq on-region t)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
328 (and on-region |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
329 (set-marker tempo-region-start (min (mark) (point))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
330 (set-marker tempo-region-stop (max (mark) (point)))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
331 (if on-region |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
332 (goto-char tempo-region-start)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
333 (save-excursion |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
334 (tempo-insert-mark (point-marker)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
335 (mapcar (function (lambda (elt) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
336 (tempo-insert elt on-region))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
337 (symbol-value template)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
338 (tempo-insert-mark (point-marker))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
339 (tempo-forward-mark)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
340 (tempo-forget-insertions) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
341 ;; Should I check for zmacs here too??? |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
342 (and (boundp 'transient-mark-mode) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
343 transient-mark-mode |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
344 (deactivate-mark)))) |
7267 | 345 |
346 ;;; | |
347 ;;; tempo-insert | |
348 | |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
349 (defun tempo-insert (element on-region) |
7267 | 350 "Insert a template element. |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
351 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
|
352 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
|
353 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
354 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
|
355 possible." |
7267 | 356 (cond ((stringp element) (tempo-process-and-insert-string element)) |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
357 ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
358 (eq (car element) 'p)) (tempo-insert-prompt-compat |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
359 (cdr element))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
360 ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
361 (eq (car element) 'P)) (let ((tempo-interactive t)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
362 (tempo-insert-prompt-compat |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
363 (cdr element)))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
364 ;;; ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
365 ;;; (eq (car element) 'v)) (tempo-save-named |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
366 ;;; (nth 1 element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
367 ;;; nil |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
368 ;;; (nth 2 element))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
369 ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
370 (eq (car element) 'r)) (if on-region |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
371 (goto-char tempo-region-stop) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
372 (tempo-insert-prompt-compat |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
373 (cdr element)))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
374 ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
375 (eq (car element) 's)) (tempo-insert-named (car (cdr element)))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
376 ((and (consp element) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
377 (eq (car element) 'l)) (mapcar (function |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
378 (lambda (elt) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
379 (tempo-insert elt on-region))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
380 (cdr element))) |
7267 | 381 ((eq element 'p) (tempo-insert-mark (point-marker))) |
382 ((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
|
383 (goto-char tempo-region-stop) |
7267 | 384 (tempo-insert-mark (point-marker)))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
385 ((eq element 'r>) (if on-region |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
386 (progn |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
387 (goto-char tempo-region-stop) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
388 (indent-region (mark) (point) nil)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
389 (tempo-insert-mark (point-marker)))) |
7267 | 390 ((eq element '>) (indent-according-to-mode)) |
391 ((eq element '&) (if (not (or (= (current-column) 0) | |
392 (save-excursion | |
393 (re-search-backward | |
394 "^\\s-*\\=" nil t)))) | |
395 (insert "\n"))) | |
396 ((eq element '%) (if (not (or (eolp) | |
397 (save-excursion | |
398 (re-search-forward | |
399 "\\=\\s-*$" nil t)))) | |
400 (insert "\n"))) | |
401 ((eq element 'n) (insert "\n")) | |
402 ((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
|
403 ;; 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
|
404 ;; 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
|
405 ;; beginning of a line. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
406 ((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
|
407 (eolp) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
408 (save-excursion |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
409 (re-search-forward |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
410 "\\=\\s-*$" nil t)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
411 (open-line 1))) |
7267 | 412 ((null element)) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
413 (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
|
414 (eval element)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
415 on-region)))) |
7267 | 416 |
417 ;;; | |
418 ;;; tempo-insert-prompt | |
419 | |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
420 (defun tempo-insert-prompt-compat (prompt) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
421 "Compatibility hack for tempo-insert-prompt. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
422 PROMPT can be either a prompt string, or a list of arguments to |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
423 tempo-insert-prompt, or nil." |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
424 (if (consp prompt) ; not NIL either |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
425 (apply 'tempo-insert-prompt prompt) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
426 (tempo-insert-prompt prompt))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
427 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
428 (defun tempo-insert-prompt (prompt &optional save-name no-insert) |
7267 | 429 "Prompt for a text string and insert it in the current buffer. |
430 If the variable `tempo-interactive' is non-nil the user is prompted | |
431 for a string in the minibuffer, which is then inserted in the current | |
432 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
|
433 `tempo-mark'. |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
434 |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
435 PROMPT is the prompt string, SAVE-NAME is a name to save the inserted |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
436 text under. If the optional argument NO-INSERT is non-nil, no text i |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
437 inserted. This can be useful when there is a SAVE-NAME. |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
438 |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
439 If there already is a value for SAVE-NAME, it is used and the user is |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
440 never prompted." |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
441 (let (insertion |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
442 (previous (and save-name |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
443 (tempo-lookup-named save-name)))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
444 (cond |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
445 ;; Insert previous value, unless no-insert is non-nil |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
446 ((and previous |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
447 (not no-insert)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
448 (tempo-insert-named save-name)) ; A double lookup here, but who |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
449 ; cares |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
450 ;; If no-insert is non-nil, don't insert the previous value. Just |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
451 ;; keep it |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
452 (previous |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
453 nil) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
454 ;; No previous value. Prompt or insert mark |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
455 (tempo-interactive |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
456 (if (not (stringp prompt)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
457 (error "tempo: The prompt (%s) is not a string" prompt)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
458 (setq insertion (read-string prompt)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
459 (or no-insert |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
460 (insert insertion)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
461 (if save-name |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
462 (tempo-save-named save-name insertion))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
463 (t |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
464 (tempo-insert-mark (point-marker)))))) |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
465 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
466 ;;; |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
467 ;;; tempo-is-user-element |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
468 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
469 (defun tempo-is-user-element (element) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
470 "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
|
471 `tempo-user-elements'" |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
472 ;; Sigh... I need (some list) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
473 (catch 'found |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
474 (mapcar (function (lambda (handler) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
475 (let ((result (funcall handler element))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
476 (if result (throw 'found result))))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
477 tempo-user-elements) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
478 (throw 'found nil))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
479 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
480 ;;; |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
481 ;;; tempo-forget-insertions |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
482 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
483 (defun tempo-forget-insertions () |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
484 "Forget all the saved named insertions." |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
485 (setq tempo-named-insertions nil)) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
486 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
487 ;;; |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
488 ;;; tempo-save-named |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
489 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
490 (defun tempo-save-named (name data) ; Had an optional prompt for 'v |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
491 "Save some data for later insertion |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
492 The contents of DATA is saved under the name NAME. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
493 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
494 The data can later be retrieved with `tempo-lookup-named'. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
495 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
496 This function returns nil, so it can be used in a template without |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
497 inserting anything." |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
498 (setq tempo-named-insertions |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
499 (cons (cons name data) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
500 tempo-named-insertions)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
501 nil) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
502 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
503 ;;; |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
504 ;;; tempo-lookup-named |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
505 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
506 (defun tempo-lookup-named (name) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
507 "Lookup some saved data under the name NAME. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
508 Returns the data if NAME was found, and nil otherwise." |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
509 (cdr (assq name tempo-named-insertions))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
510 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
511 ;;; |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
512 ;;; tempo-insert-named |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
513 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
514 (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
|
515 "Insert the previous insertion saved under a named specified in NAME. |
12321
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
516 If there is no such name saved, a tempo mark is inserted. |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
517 |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
518 Note that if the data is a string, it will not be run through the string |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
519 processor." |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
520 (let* ((insertion (tempo-lookup-named name))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
521 (cond ((null insertion) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
522 (tempo-insert-mark (point-marker))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
523 ((stringp insertion) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
524 (insert insertion)) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
525 (t |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
526 (tempo-insert insertion nil))))) |
35899872cb3f
Documented the `l' tag.
Richard M. Stallman <rms@gnu.org>
parents:
11235
diff
changeset
|
527 |
7267 | 528 |
529 ;;; | |
530 ;;; tempo-process-and-insert-string | |
531 | |
532 (defun tempo-process-and-insert-string (string) | |
533 "Insert a string from a template. | |
534 Run a string through the preprocessors in `tempo-insert-string-functions' | |
535 and insert the results." | |
536 (cond ((null tempo-insert-string-functions) | |
537 nil) | |
538 ((symbolp tempo-insert-string-functions) | |
539 (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
|
540 (funcall tempo-insert-string-functions string))) |
7267 | 541 ((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
|
542 (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
|
543 (setq string (funcall fn string)))) |
7267 | 544 (t |
545 (error "Bogus value in tempo-insert-string-functions: %s" | |
546 tempo-insert-string-functions))) | |
547 (insert string)) | |
548 | |
549 ;;; | |
550 ;;; tempo-insert-mark | |
551 | |
552 (defun tempo-insert-mark (mark) | |
553 "Insert a mark `tempo-marks' while keeping it sorted" | |
554 (cond ((null tempo-marks) (setq tempo-marks (list mark))) | |
555 ((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks))) | |
556 (t (let ((lp tempo-marks)) | |
557 (while (and (cdr lp) | |
558 (<= (car (cdr lp)) mark)) | |
559 (setq lp (cdr lp))) | |
560 (if (not (= mark (car lp))) | |
561 (setcdr lp (cons mark (cdr lp)))))))) | |
562 | |
563 ;;; | |
564 ;;; tempo-forward-mark | |
565 | |
566 (defun tempo-forward-mark () | |
567 "Jump to the next mark in `tempo-forward-mark-list'." | |
568 (interactive) | |
569 (let ((next-mark (catch 'found | |
570 (mapcar | |
571 (function | |
572 (lambda (mark) | |
573 (if (< (point) mark) | |
574 (throw 'found mark)))) | |
575 tempo-marks) | |
576 ;; return nil if not found | |
577 nil))) | |
578 (if next-mark | |
579 (goto-char next-mark)))) | |
580 | |
581 ;;; | |
582 ;;; tempo-backward-mark | |
583 | |
584 (defun tempo-backward-mark () | |
585 "Jump to the previous mark in `tempo-back-mark-list'." | |
586 (interactive) | |
587 (let ((prev-mark (catch 'found | |
588 (let (last) | |
589 (mapcar | |
590 (function | |
591 (lambda (mark) | |
592 (if (<= (point) mark) | |
593 (throw 'found last)) | |
594 (setq last mark))) | |
595 tempo-marks) | |
596 last)))) | |
597 (if prev-mark | |
598 (goto-char prev-mark)))) | |
599 | |
600 ;;; | |
601 ;;; tempo-add-tag | |
602 | |
603 (defun tempo-add-tag (tag template &optional tag-list) | |
604 "Add a template tag. | |
605 Add the TAG, that should complete to TEMPLATE to the list in TAG-LIST, | |
606 or to `tempo-tags' if TAG-LIST is nil." | |
607 | |
608 (interactive "sTag: \nCTemplate: ") | |
609 (if (null tag-list) | |
610 (setq tag-list 'tempo-tags)) | |
611 (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
|
612 (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
|
613 (tempo-invalidate-collection)) |
7267 | 614 |
615 ;;; | |
616 ;;; tempo-use-tag-list | |
617 | |
618 (defun tempo-use-tag-list (tag-list &optional completion-function) | |
619 "Install TAG-LIST to be used for template completion in the current buffer. | |
620 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
|
621 `tempo-add-tag'. |
7267 | 622 |
14008
f8a4126da2c8
(tempo-local-tags, tempo-user-elements, tempo-use-tag-list):
Karl Heuer <kwzh@gnu.org>
parents:
12333
diff
changeset
|
623 COMPLETION-FUNCTION is an obsolete option for specifying an optional |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
624 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
|
625 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
|
626 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
|
627 COMPLETION-FUNCTION just sets `tempo-match-finder' locally." |
7267 | 628 (let ((old (assq tag-list tempo-local-tags))) |
629 (if old | |
630 (setcdr old completion-function) | |
631 (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
|
632 tempo-local-tags)))) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
633 (if completion-function |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
634 (setq tempo-match-finder completion-function)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
635 (tempo-invalidate-collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
636 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
637 ;;; |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
638 ;;; tempo-invalidate-collection |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
639 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
640 (defun tempo-invalidate-collection () |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
641 "Marks the tag collection as obsolete. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
642 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
|
643 (setq tempo-dirty-collection t)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
644 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
645 ;;; |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
646 ;;; tempo-build-collection |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
647 |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
648 (defun tempo-build-collection () |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
649 "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
|
650 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
|
651 (prog1 |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
652 (or (and (not tempo-dirty-collection) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
653 tempo-collection) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
654 (setq tempo-collection |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
655 (apply (function append) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
656 (mapcar (function (lambda (tag-list) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
657 ; If the format for |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
658 ; tempo-local-tags changes, |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
659 ; change this |
11208
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
660 (eval (car tag-list)))) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
661 tempo-local-tags)))) |
18107abf5df3
(tempo-build-collection): Clear flag after computing
Karl Heuer <kwzh@gnu.org>
parents:
11202
diff
changeset
|
662 (setq tempo-dirty-collection nil))) |
7267 | 663 |
664 ;;; | |
665 ;;; tempo-find-match-string | |
666 | |
667 (defun tempo-find-match-string (finder) | |
668 "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
|
669 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
|
670 if no reasonable string is found." |
7267 | 671 (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
|
672 (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
|
673 (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
|
674 (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
|
675 0)) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
676 (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
|
677 (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
|
678 (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
|
679 ; 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
|
680 (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
|
681 nil))) |
7267 | 682 (t |
683 (funcall finder)))) | |
684 | |
685 ;;; | |
686 ;;; tempo-complete-tag | |
687 | |
688 (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
|
689 "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
|
690 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
|
691 \(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
|
692 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
|
693 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
|
694 `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
|
695 no match at all. |
7267 | 696 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
697 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
|
698 place of the matching string. |
7267 | 699 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
700 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
|
701 non-NIL, the function will give a signal. |
7267 | 702 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
703 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
|
704 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
|
705 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
706 ;; 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
|
707 ;; work. |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
708 (interactive "*") |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
709 (let* ((collection (tempo-build-collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
710 (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
|
711 (match-string (car match-info)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
712 (match-start (cdr match-info)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
713 (exact (assoc match-string collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
714 (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
|
715 (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
|
716 (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
|
717 (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
|
718 ((null compl) (or silent (ding))) |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
719 ((eq compl t) (tempo-insert-template |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
720 (cdr (assoc match-string |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
721 collection)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
722 nil)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
723 (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
|
724 (tempo-insert-template (cdr exact) nil) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
725 (insert compl) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
726 (or silent (ding)) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
727 (if tempo-show-completion-buffer |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
728 (tempo-display-completions match-string |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
729 collection))))))) |
7267 | 730 |
731 | |
7410
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
732 ;;; |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
733 ;;; tempo-display-completions |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
734 |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
735 (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
|
736 "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
|
737 (if tempo-leave-completion-buffer |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
738 (with-output-to-temp-buffer "*Completions*" |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
739 (display-completion-list |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
740 (all-completions string tag-list))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
741 (save-window-excursion |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
742 (with-output-to-temp-buffer "*Completions*" |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
743 (display-completion-list |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
744 (all-completions string tag-list))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
745 (sit-for 32767)))) |
4eca60cb3c4d
(tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents:
7296
diff
changeset
|
746 |
11196
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
747 ;;; |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
748 ;;; 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
|
749 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
750 (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
|
751 "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
|
752 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
|
753 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
754 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
|
755 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
|
756 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
757 (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
|
758 (interactive \"*\") |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
759 (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
|
760 (insert \" \")))" |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
761 |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
762 (interactive "*") |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
763 (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
|
764 (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
|
765 (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
|
766 (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
|
767 (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
|
768 (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
|
769 (progn |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
770 (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
|
771 (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
|
772 t) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
773 nil))) |
a74358cc05c6
(tempo-insert): Added the P tag and modified the s tag accordingly
Richard M. Stallman <rms@gnu.org>
parents:
10516
diff
changeset
|
774 |
10516
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
775 (provide 'tempo) |
488c5be866c3
(tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents:
7410
diff
changeset
|
776 |
7267 | 777 ;;; tempo.el ends here |