annotate lisp/tempo.el @ 9404:698990d4feca

* buffer.h (struct buffer): New members: newline_cache, width_run_cache, width_table, and cache_long_line_scans.
author Jim Blandy <jimb@redhat.com>
date Sat, 08 Oct 1994 22:12:45 +0000
parents 4eca60cb3c4d
children 488c5be866c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; tempo.el --- templates with hotspots
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1994 Free Software Foundation, Inc.
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
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
6 ;; Version: 1.1.1
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
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;; a HTML editing mode written by Nelson Minar <nelson@reed.edu>, and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;; his html-helper-mode.el is probably the best example of how to use
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; this program.
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 ;; Full documentation for tempo.el can be found on the World Wide Web
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; at http://www.lysator.liu.se:7500/~davidk/tempo.html (not yet
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; completed)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; The latest tempo.el distribution can be fetched from
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; ftp.lysator.liu.se in the directory /pub/emacs
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; Code:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (provide 'tempo)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;; Variables
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (defvar tempo-interactive nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 "*Prompt user for strings in templates.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 If this variable is non-nil, `tempo-insert' prompts the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 user for text to insert in the templates")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
92 (defvar tempo-insert-region nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
93 "*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
94 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
95 elements, unless the template function is given a prefix (or a non-nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
96 argument). If this variable is non-NIL, the behaviour is reversed.")
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
97
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
98 (defvar tempo-show-completion-buffer t
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
99 "*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
100 a partial completion can be found")
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
101
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
102 (defvar tempo-leave-completion-buffer nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
103 "*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
104 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
105
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (defvar tempo-insert-string-functions nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "List of functions to run when inserting a string.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 Each function is called with a single arg, STRING." )
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (defvar tempo-tags nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 "An association list with tags and corresponding templates")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defvar tempo-local-tags '((tempo-tags . nil))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 "A list of locally installed tag completion lists.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 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
117 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
118 function or a regexp that defines the string to match. See the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 documentation for the function `tempo-complete-tag' for more info.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 `tempo-tags' is always in the last position in this list.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (defvar tempo-marks nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 "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
125
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defvar tempo-default-match-finder "\\b\\([^\\b]*\\)\\="
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "The default regexp used to find the string to match against the tags.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
129 (defvar tempo-named-insertions nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
130 "Temporary storage for named insertions")
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
131
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; Make some variables local to every buffer
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (make-variable-buffer-local 'tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (make-variable-buffer-local 'tempo-local-tags)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;;; Functions
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; tempo-define-template
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (defun tempo-define-template (name elements &optional tag documentation taglist)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 "Define a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 This function creates a template variable `tempo-template-NAME' and an
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 interactive function `tempo-template-NAME' that inserts the template
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 at the point. The created function is returned.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 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
149 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
150 DOCUMENTATION is the documentation string for the insertion command
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 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
152 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
153 added to `tempo-tags'
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 The elements in ELEMENTS can be of several types:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 - 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
158 and the result is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 - The symbol 'p. This position is saved in `tempo-marks'.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 - 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
161 the current region is placed here. Otherwise it works like 'p.
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
162 - (p PROMPT <NAME>) If `tempo-interactive' is non-nil, the user is
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 prompted in the minbuffer with PROMPT for a string to be inserted.
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
164 If the optional parameter NAME is non-nil, the text is saved for
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
165 later insertion with the `s' tag.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 If `tempo-interactive is nil, it works like 'p.
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
167 - (r PROMPT) like the previous, but if `tempo-interactive' is nil
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 and `tempo-insert' is called with ON-REGION non-nil, the current
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 region is placed here.
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
170 - (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
171 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
172 if tempo-interactive is nil.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 - '& If there is only whitespace between the line start and point,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 nothing happens. Otherwise a newline is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 - '% If there is only whitespace between point and end-of-line
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 nothing happens. Otherwise a newline is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 - 'n inserts a newline.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 - '> The line is indented using `indent-according-to-mode'. Note that
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 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
180 line.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 - 'n> inserts a newline and indents line.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 - nil. It is ignored.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 - Anything else. It is evaluated and the result is parsed again."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (let* ((template-name (intern (concat "tempo-template-"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 name)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (command-name template-name))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (set template-name elements)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (fset command-name (list 'lambda (list '&optional 'arg)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (or documentation
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (concat "Insert a " name "."))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (list 'interactive "*P")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (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
194 template-name)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
195 (list 'if 'tempo-insert-region
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
196 (list 'not 'arg) 'arg))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (and tag
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (tempo-add-tag tag template-name taglist))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 command-name))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;;; tempo-insert-template
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 (defun tempo-insert-template (template on-region)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 "Insert a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 TEMPLATE is the template to be inserted. If ON-REGION is non-nil the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 `r' elements are replaced with the current region."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (and on-region
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (< (mark) (point))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (exchange-point-and-mark))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (tempo-insert-mark (point-marker))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (mapcar 'tempo-insert
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (symbol-value template))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (tempo-insert-mark (point-marker)))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
216 (tempo-forward-mark)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
217 (tempo-forget-insertions))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;;; tempo-insert
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (defun tempo-insert (element)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 "Insert a template element.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 Insert one element from a template. See documentation for
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 `tempo-define-template' for the kind of elements possible."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (cond ((stringp element) (tempo-process-and-insert-string element))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ((and (consp element) (eq (car element) 'p))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (tempo-insert-prompt (cdr element)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ((and (consp element) (eq (car element) 'r))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (if on-region
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (exchange-point-and-mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (tempo-insert-prompt (cdr element))))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
233 ((and (consp element) (eq (car element) 's))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
234 (if tempo-interactive
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
235 (tempo-insert-named (cdr element))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
236 (tempo-insert-mark (point-marker))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ((eq element 'p) (tempo-insert-mark (point-marker)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ((eq element 'r) (if on-region
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (exchange-point-and-mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (tempo-insert-mark (point-marker))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ((eq element '>) (indent-according-to-mode))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ((eq element '&) (if (not (or (= (current-column) 0)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (re-search-backward
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 "^\\s-*\\=" nil t))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (insert "\n")))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 ((eq element '%) (if (not (or (eolp)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (re-search-forward
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 "\\=\\s-*$" nil t))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (insert "\n")))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 ((eq element 'n) (insert "\n"))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ((eq element 'n>) (insert "\n") (indent-according-to-mode))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 ((null element))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (t (tempo-insert (eval element)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 ;;; tempo-insert-prompt
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (defun tempo-insert-prompt (prompt)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 "Prompt for a text string and insert it in the current buffer.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 If the variable `tempo-interactive' is non-nil the user is prompted
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 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
264 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
265 `tempo-mark'.
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
266
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
267 PROMPT is the prompt string or a list containing the prompt string and
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
268 a name to save the inserted text under."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
269 (if tempo-interactive
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
270 (let ((prompt-string (if (listp prompt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
271 (car prompt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
272 prompt))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
273 (save-name (and (listp prompt) (nth 1 prompt)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
274 inserted-text)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
275
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
276 (progn
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
277 (setq inserted-text (read-string prompt-string))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
278 (insert inserted-text)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
279 (if save-name
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
280 (tempo-remember-insertion save-name inserted-text))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
281 (tempo-insert-mark (point-marker))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
282
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
283 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
284 ;;; tempo-remember-insertion
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
286 (defun tempo-remember-insertion (save-name string)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
287 "Save the text in STRING under the name SAVE-NAME for later retrieval."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
288 (setq tempo-named-insertions (cons (cons save-name string)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
289 tempo-named-insertions)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
290
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
291 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
292 ;;; tempo-forget-insertions
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
293
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
294 (defun tempo-forget-insertions ()
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
295 "Forget all the saved named insertions."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
296 (setq tempo-named-insertions nil))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
297
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
298 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
299 ;;; tempo-insert-named
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
300
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
301 (defun tempo-insert-named (elt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
302 "Insert the previous insertion saved under a named specified in ELT.
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
303 The name is in the car of ELT."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
304 (let* ((name (car elt))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
305 (insertion (cdr (assq name tempo-named-insertions))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
306 (if insertion
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
307 (insert insertion)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
308 (error "Named insertion not found"))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;;; tempo-process-and-insert-string
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (defun tempo-process-and-insert-string (string)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 "Insert a string from a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 Run a string through the preprocessors in `tempo-insert-string-functions'
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 and insert the results."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (cond ((null tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ((symbolp tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (setq string
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (apply tempo-insert-string-functions (list string))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ((listp tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (mapcar (function (lambda (fn)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (setq string (apply fn string))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 tempo-insert-string-functions))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (t
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (error "Bogus value in tempo-insert-string-functions: %s"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 tempo-insert-string-functions)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (insert string))
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-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (defun tempo-insert-mark (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 "Insert a mark `tempo-marks' while keeping it sorted"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (cond ((null tempo-marks) (setq tempo-marks (list mark)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 ((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (t (let ((lp tempo-marks))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (while (and (cdr lp)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (<= (car (cdr lp)) mark))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (setq lp (cdr lp)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (if (not (= mark (car lp)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (setcdr lp (cons mark (cdr lp))))))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;;; tempo-forward-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (defun tempo-forward-mark ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 "Jump to the next mark in `tempo-forward-mark-list'."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (interactive)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (let ((next-mark (catch 'found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (mapcar
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (function
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (lambda (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (if (< (point) mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (throw 'found mark))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 ;; return nil if not found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 nil)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (if next-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (goto-char next-mark))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 ;;; tempo-backward-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (defun tempo-backward-mark ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 "Jump to the previous mark in `tempo-back-mark-list'."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (interactive)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (let ((prev-mark (catch 'found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (let (last)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (mapcar
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (function
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (lambda (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (if (<= (point) mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (throw 'found last))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (setq last mark)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 last))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (if prev-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (goto-char prev-mark))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 ;;; tempo-add-tag
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (defun tempo-add-tag (tag template &optional tag-list)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 "Add a template tag.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 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
389 or to `tempo-tags' if TAG-LIST is nil."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (interactive "sTag: \nCTemplate: ")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (if (null tag-list)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (setq tag-list 'tempo-tags))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (if (not (assoc tag (symbol-value tag-list)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (set tag-list (cons (cons tag template) (symbol-value tag-list)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 ;;; tempo-use-tag-list
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (defun tempo-use-tag-list (tag-list &optional completion-function)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 "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
402
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 TAG-LIST is a symbol whose variable value is a tag list created with
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 `tempo-add-tag' and COMPLETION-FUNCTION is an optional function or
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 string that is used by `\\[tempo-complete-tag]' to find a string to
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 match the tag against.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 If COMPLETION-FUNCTION is a string, it should contain a regular
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 expression with at least one \\( \\) pair. When searching for tags,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 `tempo-complete-tag' calls `re-search-backward' with this string, and
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 the string between the first \\( and \\) is used for matching against
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 each string in the tag list. If one is found, the whole text between
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 the first \\( and the point is replaced with the inserted template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 You will probably want to include \\ \= at the end of the regexp to make
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 sure that the string is matched only against text adjacent to the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 point.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 If COPMLETION-FUNCTION is a symbol, it should be a function that
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 returns a cons cell of the form (STRING . POS), where STRING is the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 string used for matching and POS is the buffer position after which
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 text should be replaced with a template."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (let ((old (assq tag-list tempo-local-tags)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (if old
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (setcdr old completion-function)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (setq tempo-local-tags (cons (cons tag-list completion-function)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 tempo-local-tags)))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 ;;; tempo-find-match-string
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (defun tempo-find-match-string (finder)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 "Find a string to be matched against a tag list.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 FINDER is a function or a string. Returns (STRING . POS)."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (cond ((stringp finder)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (re-search-backward finder nil t))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (cons (buffer-substring (match-beginning 1) (1+ (match-end 1)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (match-beginning 1)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (t
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (funcall finder))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 ;;; tempo-complete-tag
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (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
449 "Look for a tag and expand it.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 It goes through the tag lists in `tempo-local-tags' (this includes
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 `tempo-tags') and for each list it uses the corresponding match-finder
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 function, or `tempo-default-match-finder' if none is given, and tries
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 to match the match string against the tags in the list using
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 `try-completion'. If none is found it proceeds to the next list until
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 one is found. If a partial completion is found, it is replaced by the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 template if it can be completed uniquely, or completed as far as
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 possible.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 When doing partial completion, only tags in the currently examined
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 list are considered, so if you provide similar tags in different lists
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 in `tempo-local-tags', the result may not be desirable.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 If no match is found or a partial match is found, and SILENT is
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
465 non-nil, the function will give a signal.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
467 If tempo-show-completion-buffer is non-NIL, a buffer containing
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
468 possible completions is displayed when a partial completion is found."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
469
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
470 ;; This function is really messy. Some cleaning up is necessary.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (interactive)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (if (catch 'completed
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (mapcar
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (function
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (lambda (tag-list-a)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (let* ((tag-list (symbol-value(car tag-list-a)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (match-string-finder (or (cdr tag-list-a)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 tempo-default-match-finder))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (match-info (tempo-find-match-string match-string-finder))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (match-string (car match-info))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (match-start (cdr match-info))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (compl (or (cdr (assoc match-string tag-list))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
483 (try-completion match-string
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 tag-list))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (if compl ;any match
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (delete-region match-start (point)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (cond
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
490 ((null compl) ; No match
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 nil)
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
492 ((symbolp compl) ; ??
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (tempo-insert-template compl nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (throw 'completed t))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
495 ((eq compl t) ; Exact, sole match
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (tempo-insert-template (cdr (assoc match-string tag-list))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (throw 'completed t))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
499 ((stringp compl) ; (partial) completion found
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (let ((compl2 (assoc compl tag-list)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (if compl2
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (tempo-insert-template (cdr compl2) nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (insert compl)
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
504 (if t ;(string= match-string compl)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
505 (if tempo-show-completion-buffer
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
506 (tempo-display-completions match-string
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
507 tag-list)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
508 (if (not silent)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
509 (ding))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (throw 'completed t))))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 tempo-local-tags)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 ;; No completion found. Return nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 ;; Do nothing if a completion was found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 t
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 ;; No completion was found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (if (not silent)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (ding))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 nil))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
521 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
522 ;;; tempo-display-completions
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
523
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
524 (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
525 "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
526 (if tempo-leave-completion-buffer
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
527 (with-output-to-temp-buffer "*Completions*"
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
528 (display-completion-list
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
529 (all-completions string tag-list)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
530 (save-window-excursion
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
531 (with-output-to-temp-buffer "*Completions*"
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
532 (display-completion-list
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
533 (all-completions string tag-list)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
534 (sit-for 32767))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
535
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 ;;; tempo.el ends here