comparison lisp/hm--html-menus/tmpl-minor-mode.el @ 177:6075d714658b r20-3b15

Import from CVS: tag r20-3b15
author cvs
date Mon, 13 Aug 2007 09:51:16 +0200
parents 25f70ba0133c
children
comparison
equal deleted inserted replaced
176:6866abce6aaf 177:6075d714658b
1 ;;; tmpl-minor-mode.el --- Template Minor Mode 1 ;;; tmpl-minor-mode.el --- Template Minor Mode
2 ;;; 2
3 ;;; $Id: tmpl-minor-mode.el,v 1.5 1997/05/29 23:49:44 steve Exp $ 3 ;; Copyright (C) 1993 - 1997 Heiko Muenkel
4 ;;; 4
5 ;;; Copyright (C) 1993 - 1997 Heiko Muenkel 5 ;; Author: Heiko Muenkel <muenkel@tnt.uni-hannover.de>
6 ;;; email: muenkel@tnt.uni-hannover.de 6 ;; Keywords: data tools
7 ;;; 7
8 ;;; Keywords: data tools 8 ;; $Id: tmpl-minor-mode.el,v 1.6 1997/07/26 22:09:46 steve Exp $
9 ;;; 9
10 ;;; This program is free software; you can redistribute it and/or modify 10 ;; This file is part of XEmacs.
11 ;;; it under the terms of the GNU General Public License as published by 11
12 ;;; the Free Software Foundation; either version 2, or (at your option) 12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;;; any later version. 13 ;; under the terms of the GNU General Public License as published by
14 ;;; 14 ;; the Free Software Foundation; either version 2, or (at your
15 ;;; This program is distributed in the hope that it will be useful, 15 ;; option) any later version.
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; This program is distributed in the hope that it will be useful, but
18 ;;; GNU General Public License for more details. 18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;;; You should have received a copy of the GNU General Public License 20 ;; General Public License for more details.
21 ;;; along with this program; if not, write to the Free Software 21
22 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 ;; You should have received a copy of the GNU General Public License
23 ;;; 23 ;; along with XEmacs; See the file COPYING. if not, write to the Free
24 ;;; 24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA
26
27 ;;; Synched up with: Not part of Emacs.
28
25 ;;; Commentary: 29 ;;; Commentary:
26 ;;; 30
27 ;;; This file contains functions to expand templates. 31 ;; Description:
28 ;;; Look at the file templates-syntax.doc for the syntax of the 32 ;; This file contains functions to expand templates.
29 ;;; templates. 33 ;; Look at the file templates-syntax.doc for the syntax of the
30 ;;; There are the following 2 interactive functions to expand 34 ;; templates.
31 ;;; templates: 35 ;; There are the following 2 interactive functions to expand
32 ;;; tmpl-expand-templates-in-region 36 ;; templates:
33 ;;; tmpl-expand-templates-in-buffer 37 ;; tmpl-expand-templates-in-region
34 ;;; The following two interactive functions are to escape the 38 ;; tmpl-expand-templates-in-buffer
35 ;;; unescaped special template signs: 39 ;; The following two interactive functions are to escape the
36 ;;; tmpl-escape-tmpl-sign-in-region 40 ;; unescaped special template signs:
37 ;;; tmpl-escape-tmpl-sign-in-buffer 41 ;; tmpl-escape-tmpl-sign-in-region
38 ;;; The following function ask for a name of a template file, inserts 42 ;; tmpl-escape-tmpl-sign-in-buffer
39 ;;; the template file and expands the templates: 43 ;; The following function ask for a name of a template file, inserts
40 ;;; tmpl-insert-template-file 44 ;; the template file and expands the templates:
41 ;;; If you want to use keystrokes to call the above functions, you must 45 ;; tmpl-insert-template-file
42 ;;; switch the minor mode tmpl-mode on with `tmpl-minor-mode'. After 46 ;; If you want to use keystrokes to call the above functions, you must
43 ;;; that, the following keys are defined: 47 ;; switch the minor mode tmpl-mode on with `tmpl-minor-mode'. After
44 ;;; `C-c x' = tmpl-expand-templates-in-region 48 ;; that, the following keys are defined:
45 ;;; `C-c C-x' = tmpl-expand-templates-in-buffer 49 ;; `C-c x' = tmpl-expand-templates-in-region
46 ;;; `C-c ESC' = tmpl-escape-tmpl-sign-in-region 50 ;; `C-c C-x' = tmpl-expand-templates-in-buffer
47 ;;; `C-c C-ESC' = tmpl-escape-tmpl-sign-in-buffer 51 ;; `C-c ESC' = tmpl-escape-tmpl-sign-in-region
48 ;;; Type again `M-x tmpl-minor-mode' to switch the template minor mode off. 52 ;; `C-c C-ESC' = tmpl-escape-tmpl-sign-in-buffer
49 ;;; 53 ;; Type again `M-x tmpl-minor-mode' to switch the template minor mode off.
50 ;;; This file needs also the file adapt.el ! 54
51 ;;; 55 ;; This file needs also the file adapt.el !
52 ;;; Installation: 56
53 ;;; 57
54 ;;; Put this file in one of your lisp directories and the following 58 ;; Installation:
55 ;;; lisp command in your .emacs: 59
56 ;;; (load-library "templates") 60 ;; Put this file in one of your lisp directories and the following
57 ;;; 61 ;; lisp command in your .emacs:
62 ;; (load-library "templates")
63
64 ;;; Code:
58 65
59 (require 'adapt) 66 (require 'adapt)
60 67
61 68 (defgroup tmpl-minor nil
62 (defvar tmpl-template-dir-list nil 69 "A package for inserting and expanding templates."
70 :group 'data)
71
72 (defcustom tmpl-template-dir-list nil
63 "*A list of directories with the template files. 73 "*A list of directories with the template files.
64 If it is nil, then the default-directory will be used. 74 If it is nil, then the default-directory will be used.
65 If more than one directory is given, then the 75 If more than one directory is given, then the
66 template filenames should differ in all directories. 76 template filenames should differ in all directories.
67 77
68 This variable is used in the commands for inserting templates. 78 This variable is used in the commands for inserting templates.
69 Look at `tmpl-insert-template-file-from-fixed-dirs' and 79 Look at `tmpl-insert-template-file-from-fixed-dirs' and
70 at `tmpl-insert-template-file'. The command `tmpl-insert-template-file' 80 at `tmpl-insert-template-file'. The command `tmpl-insert-template-file'
71 uses only the car of the list (if it is a list).") 81 uses only the car of the list (if it is a list)."
72 82 :group 'tmpl-minor
73 (defvar tmpl-automatic-expand t 83 :type '(choice (const :tag "default-directory" :value nil)
84 (repeat directory)))
85
86 (defcustom tmpl-automatic-expand t
74 "*An inserted template will be automaticly expanded, if this is t. 87 "*An inserted template will be automaticly expanded, if this is t.
75 88
76 This variable is used in the commands for inserting templates. 89 This variable is used in the commands for inserting templates.
77 Look at `tmpl-insert-template-file-from-fixed-dirs' and 90 Look at `tmpl-insert-template-file-from-fixed-dirs' and
78 at `tmpl-insert-template-file'.") 91 at `tmpl-insert-template-file'."
79 92 :group 'tmpl-minor
80 (defvar tmpl-filter-regexp ".*\\.tmpl$" 93 :type 'boolean)
94
95
96 (defcustom tmpl-filter-regexp ".*\\.tmpl$"
81 "*Regexp for filtering out non template files in a directory. 97 "*Regexp for filtering out non template files in a directory.
82 It is used in `tmpl-insert-template-file-from-fixed-dirs' to allow 98 It is used in `tmpl-insert-template-file-from-fixed-dirs' to allow
83 only the selecting of files, which are matching the regexp. 99 only the selecting of files, which are matching the regexp.
84 If it is nil, then the Filter \".*\\.tmpl$\" is used. 100 If it is nil, then the Filter \".*\\.tmpl$\" is used.
85 Set it to \".*\" if you want to disable the filter function or 101 Set it to \".*\" if you want to disable the filter function or
86 use the command `tmpl-insert-template-file'.") 102 use the command `tmpl-insert-template-file'."
103 :group 'tmpl-minor
104 :type 'string)
87 105
88 (defvar tmpl-history-variable-name 'tmpl-history-variable 106 (defvar tmpl-history-variable-name 'tmpl-history-variable
89 "The name of the history variable. 107 "The name of the history variable.
90 The history variable is used by the commands `tmpl-insert-template-file' 108 The history variable is used by the commands `tmpl-insert-template-file'
91 and `tmpl-insert-template-file-from-fixed-dirs'. 109 and `tmpl-insert-template-file-from-fixed-dirs'.
93 Not used in the Emacs 19.") 111 Not used in the Emacs 19.")
94 112
95 (defvar tmpl-history-variable nil 113 (defvar tmpl-history-variable nil
96 "The history variable. See also `tmpl-history-variable-name'.") 114 "The history variable. See also `tmpl-history-variable-name'.")
97 115
98 (defvar tmpl-sign "\000" "Sign which marks a template expression.") 116 (defcustom tmpl-sign "\000"
99 117 "Sign which marks a template expression."
118 :group 'tmpl-minor
119 :type 'string)
100 120
101 (defvar tmpl-name-lisp "LISP" "Name of the lisp templates.") 121 (defvar tmpl-name-lisp "LISP" "Name of the lisp templates.")
102 122
103 123
104 (defvar tmpl-name-command "COMMAND" "Name of the emacs command templates.") 124 (defvar tmpl-name-command "COMMAND" "Name of the emacs command templates.")
135 (save-restriction 155 (save-restriction
136 (widen) 156 (widen)
137 (save-excursion 157 (save-excursion
138 (beginning-of-line) 158 (beginning-of-line)
139 (1+ (count-lines 1 (point)))))) 159 (1+ (count-lines 1 (point))))))
140
141
142 ;(defun mapcar* (f &rest args)
143 ; "Apply FUNCTION to successive cars of all ARGS, until one ends.
144 ;Return the list of results."
145 ; (if (not (memq 'nil args)) ; If no list is exhausted,
146 ; (cons (apply f (mapcar 'car args)) ; Apply function to CARs.
147 ; (apply 'mapcar* f ; Recurse for rest of elements.
148 ; (mapcar 'cdr args)))))
149 ;
150 ;(defmacro tmpl-error (&rest args)
151 ; "Widen the buffer and signal an error.
152 ;Making error message by passing all args to `error',
153 ;which passes all args to format."
154 ; (widen)
155 ; (error args))
156 160
157 161
158 (defun tmpl-search-next-template-sign (&optional dont-unescape) 162 (defun tmpl-search-next-template-sign (&optional dont-unescape)
159 "Search the next template sign after the current point. 163 "Search the next template sign after the current point.
160 It returns t, if a template is found and nil otherwise. 164 It returns t, if a template is found and nil otherwise.
240 (defun tmpl-expand-comment-template (begin-of-template template-attribute-list) 244 (defun tmpl-expand-comment-template (begin-of-template template-attribute-list)
241 "Expand the comment template, which starts at the point BEGIN-OF-TEMPLATE. 245 "Expand the comment template, which starts at the point BEGIN-OF-TEMPLATE.
242 TEMPLATE-ATTRIBUTE-LIST is the attribute list of the template." 246 TEMPLATE-ATTRIBUTE-LIST is the attribute list of the template."
243 (end-of-line) 247 (end-of-line)
244 (template-delete-template begin-of-template template-attribute-list)) 248 (template-delete-template begin-of-template template-attribute-list))
245 ; (tmpl-save-excursion
246 ; (if (or (not (assoc tmpl-attribute-dont-delete template-attribute-list))
247 ; (not (car (cdr (assoc tmpl-attribute-dont-delete
248 ; template-attribute-list)))))
249 ; (if (and (assoc tmpl-attribute-delete-line template-attribute-list)
250 ; (car (cdr (assoc tmpl-attribute-delete-line
251 ; template-attribute-list))))
252 ; ;; Delete the whole line
253 ; (let ((end-of-region (progn (end-of-line) (point)))
254 ; (start-of-region begin-of-template)) ; ausgetauscht
255 ; (delete-region start-of-region end-of-region)
256 ; (delete-char 1))
257 ; ;; Delete only the comment
258 ; (let ((end-of-region (progn
259 ; (end-of-line)
260 ; (point)))
261 ; (start-of-region (progn (goto-char begin-of-template)
262 ; (point))))
263 ; (delete-region start-of-region end-of-region))))))
264 249
265 250
266 (defun tmpl-get-template-argument () 251 (defun tmpl-get-template-argument ()
267 "Return the Text between a start tag and the end tag as symbol. 252 "Return the Text between a start tag and the end tag as symbol.
268 The point must be after the `templ-sign' of the start tag. 253 The point must be after the `templ-sign' of the start tag.
516 (when anser-not-ok 501 (when anser-not-ok
517 (setq directories (list (tmpl-read-template-directory 502 (setq directories (list (tmpl-read-template-directory
518 "Directory with Templatefiles: " 503 "Directory with Templatefiles: "
519 (car directories)))))) 504 (car directories))))))
520 (unless (or (not history-variable) 505 (unless (or (not history-variable)
521 ; (string= answer (car internal-history)))
522 (string= file (car (eval history-variable)))) 506 (string= file (car (eval history-variable))))
523 (set history-variable (cons file (eval history-variable)))) 507 (set history-variable (cons file (eval history-variable))))
524 file)) 508 file))
525 509
526 510
592 (insert-file (expand-file-name file)) 576 (insert-file (expand-file-name file))
593 (if tmpl-automatic-expand 577 (if tmpl-automatic-expand
594 (tmpl-expand-templates-in-buffer)) 578 (tmpl-expand-templates-in-buffer))
595 file) 579 file)
596 580
597 ;(defun tmpl-insert-template-file (&optional template-dir automatic-expand)
598 ; "Insert a template file and expand it, if AUTOMATIC-EXPAND is t.
599 ;The TEMPLATE-DIR is the directory with the template files."
600 ; (interactive)
601 ; (insert-file
602 ; (expand-file-name
603 ; (read-file-name "Templatefile: "
604 ; template-dir
605 ; nil
606 ; t)))
607 ; (if automatic-expand
608 ; (tmpl-expand-templates-in-buffer)))
609 581
610 ;;; General utilities, which are useful in a template file 582 ;;; General utilities, which are useful in a template file
611 (defun tmpl-util-indent-region (begin end) 583 (defun tmpl-util-indent-region (begin end)
612 "Indents a region acording to the mode." 584 "Indents a region acording to the mode."
613 (interactive "r") 585 (interactive "r")
698 670
699 (setq minor-mode-alist (cons '(tmpl-minor-mode " TMPL") minor-mode-alist)) 671 (setq minor-mode-alist (cons '(tmpl-minor-mode " TMPL") minor-mode-alist))
700 672
701 673
702 (provide 'tmpl-minor-mode) 674 (provide 'tmpl-minor-mode)
675
676 ;;; tmpl-minor-mode ends here