43687
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; xml-lite.el --- an indentation-engine for XML
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3 ;; Copyright (C) 2001 Mike Williams <mdub@bigfoot.com>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Author: Mike Williams <mdub@bigfoot.com>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Created: February 2001
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;; Version: $Revision: 1.24 $
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; Keywords: xml
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; This program is free software; you can redistribute it and/or modify
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;; it under the terms of the GNU General Public License as published by
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;; the Free Software Foundation; either version 2 of the License, or
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; (at your option) any later version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; This program is distributed in the hope that it will be useful,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;; GNU General Public License for more details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 ;; Boston, MA 02111-1307, USA.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 ;;; Commentary:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;; This package provides a simple indentation engine for XML. It is
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;; intended for use in situations where the full power of the popular PSGML
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 ;; package (DTD parsing, syntax checking) is not required.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 ;; xml-lite is designed to be used in conjunction with the default GNU
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 ;; Emacs sgml-mode, to provide a lightweight XML-editing environment.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;; Updates will be made available at:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; http://www.bigfoot.com/~mdub/software/xml-lite.el
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 ;; Note: the font-lock support that was in this package has been removed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 ;;; Thanks:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 ;; Jens Schmidt <Jens.Schmidt@oracle.com>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;; for his feedback and suggestions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 ;;; Code:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (eval-when-compile (require 'cl))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (require 'sgml-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (require 'custom)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 ;; Variables
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (defgroup xml-lite nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 "Customizable variables for XML-Lite mode."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 :group 'languages
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (defcustom xml-lite-indent-offset 4
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 "*Specifies the default indentation level for `xml-lite-indent-line'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 :type 'integer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 :group 'xml-lite
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 (defcustom xml-lite-indent-comment-offset 5
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 "*Specifies the indentation level for XML comments."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 :type 'integer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 :group 'xml-lite
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 (defcustom xml-lite-electric-slash 'close
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 "*If non-nil, inserting a '/' after a '<' behaves electrically.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 If set to `indent', typing '</' just triggers reindentation.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 If set to `close', typing '</' inserts an end-tag for the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 enclosing XML element."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 :type '(choice (const :tag "Indent" indent)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 (const :tag "Close" close)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (const :tag "No" nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 :group 'xml-lite
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 )
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 (defcustom xml-lite-mode-line-string " XML"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 "*String to display in the modeline when `xml-lite-mode' is active.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 Set this to nil if you don't want a modeline indicator for xml-lite-mode."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 :type 'string
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 :group 'xml-lite)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 (defcustom xml-lite-mode-hook nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 "*Hook called by `xml-lite-mode'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 :type 'hook
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 :group 'xml-lite)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (defvar xml-lite-mode nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 "Non-nil if `xml-lite-mode' is enabled.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 (make-variable-buffer-local 'xml-lite-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 ;; Parsing
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (defstruct (xml-lite-tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 (:constructor xml-lite-make-tag (type start end name name-end)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 type start end name name-end)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 (defsubst xml-lite-parse-tag-name ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 "Skip past a tag-name, and return the name."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 (let ((here (point)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 (if (> (skip-chars-forward "-._:A-Za-z0-9") 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (buffer-substring-no-properties here (point)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 (defun xml-lite-parse-tag-backward ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 "Get information about the parent tag."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 (let ((limit (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 (tag-type 'open)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (tag-start (search-backward "<" nil t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 tag-end name name-end)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 (if (not tag-start) nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 (setq tag-end (search-forward ">" limit t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 ;; determine tag type
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 (goto-char (1+ tag-start))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 ((= ?? (char-after)) ; processing-instruction
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 (setq tag-type 'pi))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 ((= ?! (char-after)) ; declaration
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 (setq tag-type 'decl)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 ((looking-at "!--") ; comment
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 (setq tag-type 'comment
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 tag-end (search-forward "-->" nil t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 ((looking-at "!\\[CDATA\\[") ; cdata
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 (setq tag-type 'cdata
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139 tag-end (search-forward "]]>" nil t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 (ignore-errors
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 (goto-char tag-start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 (forward-sexp 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 (setq tag-end (point))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 ((= ?% (char-after)) ; JSP tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 (setq tag-type 'jsp
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 tag-end (search-forward "%>" nil t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 ((= ?/ (char-after)) ; close-tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 (goto-char (+ 2 tag-start))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152 (setq tag-type 'close
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 name (xml-lite-parse-tag-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 name-end (point)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 (setq tag-type 'open
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 name (xml-lite-parse-tag-name)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 name-end (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 ;; check whether it's an empty tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 (if (and tag-end (eq ?/ (char-before (- tag-end 1))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 (setq tag-type 'empty))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 (goto-char tag-start)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 (xml-lite-make-tag tag-type tag-start tag-end name name-end))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 (defsubst xml-lite-at-indentation-p ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 "Return true if point is at the first non-whitespace character on the line."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 (skip-chars-backward " \t")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 (bolp)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 (defsubst xml-lite-inside-tag-p (tag-info &optional point)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 "Return true if TAG-INFO contains the POINT."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 (let ((end (xml-lite-tag-end tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176 (point (or point (point))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 (or (null end)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 (> end point))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 (defun xml-lite-get-context (&optional full)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 "Determine the context of the current position.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 If FULL is non-nil, parse back to the beginning of the buffer, otherwise
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 parse until we find a start-tag as the first thing on a line.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 The context is a list of tag-info structures. The last one is the tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 immediately enclosing the current position."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 (let ((here (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (level 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 tag-info context)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 (while
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 (and (or (not context)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 full
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 (not (xml-lite-at-indentation-p)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 (setq tag-info (xml-lite-parse-tag-backward)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 ;; inside a tag ...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 ((xml-lite-inside-tag-p tag-info here)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 (setq context (cons tag-info context)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
203
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
204 ;; start-tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 ((eq (xml-lite-tag-type tag-info) 'open)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 (setq level (1- level))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 (when (= level -1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 (setq context (cons tag-info context))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209 (setq level 0)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
210
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 ;; end-tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 ((eq (xml-lite-tag-type tag-info) 'close)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 (setq level (1+ level)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
215 )))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 ;; return context
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 context
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
221 (defun xml-lite-show-context (&optional full)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
222 "Display the current context.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
223 If FULL is non-nil, parse back to the beginning of the buffer."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
224 (interactive "P")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 (with-output-to-temp-buffer "*XML Context*"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 (pp (xml-lite-get-context full))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
229 ;; Indenting
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
230
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
231 (defun xml-lite-calculate-indent ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
232 "Calculate the column to which this line should be indented."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 (let* ((here (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 (context (xml-lite-get-context))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 (ref-tag-info (car context))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 (last-tag-info (car (last context))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
237
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
238 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
239 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
240
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
241 ;; no context
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
242 ((null context)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
243 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
244
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
245 ;; inside a comment
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
246 ((eq 'comment (xml-lite-tag-type last-tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
247 (goto-char (xml-lite-tag-start last-tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
248 (+ (current-column) xml-lite-indent-comment-offset))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
249
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
250 ;; inside a tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
251 ((xml-lite-inside-tag-p last-tag-info here)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
252 (let ((syntax-info
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
253 (parse-partial-sexp (xml-lite-tag-start last-tag-info)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
254 (point))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
255 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
256 ;; inside a string
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
257 ((nth 3 syntax-info)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
258 (goto-char (nth 8 syntax-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
259 (1+ (current-column)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
260 ;; if we have a tag-name, base indent on that
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
261 ((and (xml-lite-tag-name-end last-tag-info)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
262 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
263 (goto-char (xml-lite-tag-name-end last-tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
264 (not (looking-at "[ \t]*$"))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
265 (1+ (current-column)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
266 ;; otherwise, add indent-offset
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
267 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
268 (goto-char (xml-lite-tag-start last-tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
269 (+ (current-column) xml-lite-indent-offset)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
270
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
271 ;; inside an element
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
272 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
273 ;; indent to start of tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
274 (let ((here (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
275 indent-col)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276 (goto-char (xml-lite-tag-start ref-tag-info))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
277 (setq indent-col (current-column))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
278 (goto-char here)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
279 ;; add xml-lite-indent-offset, unless we're looking at the matching
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
280 ;; end-tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
281 (unless (and (eq (length context) 1) (looking-at "</"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
282 (setq indent-col (+ indent-col xml-lite-indent-offset)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
283 indent-col))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
285 ))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
287 (defun xml-lite-indent-line ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
288 "Indent the current line as XML."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
289 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290 (let ((origin-point (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
291 bol-point indent-point
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 indent-col)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294 ;; save beginning of line
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
295 (beginning-of-line)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 (setq bol-point (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
297 ;; save current indent
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 (skip-chars-forward " \t")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 (setq indent-point (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
300
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301 ;; calculate basic indent
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 (setq indent-col (xml-lite-calculate-indent))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
303
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 (unless (eq (current-column) indent-col)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 ;; re-indent, adjusting origin point for indentation change
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
306 (delete-region bol-point (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
307 (indent-to indent-col)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 (setq origin-point (+ origin-point (- (point) indent-point))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
310 (if (> origin-point (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
311 (goto-char origin-point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
312
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
313 ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
314
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
315
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
316 ;; Editing shortcuts
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
317
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
318 (defun xml-lite-insert-end-tag ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
319 "Insert an end-tag for the current element."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
320 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
321 (let* ((context (xml-lite-get-context))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
322 (tag-info (car (last context)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
323 (type (and tag-info (xml-lite-tag-type tag-info))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
324
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
325 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 ((null context)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 (error "Nothing to close"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
329
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 ;; inside a tag
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
331 ((xml-lite-inside-tag-p tag-info)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
332 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
333 ((eq type 'open) (insert " />"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
334 ((eq type 'comment) (insert " -->"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
335 ((eq type 'cdata) (insert "]]>"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 ((eq type 'jsp) (insert "%>"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
337 ((eq type 'pi) (insert "?>"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
338 (t (insert ">"))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
339
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 ;; inside an element
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
341 ((eq type 'open)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
342 (insert "</" (xml-lite-tag-name tag-info) ">")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
343 (xml-lite-indent-line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
344
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
345 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
346 (error "Nothing to close")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
347
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
348 (defun xml-lite-slash (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
349 "Insert ARG slash characters.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
350 Behaves electrically if `xml-lite-electric-slash' is non-nil."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
351 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
352 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
353 ((not (and (eq (char-before) ?<) (= arg 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
354 (insert-char ?/ arg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
355 ((eq xml-lite-electric-slash 'indent)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
356 (insert-char ?/ 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
357 (xml-lite-indent-line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
358 ((eq xml-lite-electric-slash 'close)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
359 (delete-backward-char 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
360 (xml-lite-insert-end-tag))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
361 (t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
362 (insert-char ?/ arg))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
363
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
364
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
365 ;; Movement commands
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
366
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
367 (defun forward-xml-tag (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
368 "Move forward ARG XML-tags."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
369 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
370 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
371 ((> arg 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
372 (search-forward ">" nil nil arg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
373 ((< arg 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
374 (search-backward "<" nil nil (- arg)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 ))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
376
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
377 (defun backward-xml-tag (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
378 "Move backward ARG XML-tags."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
379 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
380 (forward-xml-tag (- arg)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
381
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
382 (defun beginning-of-xml-tag ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
383 "Move to the beginning of the current XML-tag."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
384 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
385 (if (= ?< (char-after (point)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
386 (point)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
387 (search-backward "<")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
388
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
389 (defun end-of-xml-tag ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
390 "Move to the end of the current XML-tag."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
391 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
392 (forward-xml-tag 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
393
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
394
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
395 ;; Keymap
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
396
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
397 (defvar xml-lite-mode-map
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
398 (let ((map (make-sparse-keymap)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
399 (define-key map "\t" 'indent-for-tab-command)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
400 (define-key map "\C-c/" 'xml-lite-insert-end-tag)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
401 (define-key map "\C-c\C-s" 'xml-lite-show-context)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
402 (define-key map "/" 'xml-lite-slash)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
403 map)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
404 "Key bindings for `xml-lite-mode'.")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
405
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
406
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
407 ;; Minor mode
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
408
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
409 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
410 (define-minor-mode xml-lite-mode
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
411 "Toggle `xml-lite-mode'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
412 With ARG, enable xml-lite-mode if and only if ARG is positive.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
413
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
414 xml-lite-mode provides indentation for XML tags. The value of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
415 `xml-lite-indent-offset' determines the amount of indentation.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
416
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
417 Key bindings:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
418 \\{xml-lite-mode-map}"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
419 nil ; initial value
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
420 " XML" ; mode indicator
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
421 'xml-lite-mode-map ; keymap
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
422 (if xml-lite-mode
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
423 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
424 (if (eq major-mode 'fundamental-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
425 (sgml-mode))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
426 (make-local-variable 'indent-line-function)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
427 (setq xml-lite-mode t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
428 xml-lite-orig-indent-line-function indent-line-function
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
429 indent-line-function 'xml-lite-indent-line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
430 (setq indent-line-function xml-lite-orig-indent-line-function))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
431 (force-mode-line-update))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
432
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
433 (provide 'xml-lite)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
434
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
435 ;;; xml-lite.el ends here
|