annotate lisp/hm--html-menus/tmpl-minor-mode.el @ 172:a38aed19690b

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