annotate lisp/hm--html-menus/tmpl-minor-mode.el @ 206:d3e9274cbc4e

Added tag r20-4b1 for changeset 92f8ad5d0d3f
author cvs
date Mon, 13 Aug 2007 10:02:48 +0200
parents 6075d714658b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; tmpl-minor-mode.el --- Template Minor Mode
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
2
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
3 ;; Copyright (C) 1993 - 1997 Heiko Muenkel
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
4
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
5 ;; Author: Heiko Muenkel <muenkel@tnt.uni-hannover.de>
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
6 ;; Keywords: data tools
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
7
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
8 ;; $Id: tmpl-minor-mode.el,v 1.6 1997/07/26 22:09:46 steve Exp $
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
9
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
10 ;; This file is part of XEmacs.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
11
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
13 ;; under the terms of the GNU General Public License as published by
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
15 ;; option) any later version.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
16
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
17 ;; This program is distributed in the hope that it will be useful, but
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
20 ;; General Public License for more details.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
21
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
22 ;; You should have received a copy of the GNU General Public License
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
23 ;; along with XEmacs; See the file COPYING. if not, write to the Free
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
25 ;; 02111-1307, USA
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
26
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
27 ;;; Synched up with: Not part of Emacs.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
28
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Commentary:
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
30
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
31 ;; Description:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
32 ;; This file contains functions to expand templates.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
33 ;; Look at the file templates-syntax.doc for the syntax of the
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
34 ;; templates.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
35 ;; There are the following 2 interactive functions to expand
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
36 ;; templates:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
37 ;; tmpl-expand-templates-in-region
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
38 ;; tmpl-expand-templates-in-buffer
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
39 ;; The following two interactive functions are to escape the
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
40 ;; unescaped special template signs:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
41 ;; tmpl-escape-tmpl-sign-in-region
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
42 ;; tmpl-escape-tmpl-sign-in-buffer
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
43 ;; The following function ask for a name of a template file, inserts
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
44 ;; the template file and expands the templates:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
45 ;; tmpl-insert-template-file
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
46 ;; If you want to use keystrokes to call the above functions, you must
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
47 ;; switch the minor mode tmpl-mode on with `tmpl-minor-mode'. After
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
48 ;; that, the following keys are defined:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
49 ;; `C-c x' = tmpl-expand-templates-in-region
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
50 ;; `C-c C-x' = tmpl-expand-templates-in-buffer
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
51 ;; `C-c ESC' = tmpl-escape-tmpl-sign-in-region
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
52 ;; `C-c C-ESC' = tmpl-escape-tmpl-sign-in-buffer
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
53 ;; Type again `M-x tmpl-minor-mode' to switch the template minor mode off.
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
54
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
55 ;; This file needs also the file adapt.el !
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
56
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
57
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
58 ;; Installation:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
59
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
60 ;; Put this file in one of your lisp directories and the following
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
61 ;; lisp command in your .emacs:
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
62 ;; (load-library "templates")
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
63
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
64 ;;; Code:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (require 'adapt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
68 (defgroup tmpl-minor nil
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
69 "A package for inserting and expanding templates."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
70 :group 'data)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
72 (defcustom tmpl-template-dir-list nil
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
73 "*A list of directories with the template files.
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
74 If it is nil, then the default-directory will be used.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
75 If more than one directory is given, then the
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
76 template filenames should differ in all directories.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
77
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
78 This variable is used in the commands for inserting templates.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
79 Look at `tmpl-insert-template-file-from-fixed-dirs' and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
80 at `tmpl-insert-template-file'. The command `tmpl-insert-template-file'
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
81 uses only the car of the list (if it is a list)."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
82 :group 'tmpl-minor
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
83 :type '(choice (const :tag "default-directory" :value nil)
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
84 (repeat directory)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
85
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
86 (defcustom tmpl-automatic-expand t
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
87 "*An inserted template will be automaticly expanded, if this is t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
88
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
89 This variable is used in the commands for inserting templates.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
90 Look at `tmpl-insert-template-file-from-fixed-dirs' and
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
91 at `tmpl-insert-template-file'."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
92 :group 'tmpl-minor
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
93 :type 'boolean)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
94
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
95
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
96 (defcustom tmpl-filter-regexp ".*\\.tmpl$"
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
97 "*Regexp for filtering out non template files in a directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
98 It is used in `tmpl-insert-template-file-from-fixed-dirs' to allow
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
99 only the selecting of files, which are matching the regexp.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
100 If it is nil, then the Filter \".*\\.tmpl$\" is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
101 Set it to \".*\" if you want to disable the filter function or
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
102 use the command `tmpl-insert-template-file'."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
103 :group 'tmpl-minor
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
104 :type 'string)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
105
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
106 (defvar tmpl-history-variable-name 'tmpl-history-variable
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
107 "The name of the history variable.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
108 The history variable is used by the commands `tmpl-insert-template-file'
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
109 and `tmpl-insert-template-file-from-fixed-dirs'.
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
110
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
111 Not used in the Emacs 19.")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
112
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
113 (defvar tmpl-history-variable nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
114 "The history variable. See also `tmpl-history-variable-name'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
115
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
116 (defcustom tmpl-sign "\000"
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
117 "Sign which marks a template expression."
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
118 :group 'tmpl-minor
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
119 :type 'string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (defvar tmpl-name-lisp "LISP" "Name of the lisp templates.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (defvar tmpl-name-command "COMMAND" "Name of the emacs command templates.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar tmpl-name-comment "C" "Name of a comment template.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvar tmpl-attribute-delete-line 'DELETE-LINE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "Attribute name of the attribute `delete-line`.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defvar tmpl-attribute-dont-delete 'DONT-DELETE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 "Attribute name of the attribute `dont-delete`.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defvar tmpl-end-template "END" "End of a template.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (defvar tmpl-white-spaces "
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
142 " "String with white spaces.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defmacro tmpl-save-excursion (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "Put `save-excursion' and `save-window-excursion' around the body."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (`(save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (, (cons 'save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 body)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defun tmpl-current-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "Returns the current line number."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (1+ (count-lines 1 (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defun tmpl-search-next-template-sign (&optional dont-unescape)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Search the next template sign after the current point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 It returns t, if a template is found and nil otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 If DONT-UNESCAPE is t, then the escaped template signs are not unescaped."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (search-forward tmpl-sign nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (or (eq (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (not (string= tmpl-sign
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (buffer-substring (point) (+ (length tmpl-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (if (not dont-unescape)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (delete-char (length tmpl-sign))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (tmpl-search-next-template-sign dont-unescape))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun tmpl-get-template-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "Return a string with the template tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 That is the string from the current point to the next `tmpl-sign',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 without the tmpl-sign. The point is set after the `tmpl-sign'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (let ((template-start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (if (tmpl-search-next-template-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (buffer-substring template-start (- (point) (length tmpl-sign)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defun tmpl-get-template-name (template-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "Returns the name of the template in the TEMPLATE-STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (let* ((start (string-match (concat "[^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 template-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (end (string-match (concat "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 template-string start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (substring template-string start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (substring template-string start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun tmpl-get-template-attribute-list (template-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "Returns the attribute list (as a lisp list) from the template-string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (let* ((start (string-match (concat "[^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 template-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (setq start (string-match (concat "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 template-string start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (if start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (car (read-from-string template-string start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun template-delete-template (begin-of-template template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Delete the current template from BEGIN-OF-TEMPLATE to the current point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (tmpl-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (or (not (assoc tmpl-attribute-dont-delete template-attribute-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (not (car (cdr (assoc tmpl-attribute-dont-delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 template-attribute-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if (and (assoc tmpl-attribute-delete-line template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (car (cdr (assoc tmpl-attribute-delete-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 template-attribute-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let ((end-of-template (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (diff 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (skip-chars-forward " \t") ; Skip blanks and tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if (string= "\n" (buffer-substring (point) (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq diff 0) ; don't delete the linefeed at the beginnig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (setq end-of-template (1+ (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (goto-char begin-of-template)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (skip-chars-backward " \t") ; Skip blanks and tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (if (eq (point) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (delete-region (point) end-of-template)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (string= "\n" (buffer-substring (1- (point)) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (delete-region (- (point) diff) end-of-template)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (delete-region begin-of-template end-of-template))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (delete-region begin-of-template (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun tmpl-expand-comment-template (begin-of-template template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "Expand the comment template, which starts at the point BEGIN-OF-TEMPLATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 TEMPLATE-ATTRIBUTE-LIST is the attribute list of the template."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (template-delete-template begin-of-template template-attribute-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (defun tmpl-get-template-argument ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 "Return the Text between a start tag and the end tag as symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 The point must be after the `templ-sign' of the start tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 After this function has returned, the point is after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 first `templ-sign' of the end tag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (let ((start-of-argument-text (progn (skip-chars-forward tmpl-white-spaces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (if (tmpl-search-next-template-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (car (read-from-string (buffer-substring start-of-argument-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (- (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (length tmpl-sign)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (error "Error Before Line %d: First Template Sign Of End Tag Missing !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (tmpl-current-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun tmpl-make-list-of-words-from-string (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Return a list of words which occur in the string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (cond ((or (not (stringp string)) (string= "" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (t (let* ((end-of-first-word (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (concat "["
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (rest-of-string (substring string (1+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 end-of-first-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (1- (length string)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (cons (substring string 0 end-of-first-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (tmpl-make-list-of-words-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (substring rest-of-string (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (concat "[^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 tmpl-white-spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 rest-of-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 0))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defun tmpl-get-template-end-tag ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "Return a list with the elements of the following end tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 The point must be after the first `templ-sign' of the end tag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 After this function has returned, the point is after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 last `templ-sign' of the end tag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (let* ((start-point (progn (skip-chars-forward tmpl-white-spaces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (end-tag-string (if (tmpl-search-next-template-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (buffer-substring start-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (- (point) (length tmpl-sign)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (error "Error Before Line %d: Last Template Sign Of End Tag Missing !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (tmpl-current-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (tmpl-make-list-of-words-from-string end-tag-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defun tmpl-expand-command-template (begin-of-template template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "Expand the command template, which starts at the point BEGIN-OF-TEMPLATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 TEMPLATE-ATTRIBUTE-LIST is the attribute list of the template."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (let ((template-argument (tmpl-get-template-argument))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (template-end-tag (tmpl-get-template-end-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (if (equal (list tmpl-end-template tmpl-name-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 template-end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (tmpl-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (template-delete-template begin-of-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (command-execute template-argument)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (error "ERROR in Line %d: Wrong Template Command End Tag"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (tmpl-current-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defun tmpl-expand-lisp-template (begin-of-template template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "Expand the lisp template, which starts at the point BEGIN-OF-TEMPLATE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 TEMPLATE-ATTRIBUTE-LIST is the attribute list of the template."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (let ((template-argument (tmpl-get-template-argument))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (template-end-tag (tmpl-get-template-end-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (if (equal (list tmpl-end-template tmpl-name-lisp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 template-end-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (tmpl-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (template-delete-template begin-of-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 template-attribute-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (eval template-argument)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (error "ERROR in Line %d: Wrong Template Lisp End Tag"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (tmpl-current-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (defun tmpl-expand-template-at-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 "Expand the template at the current point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 The point must be after the sign ^@."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (let ((begin-of-template (- (point) (length tmpl-sign)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (template-tag (tmpl-get-template-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (if (not template-tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (error "ERROR In Line %d: End Sign Of Template Tag Missing !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (tmpl-current-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (let ((template-name (tmpl-get-template-name template-tag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (template-attribute-list (tmpl-get-template-attribute-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 template-tag)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (cond ((not template-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (error "ERROR In Line %d: No Template Name"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (tmpl-current-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ((string= tmpl-name-comment template-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; comment template found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (tmpl-expand-comment-template begin-of-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 template-attribute-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ((string= tmpl-name-command template-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; command template found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (tmpl-expand-command-template begin-of-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 template-attribute-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 ((string= tmpl-name-lisp template-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ;; lisp template found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (tmpl-expand-lisp-template begin-of-template
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 template-attribute-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (t (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (error "ERROR In Line %d: Wrong Template Name (%s) !"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (tmpl-current-line) template-name)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
376 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (defun tmpl-expand-templates-in-region (&optional begin end)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
378 "Expands the templates in the region from BEGIN to END.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
379 If BEGIN and END are nil, then the current region is used."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (tmpl-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (narrow-to-region (or begin (region-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (or end (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (while (tmpl-search-next-template-sign)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (tmpl-expand-template-at-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (widen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
390 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defun tmpl-expand-templates-in-buffer ()
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
392 "Expands all templates in the current buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (tmpl-expand-templates-in-region (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (defun tmpl-escape-tmpl-sign-in-region (&optional begin end)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
398 "Escapes all `tmpl-sign' with a `tmpl-sign' in the region from BEGIN to END.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 If BEGIN and END are nil, then the active region between mark and point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (narrow-to-region (or begin (region-beginning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (or end (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (while (tmpl-search-next-template-sign t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (insert tmpl-sign))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (widen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (defun tmpl-escape-tmpl-sign-in-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 "Escape all `tmpl-sign' with a `tmpl-sign' in the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (tmpl-escape-tmpl-sign-in-region (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
416 (defun tmpl-get-table-with-template-files (template-dirs filter-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
417 "Returns a table (alist) with all filenames matching the FILTER-REGEXP.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
418 It searches the files in in all directories of the list TEMPLATE-DIRS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
419 The alist looks like:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
420 '((file-name . file-name-with-path) ...)"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
421 (cond ((not template-dirs) '())
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
422 ((file-accessible-directory-p (car template-dirs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
423 (append (mapcar '(lambda (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
424 (cons (file-name-nondirectory file) file))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
425 (if (adapt-xemacsp)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
426 (directory-files (car template-dirs)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
427 t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
428 filter-regexp
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
429 nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
430 t)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
431 (directory-files (car template-dirs)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
432 t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
433 filter-regexp
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
434 nil)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
435 (tmpl-get-table-with-template-files (cdr template-dirs)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
436 filter-regexp)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
437 (t (tmpl-get-table-with-template-files (cdr template-dirs)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
438 filter-regexp))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
440 (defun tmpl-insert-change-dir-entry (table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
441 "Insert the entry '(\"Change the directory\" . select-other-directory)."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
442 (cons '("Change the directory" . select-other-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
443 table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
444
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
445 (defun tmpl-read-template-directory (prompt default-direcory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
446 "Reads a template directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
447 If the directory isn't already in `tmpl-template-dirs', the it asks,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
448 if it should be added to it."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
449 (let ((directory (expand-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
450 (read-directory-name prompt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
451 (or default-direcory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
452 (default-directory))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
453 (when (and (not (member* directory tmpl-template-dir-list :test 'string=))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
454 (y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
455 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
456 "Add %s permanent to the template directory list? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
457 directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
458 (setq tmpl-template-dir-list (cons directory tmpl-template-dir-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
459 directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
460
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
461 (defun tmpl-read-template-filename (&optional
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
462 template-dirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
463 filter-regexp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
464 history-variable)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
465 "Reads interactive the name of a template file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
466 The TEMPLATE-DIRS is a list of directories with template files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
467 Note: The template filenames should differ in all directories.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
468 If it is nil, then the default-directory is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
469 FILTER-REGEXP can be used to allow only the selecting of files,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
470 which are matching the regexp. If FILTER-REGEXP is nil, then the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
471 Filter \".*\\.tmpl$\" is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
472 HISTROY-VARIABLE contains the last template file names."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
473 (let ((filter (or filter-regexp ".*\\.tmpl$"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
474 (directories (or template-dirs (list (default-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
475 (table nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
476 (file nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
477 (answer nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
478 (anser-not-ok t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
479 (internal-history (mapcar '(lambda (path)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
480 (file-name-nondirectory path))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
481 (eval history-variable))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
482 (while anser-not-ok
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
483 (setq table (tmpl-get-table-with-template-files directories filter))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
484 (while (not table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
485 ;; Try another filter (all files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
486 (setq table (tmpl-get-table-with-template-files directories ".*"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
487 (unless table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
488 (setq directories (list (tmpl-read-template-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
489 "No files found, try another directory: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
490 (car directories))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
491 (setq table (tmpl-insert-change-dir-entry table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
492 (setq answer (completing-read "Templatefile: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
493 table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
494 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
495 t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
496 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
497 'internal-history))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
498 (setq file (cdr (assoc* answer table :test 'string=)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
499 (setq anser-not-ok (equal file 'select-other-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
500 (when anser-not-ok
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
501 (setq directories (list (tmpl-read-template-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
502 "Directory with Templatefiles: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
503 (car directories))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
504 (unless (or (not history-variable)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
505 (string= file (car (eval history-variable))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
506 (set history-variable (cons file (eval history-variable))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
507 file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
508
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
509
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
510
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
511 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
512 (defun tmpl-insert-template-file-from-fixed-dirs (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
513 "Inserts a template FILE and expands it, if `tmpl-automatic-expand' is t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
514 This command tries to read the template file from a list of
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
515 predefined directories (look at `tmpl-template-dir-list') and it filters
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
516 the contents of these directories with the regular expression
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
517 `tmpl-filter-regexp' (look also at this variable).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
518 The command uses a history variable, which could be changed with the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
519 variable `tmpl-history-variable-name'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
520
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
521 The user of the command is able to change interactively to another
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
522 directory by entering at first the string \"Change the directory\".
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
523 This may be too difficult for the user. Therefore another command
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
524 called `tmpl-insert-template-file' exist, which doesn't use fixed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
525 directories and filters."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
526 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
527 (list (tmpl-read-template-filename tmpl-template-dir-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
528 tmpl-filter-regexp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
529 tmpl-history-variable-name)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
530 (insert-file (expand-file-name file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
531 (if tmpl-automatic-expand
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
532 (tmpl-expand-templates-in-region (point) (mark t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
533 file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
534
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
535
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
536 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
537 (defun tmpl-insert-template-file (file)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
538 "Inserts a template FILE and expand it, if `tmpl-automatic-expand' is t.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
539 Look also at `tmpl-template-dir-list', to specify a default template directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
540 You should also take a look at `tmpl-insert-template-file-from-fixed-dirs'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
541 which has additional advantages (and disadvantages :-).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
542
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
543 ATTENTION: The interface of this function has changed. The old
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
544 function had the argument list (&optional TEMPLATE-DIR AUTOMATIC-EXPAND).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
545 The variables `tmpl-template-dir-list' and `tmpl-automatic-expand' must
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
546 now be used instead of the args TEMPLATE-DIR and AUTOMATIC-EXPAND."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
547 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
548 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
549 (let* ((default-directory (or (car tmpl-template-dir-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
550 default-directory))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
551 (filename (if (adapt-xemacsp)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
552 (read-file-name "Templatefile: "
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
553 (if (listp tmpl-template-dir-list)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
554 (car tmpl-template-dir-list))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
555 nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
556 t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
557 nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
558 tmpl-history-variable-name)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
559 (read-file-name "Templatefile: "
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
560 (if (listp tmpl-template-dir-list)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
561 (car tmpl-template-dir-list))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
562 nil
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
563 t
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
564 nil)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
565 (directory (expand-file-name (file-name-directory filename))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
566 (when (and (not (member* directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
567 tmpl-template-dir-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
568 :test 'string=))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
569 (y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
570 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
571 "Add %s permanent to the template directory list? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
572 directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
573 (setq tmpl-template-dir-list (cons directory tmpl-template-dir-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
574 filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
575 (insert-file (expand-file-name file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
576 (if tmpl-automatic-expand
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
577 (tmpl-expand-templates-in-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
578 file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 70
diff changeset
579
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
580
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
581 ;;; General utilities, which are useful in a template file
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
582 (defun tmpl-util-indent-region (begin end)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
583 "Indents a region acording to the mode."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
584 (interactive "r")
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
585 (save-excursion
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
586 (goto-char end)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
587 (let ((number-of-lines (count-lines begin (point)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
588 (line 0))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
589 (goto-char begin)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
590 (while (< line number-of-lines)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
591 (setq line (1+ line))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
592 (indent-according-to-mode)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
593 (forward-line)))))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
594
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
595 (defun tmpl-util-indent-buffer ()
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
596 "Indents the whole buffer acording to the mode."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
597 (interactive)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
598 (tmpl-util-indent-region (point-min) (point-max)))
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 116
diff changeset
599
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
600
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;;; Definition of the minor mode tmpl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (defvar tmpl-minor-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 "*t, if the minor mode tmpl-mode is on and nil otherwise.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (make-variable-buffer-local 'tmpl-minor-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;(set-default 'tmpl-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (defvar tmpl-old-local-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 "Local keymap, before the minor-mode tmpl was switched on.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (make-variable-buffer-local 'tmpl-old-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (defvar tmpl-minor-mode-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 "*The keymap for the minor mode tmpl-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (make-variable-buffer-local 'tmpl-minor-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (if (adapt-xemacsp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (defun tmpl-define-minor-mode-keymap ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 "Defines the minor mode keymap."
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
629 (define-key tmpl-minor-mode-map [(control c) (control c) x]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 'tmpl-expand-templates-in-region)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
631 (define-key tmpl-minor-mode-map [(control c) (control c) (control x)]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 'tmpl-expand-templates-in-buffer)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
633 (define-key tmpl-minor-mode-map [(control c) (control c) e]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 'tmpl-escape-tmpl-sign-in-region)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
635 (define-key tmpl-minor-mode-map
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
636 [(control c) (control c) (control e)]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 'tmpl-escape-tmpl-sign-in-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (defun tmpl-define-minor-mode-keymap ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 "Defines the minor mode keymap."
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
640 (define-key tmpl-minor-mode-map [?\C-c ?\C-c ?x]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 'tmpl-expand-templates-in-region)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
642 (define-key tmpl-minor-mode-map [?\C-c ?\C-c ?\C-x]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 'tmpl-expand-templates-in-buffer)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
644 (define-key tmpl-minor-mode-map [?\C-c ?\C-c ?e]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 'tmpl-escape-tmpl-sign-in-region)
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 104
diff changeset
646 (define-key tmpl-minor-mode-map [?\C-c ?\C-c ?\C-e]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 'tmpl-escape-tmpl-sign-in-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (defun tmpl-minor-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 "Toggle the minor mode tmpl-mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (if tmpl-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (setq tmpl-minor-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (use-local-map tmpl-old-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (setq tmpl-old-local-map nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (setq tmpl-minor-mode t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (setq tmpl-old-local-map (current-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (if tmpl-old-local-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (setq tmpl-minor-mode-map (copy-keymap tmpl-old-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (setq tmpl-minor-mode-map nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (setq tmpl-minor-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (set-keymap-name tmpl-minor-mode-map 'minor-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (tmpl-define-minor-mode-keymap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (use-local-map tmpl-minor-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (setq minor-mode-alist (cons '(tmpl-minor-mode " TMPL") minor-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (provide 'tmpl-minor-mode)
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
674
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 153
diff changeset
675 ;;; tmpl-minor-mode ends here