annotate lisp/tempo.el @ 10588:2a8f29cd9e9f

(Frassoc): New function. (syms_of_fns): defsubr it.
author Richard M. Stallman <rms@gnu.org>
date Sun, 29 Jan 1995 22:04:10 +0000
parents 488c5be866c3
children a74358cc05c6
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
7267
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
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
6 ;; Version: 1.2
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 ;; 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
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
77 ;;; Known bugs:
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
78
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
79 ;; 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
80 ;; 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
81 ;; 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
82 ;; be easily avoided.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
83
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
84 ;; 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
85 ;; be looked into.
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 ;; 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
88
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
89 ;; 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
90 ;; 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
91 ;; emacs version and your problems.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
92
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;; Code:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
95 ;; (provide 'tempo)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
97 ;;; User options
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defvar tempo-interactive nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "*Prompt user for strings in templates.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 If this variable is non-nil, `tempo-insert' prompts the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 user for text to insert in the templates")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
104 (defvar tempo-insert-region nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
105 "*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
106 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
107 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
108 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
109
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
110 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
111
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
112 (defvar tempo-show-completion-buffer t
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
113 "*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
114 a partial completion can be found")
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
115
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
116 (defvar tempo-leave-completion-buffer nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
117 "*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
118 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
119
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
120 ;;; Internal variables
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
121
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (defvar tempo-insert-string-functions nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 "List of functions to run when inserting a string.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 Each function is called with a single arg, STRING." )
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-tags nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "An association list with tags and corresponding templates")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defvar tempo-local-tags '((tempo-tags . nil))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 "A list of locally installed tag completion lists.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 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
132 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
133 function or a regexp that defines the string to match. See the
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 documentation for the function `tempo-complete-tag' for more info.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 `tempo-tags' is always in the last position in this list.")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
138 (defvar tempo-collection nil
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
139 "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
140
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
141 (defvar tempo-dirty-collection t
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
142 "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
143
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defvar tempo-marks nil
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 "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
146
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
147 (defvar tempo-match-finder "\\b\\([^\\b]+\\)\\="
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
148 "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
149
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
150 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
151 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
152 `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
153 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
154 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
155 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
156
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
157 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
158 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
159 point.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
160
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
161 If `tempo-match-finder' is a 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
162 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
163 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
164 should be replaced with a template.")
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
165
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
166 (defvar tempo-user-elements nil
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
167 "Element handlers for user-defined elements.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
168 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
169 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
170 it recognizes the argument, and NIL otherwise")
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
172 (defvar tempo-named-insertions nil
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
173 "Temporary storage for named insertions")
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
174
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
175 (defvar tempo-region-start (make-marker)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
176 "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
177
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
178 (defvar tempo-region-stop (make-marker)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
179 "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
180
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; Make some variables local to every buffer
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (make-variable-buffer-local 'tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (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
185 (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
186 (make-variable-buffer-local 'tempo-collection)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
187 (make-variable-buffer-local 'tempo-dirty-collection)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 ;;; Functions
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; tempo-define-template
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun tempo-define-template (name elements &optional tag documentation taglist)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "Define a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 This function creates a template variable `tempo-template-NAME' and an
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 interactive function `tempo-template-NAME' that inserts the template
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 at the point. The created function is returned.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 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
201 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
202 DOCUMENTATION is the documentation string for the insertion command
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 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
204 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
205 added to `tempo-tags'
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 The elements in ELEMENTS can be of several types:
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 - 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
210 and the result is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 - The symbol 'p. This position is saved in `tempo-marks'.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 - 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
213 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
214 - (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
215 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
216 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
217 later insertion with the `s' tag.
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
218 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
219 - (r PROMPT) like the previous, but if `tempo-interactive' is nil
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 and `tempo-insert' is called with ON-REGION non-nil, the current
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
221 region is placed here. This usually happens when you call the
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
222 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
223 - (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
224 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
225 if tempo-interactive is nil.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 - '& If there is only whitespace between the line start and point,
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 nothing happens. Otherwise a newline is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 - '% If there is only whitespace between point and end-of-line
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 nothing happens. Otherwise a newline is inserted.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 - 'n inserts a newline.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 - '> The line is indented using `indent-according-to-mode'. Note that
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 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
233 line.
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
234 - '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
235 - 'o Like '% but leaves the point before the newline.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 - nil. It is ignored.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 - Anything else. It is evaluated and the result is parsed again."
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 (let* ((template-name (intern (concat "tempo-template-"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 name)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (command-name template-name))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (set template-name elements)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (fset command-name (list 'lambda (list '&optional 'arg)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (or documentation
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (concat "Insert a " name "."))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (list 'interactive "*P")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (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
248 template-name)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
249 (list 'if 'tempo-insert-region
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
250 (list 'not 'arg) 'arg))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (and tag
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (tempo-add-tag tag template-name taglist))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 command-name))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;;; tempo-insert-template
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 (defun tempo-insert-template (template on-region)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "Insert a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 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
261 `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
262 mode, ON-REGION is ignored and assumed true if the region is active."
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
263 (if (and (boundp 'transient-mark-mode)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
264 transient-mark-mode
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
265 mark-active)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
266 (setq on-region t))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (and on-region
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
268 (set-marker tempo-region-start (min (mark) (point)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
269 (set-marker tempo-region-stop (max (mark) (point))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
270 (if on-region
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
271 (goto-char tempo-region-start))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (tempo-insert-mark (point-marker))
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
274 (mapcar (function (lambda (elt)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
275 (tempo-insert elt on-region)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (symbol-value template))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (tempo-insert-mark (point-marker)))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
278 (tempo-forward-mark)
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
279 (tempo-forget-insertions)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
280 (and (boundp 'transient-mark-mode)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
281 transient-mark-mode
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
282 (deactivate-mark)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 ;;; tempo-insert
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
287 (defun tempo-insert (element on-region)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 "Insert a template element.
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
289 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
290 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
291
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
292 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
293 possible."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (cond ((stringp element) (tempo-process-and-insert-string element))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ((and (consp element) (eq (car element) 'p))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (tempo-insert-prompt (cdr element)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 ((and (consp element) (eq (car element) 'r))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (if on-region
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
299 (goto-char tempo-region-stop)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (tempo-insert-prompt (cdr element))))
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
301 ((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
302 (if tempo-interactive
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
303 (tempo-insert-named (cdr element))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
304 (tempo-insert-mark (point-marker))))
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
305 ((and (consp element) (eq (car element) 'l))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
306 (mapcar (function (lambda (elt) (tempo-insert elt on-region)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
307 (cdr element)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ((eq element 'p) (tempo-insert-mark (point-marker)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ((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
310 (goto-char tempo-region-stop)
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (tempo-insert-mark (point-marker))))
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
312 ((eq element 'r>) (if on-region
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
313 (progn
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
314 (goto-char tempo-region-stop)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
315 (indent-region (mark) (point) nil))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
316 (tempo-insert-mark (point-marker))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ((eq element '>) (indent-according-to-mode))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ((eq element '&) (if (not (or (= (current-column) 0)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (re-search-backward
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 "^\\s-*\\=" nil t))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (insert "\n")))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ((eq element '%) (if (not (or (eolp)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (save-excursion
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (re-search-forward
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 "\\=\\s-*$" nil t))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (insert "\n")))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ((eq element 'n) (insert "\n"))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 ((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
330 ;; 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
331 ;; 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
332 ;; beginning of a line.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
333 ((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
334 (eolp)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
335 (save-excursion
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
336 (re-search-forward
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
337 "\\=\\s-*$" nil t))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
338 (open-line 1)))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ((null element))
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
340 (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
341 (eval element))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
342 on-region))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343
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 ;;; tempo-insert-prompt
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (defun tempo-insert-prompt (prompt)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 "Prompt for a text string and insert it in the current buffer.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 If the variable `tempo-interactive' is non-nil the user is prompted
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 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
351 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
352 `tempo-mark'.
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
353
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
354 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
355 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
356 (if tempo-interactive
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
357 (let ((prompt-string (if (listp prompt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
358 (car prompt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
359 prompt))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
360 (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
361 inserted-text)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
362
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
363 (progn
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
364 (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
365 (insert inserted-text)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
366 (if save-name
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
367 (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
368 (tempo-insert-mark (point-marker))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
369
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
370 ;;;
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
371 ;;; tempo-is-user-element
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
372
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
373 (defun tempo-is-user-element (element)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
374 "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
375 `tempo-user-elements'"
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
376 ;; Sigh... I need (some list)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
377 (catch 'found
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
378 (mapcar (function (lambda (handler)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
379 (let ((result (funcall handler element)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
380 (if result (throw 'found result)))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
381 tempo-user-elements)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
382 (throw 'found nil)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
383
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
384 ;;;
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
385 ;;; tempo-remember-insertion
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
387 (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
388 "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
389 (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
390 tempo-named-insertions)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
391
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
392 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
393 ;;; tempo-forget-insertions
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
394
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
395 (defun tempo-forget-insertions ()
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
396 "Forget all the saved named insertions."
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
397 (setq tempo-named-insertions nil))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
398
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
399 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
400 ;;; tempo-insert-named
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
401
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
402 (defun tempo-insert-named (elt)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
403 "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
404 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
405 (let* ((name (car elt))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
406 (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
407 (if insertion
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
408 (insert insertion)
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
409 (error "Named insertion not found"))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 ;;; tempo-process-and-insert-string
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (defun tempo-process-and-insert-string (string)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 "Insert a string from a template.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 Run a string through the preprocessors in `tempo-insert-string-functions'
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 and insert the results."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (cond ((null tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 nil)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 ((symbolp tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (setq string
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (apply tempo-insert-string-functions (list string))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 ((listp tempo-insert-string-functions)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (mapcar (function (lambda (fn)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (setq string (apply fn string))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 tempo-insert-string-functions))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (t
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (error "Bogus value in tempo-insert-string-functions: %s"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 tempo-insert-string-functions)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (insert string))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431
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 ;;; tempo-insert-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (defun tempo-insert-mark (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 "Insert a mark `tempo-marks' while keeping it sorted"
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (cond ((null tempo-marks) (setq tempo-marks (list mark)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 ((< mark (car tempo-marks)) (setq tempo-marks (cons mark tempo-marks)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (t (let ((lp tempo-marks))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (while (and (cdr lp)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (<= (car (cdr lp)) mark))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (setq lp (cdr lp)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (not (= mark (car lp)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setcdr lp (cons mark (cdr lp))))))))
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 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 ;;; tempo-forward-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (defun tempo-forward-mark ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 "Jump to the next mark in `tempo-forward-mark-list'."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (interactive)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (let ((next-mark (catch 'found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (mapcar
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (function
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (lambda (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (if (< (point) mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (throw 'found mark))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; return nil if not found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 nil)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (if next-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (goto-char next-mark))))
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 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ;;; tempo-backward-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (defun tempo-backward-mark ()
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 "Jump to the previous mark in `tempo-back-mark-list'."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (interactive)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (let ((prev-mark (catch 'found
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (let (last)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (mapcar
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (function
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (lambda (mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (if (<= (point) mark)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (throw 'found last))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (setq last mark)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 tempo-marks)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 last))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (if prev-mark
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (goto-char prev-mark))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 ;;; tempo-add-tag
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 (defun tempo-add-tag (tag template &optional tag-list)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 "Add a template tag.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 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
489 or to `tempo-tags' if TAG-LIST is nil."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (interactive "sTag: \nCTemplate: ")
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (if (null tag-list)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (setq tag-list 'tempo-tags))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (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
495 (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
496 (tempo-invalidate-collection))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 ;;; tempo-use-tag-list
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (defun tempo-use-tag-list (tag-list &optional completion-function)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 "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
503 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
504 `tempo-add-tag'.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
506 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
507 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
508 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
509 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
510 COMPLETION-FUNCTION just sets `tempo-match-finder' locally."
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (let ((old (assq tag-list tempo-local-tags)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (if old
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 (setcdr old completion-function)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (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
515 tempo-local-tags))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
516 (if completion-function
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
517 (setq tempo-match-finder completion-function))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
518 (tempo-invalidate-collection))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
519
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
520 ;;;
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
521 ;;; tempo-invalidate-collection
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
522
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
523 (defun tempo-invalidate-collection ()
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
524 "Marks the tag collection as obsolete.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
525 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
526 (setq tempo-dirty-collection t))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
527
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
528 ;;;
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
529 ;;; tempo-build-collection
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
530
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
531 (defun tempo-build-collection ()
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
532 "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
533 If `tempo-dirty-collection' is NIL, the old collection is reused."
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
534 (setq tempo-dirty nil)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
535 (or (and (not tempo-dirty-collection)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
536 tempo-collection)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
537 (setq tempo-collection
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
538 (apply (function append)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
539 (mapcar (function (lambda (tag-list)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
540 ; If the format for
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
541 ; tempo-local-tags changes,
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
542 ; change this
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
543 (eval (car tag-list))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
544 tempo-local-tags)))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 ;;; tempo-find-match-string
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 (defun tempo-find-match-string (finder)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 "Find a string to be matched against a tag list.
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 FINDER is a function or a string. Returns (STRING . POS)."
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (cond ((stringp finder)
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (save-excursion
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
554 (or (re-search-backward finder nil t)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
555 0))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
556 (cons (buffer-substring (match-beginning 1)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
557 (match-end 1)) ; This seems to be a
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
558 ; bug in emacs
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (match-beginning 1)))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (t
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (funcall finder))))
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ;;;
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 ;;; tempo-complete-tag
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 (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
567 "Look for a tag and expand it.
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
568 All the tags in the tag lists in `tempo-local-tags' (this includes
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
569 `tempo-tags') are searched for a match for the text before the point.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
570 The way the string to match for is determined can be altered with the
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
571 variable `tempo-match-finder'
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
573 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
574 place of the matching string.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
576 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
577 non-NIL, the function will give a signal.
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
579 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
580 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
581
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
582 ;; 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
583 ;; work.
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
584 (interactive "*")
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
585 (let* ((collection (tempo-build-collection))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
586 (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
587 (match-string (car match-info))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
588 (match-start (cdr match-info))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
589 (exact (assoc match-string collection))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
590 (compl (or (car exact)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
591 (try-completion match-string collection))))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
592 (if compl (delete-region match-start (point)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
593 (cond ((null compl) (or silent (ding)))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
594 ((eq compl t) (tempo-insert-template
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
595 (cdr (assoc match-string
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
596 collection))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
597 nil))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
598 (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
599 (tempo-insert-template (cdr exact) nil)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
600 (insert compl)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
601 (or silent (ding))
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
602 (if tempo-show-completion-buffer
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
603 (tempo-display-completions match-string
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
604 collection)))))))
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606
7410
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
607 ;;;
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
608 ;;; tempo-display-completions
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
609
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
610 (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
611 "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
612 (if tempo-leave-completion-buffer
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
613 (with-output-to-temp-buffer "*Completions*"
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
614 (display-completion-list
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
615 (all-completions string tag-list)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
616 (save-window-excursion
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
617 (with-output-to-temp-buffer "*Completions*"
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
618 (display-completion-list
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
619 (all-completions string tag-list)))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
620 (sit-for 32767))))
4eca60cb3c4d (tempo-insert-region, tempo-show-completion-buffer,
Richard M. Stallman <rms@gnu.org>
parents: 7296
diff changeset
621
10516
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
622 (provide 'tempo)
488c5be866c3 (tempo-insert-template): Quoted transient-mark-mode
Richard M. Stallman <rms@gnu.org>
parents: 7410
diff changeset
623
7267
4aa70d4d981c Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 ;;; tempo.el ends here