1 ;; tt-mode.el --- Emacs major mode for editing Template Toolkit files
3 ;; Copyright (c) 2002 Dave Cross, all rights reserved.
5 ;; This file may be distributed under the same terms as GNU Emacs.
7 ;; $Id: tt-mode.el 13 2008-01-27 09:35:16Z dave $
9 ;; This file adds simple font highlighting of TT directives when you are
10 ;; editing Template Toolkit files.
12 ;; I usually give these files an extension of .tt and in order to automatically
13 ;; invoke this mode for these files, I have the following in my .emacs file.
16 ;; (cons "/home/dave/xemacs" load-path))
17 ;; (autoload 'tt-mode "tt-mode")
18 ;; (setq auto-mode-alist
19 ;; (append '(("\\.tt$" . tt-mode)) auto-mode-alist ))
21 ;; Something similar may well work for you.
23 ;; Author: Dave Cross <dave@dave.org.uk>
25 ;; Modified by Lennart Borgman 2008-08-06
29 (defvar tt-mode-hook nil
30 "List of functions to call when entering TT mode")
34 (regexp-opt (list "GET" "CALL" "SET" "DEFAULT" "INSERT" "INCLUDE"
35 "BLOCK" "END" "PROCESS" "WRAPPER" "IF" "UNLESS"
36 "ELSIF" "ELSE" "SWITCH" "CASE" "FOR" "FOREACH"
37 "WHILE" "FILTER" "USE" "MACRO" "PERL" "RAWPERL"
38 "TRY" "THROW" "CATCH" "FINAL" "LAST" "RETURN"
39 "STOP" "CLEAR" "META" "TAGS"))
42 (defvar tt-font-lock-keywords
44 ;; Fontify [& ... &] expressions
45 '("\\(\\[%[-+]?\\)\\(\\(.\\|\n\\)+?\\)\\([-+]?%\\]\\)"
46 (1 font-lock-string-face t)
47 (2 font-lock-variable-name-face t)
48 (4 font-lock-string-face t))
49 ;; Look for keywords within those expressions
51 ;; Comment out whole directive tag
52 '("\\[%\\(#.*?\\)%\\]"
53 (1 font-lock-comment-face t))
54 ;; Comments to end of line
55 ;;; '("\\[%\\(?:.\\|\n\\)*\\(#.*\\)"
56 ;;; (1 font-lock-comment-face t))
57 '("\\[% *\\([a-z_0-9]*\\) *%\\]"
58 (1 font-lock-constant-face t))
60 "\\(\\[%[-+]?\\|;\\)[ \n\t]*\\("
63 2 font-lock-keyword-face t)
65 "Expressions to font-lock in tt-mode.")
67 ;; (defvar tt-font-lock-keywords
68 ;; ;; Since this is used in a multi major mode we
70 ;; ;; Fontify [& ... &] expressions
71 ;; ;;; '("^\\([-+]?\\)\\(\\(.\\|\n\\)+?\\)\\([-+]?\\)$"
72 ;; ;;; (1 font-lock-string-face t)
73 ;; ;;; (2 font-lock-variable-name-face t)
74 ;; ;;; (4 font-lock-string-face t))
76 ;; (1 font-lock-comment-face t))
77 ;; '("^ *\\([a-z_0-9]*\\) *$"
78 ;; (1 font-lock-constant-face t))
80 ;; "^\\(?:[-+]?\\|;\\)[ \n\t]*\\("
84 ;; 1 font-lock-keyword-face t)
86 ;; "Expressions to font-lock in tt-mode.")
88 (defvar tt-font-lock-defaults
89 '(tt-font-lock-keywords nil t))
91 (defun tt-mode-after-change (beg end pre-len)
92 ;; add/remove font-lock-multiline
93 ;; Fix-me: add variable for search lengths
95 (beg-is-ml (get-text-property beg 'font-lock-multiline))
100 (let ((beg-ok (not (previous-single-property-change
101 here 'font-lock-multiline
106 (search-forward "%]" end t)
108 (search-forward "[%" end t)
111 (remove-list-of-text-properties here tt-beg '(font-lock-multiline))
112 (set-text-properties tt-beg tt-end '(font-lock-multiline t))))
117 (define-derived-mode tt-mode fundamental-mode "TT"
118 "Major mode for editing Template Toolkit files."
119 (set (make-local-variable 'font-lock-defaults) tt-font-lock-defaults)
120 (add-hook 'after-change-functions 'tt-mode-after-change nil t)
124 ;; tt-mode.el ends here