annotate lisp/hm--html-menus/tmpl-minor-mode.el @ 42:8b8b7f3559a2 r19-15b104

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