annotate lisp/tempo.el @ 13781:fc1cf507c51b

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