Mercurial > emacs
annotate lisp/textmodes/xml-lite.el @ 44284:f259c3857fea
Remove redundant remains of xml-lite-mode.
author | Mike Williams <mdub@bigfoot.com> |
---|---|
date | Mon, 01 Apr 2002 11:00:33 +0000 |
parents | c3ee131a3ab1 |
children | 52b704431b5d |
rev | line source |
---|---|
43687 | 1 ;;; xml-lite.el --- an indentation-engine for XML |
2 | |
44187
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
3 ;; Copyright (C) 2002 Free Software Foundation, Inc. |
43687 | 4 |
5 ;; Author: Mike Williams <mdub@bigfoot.com> | |
6 ;; Created: February 2001 | |
7 ;; Keywords: xml | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; This program is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2 of the License, or | |
14 ;; (at your option) any later version. | |
15 ;; | |
16 ;; This program is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 ;; | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 ;; | |
28 ;; This package provides a simple indentation engine for XML. It is | |
29 ;; intended for use in situations where the full power of the popular PSGML | |
30 ;; package (DTD parsing, syntax checking) is not required. | |
31 ;; | |
32 ;; xml-lite is designed to be used in conjunction with the default GNU | |
33 ;; Emacs sgml-mode, to provide a lightweight XML-editing environment. | |
34 | |
35 ;;; Thanks: | |
36 ;; | |
37 ;; Jens Schmidt <Jens.Schmidt@oracle.com> | |
38 ;; for his feedback and suggestions | |
39 | |
40 ;;; Code: | |
41 | |
42 (eval-when-compile (require 'cl)) | |
43 (require 'sgml-mode) | |
44 | |
45 | |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
46 ;; Syntax analysis |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
47 |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
48 (defsubst xml-lite-at-indentation-p () |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
49 "Return true if point is at the first non-whitespace character on the line." |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
50 (save-excursion |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
51 (skip-chars-backward " \t") |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
52 (bolp))) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
53 |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
54 |
43687 | 55 ;; Parsing |
56 (defstruct (xml-lite-tag | |
57 (:constructor xml-lite-make-tag (type start end name name-end))) | |
58 type start end name name-end) | |
59 (defsubst xml-lite-parse-tag-name () | |
60 "Skip past a tag-name, and return the name." | |
44180
e7a365c909ff
Don't require `custom'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44168
diff
changeset
|
61 (buffer-substring-no-properties |
e7a365c909ff
Don't require `custom'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44168
diff
changeset
|
62 (point) (progn (skip-syntax-forward "w_") (point)))) |
43687 | 63 |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
64 (defsubst xml-lite-looking-back-at (s) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
65 (let ((limit (max (- (point) (length s)) (point-min)))) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
66 (equal s (buffer-substring-no-properties limit (point))))) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
67 |
44187
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
68 (defsubst xml-lite-looking-at (s) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
69 (let ((limit (min (+ (point) (length s))))) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
70 (equal s (buffer-substring-no-properties (point) limit)))) |
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
71 |
43687 | 72 (defun xml-lite-parse-tag-backward () |
73 "Get information about the parent tag." | |
74 (let ((limit (point)) | |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
75 tag-type tag-start tag-end name name-end) |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
76 (with-syntax-table sgml-tag-syntax-table |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
77 (cond |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
78 |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
79 ((null (re-search-backward "[<>]" nil t))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
80 |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
81 ((= ?> (char-after)) ;--- found tag-end --- |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
82 (setq tag-end (1+ (point))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
83 (goto-char tag-end) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
84 (cond |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
85 ((xml-lite-looking-back-at "--") ; comment |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
86 (setq tag-type 'comment |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
87 tag-start (search-backward "<!--" nil t))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
88 ((xml-lite-looking-back-at "]]>") ; cdata |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
89 (setq tag-type 'cdata |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
90 tag-start (search-backward "![CDATA[" nil t))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
91 (t |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
92 (setq tag-start (ignore-errors (backward-sexp) (point)))))) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
93 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
94 ((= ?< (char-after)) ;--- found tag-start --- |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
95 ;; !!! This should not happen because the caller should be careful |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
96 ;; that we do not start from within a tag !!! |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
97 (setq tag-start (point)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
98 (goto-char (1+ tag-start)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
99 (cond |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
100 ((xml-lite-looking-at "!--") ; comment |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
101 (setq tag-type 'comment |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
102 tag-end (search-forward "-->" nil t))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
103 ((xml-lite-looking-at "![CDATA[") ; cdata |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
104 (setq tag-type 'cdata |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
105 tag-end (search-forward "]]>" nil t))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
106 (t |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
107 (goto-char tag-start) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
108 (setq tag-end (ignore-errors (forward-sexp) (point))))))) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
109 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
110 (cond |
43687 | 111 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
112 ((or tag-type (null tag-start))) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
113 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
114 ((= ?! (char-after (1+ tag-start))) ; declaration |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
115 (setq tag-type 'decl)) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
116 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
117 ((= ?? (char-after (1+ tag-start))) ; processing-instruction |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
118 (setq tag-type 'pi)) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
119 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
120 ((= ?/ (char-after (1+ tag-start))) ; close-tag |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
121 (goto-char (+ 2 tag-start)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
122 (setq tag-type 'close |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
123 name (xml-lite-parse-tag-name) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
124 name-end (point))) |
43687 | 125 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
126 ((member ; JSP tags etc |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
127 (char-after (1+ tag-start)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
128 '(?% ?#)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
129 (setq tag-type 'unknown)) |
43687 | 130 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
131 (t |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
132 (goto-char (1+ tag-start)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
133 (setq tag-type 'open |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
134 name (xml-lite-parse-tag-name) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
135 name-end (point)) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
136 ;; check whether it's an empty tag |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
137 (if (or (and tag-end (eq ?/ (char-before (- tag-end 1)))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
138 (and (not sgml-xml-mode) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
139 (member-ignore-case name sgml-empty-tags))) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
140 (setq tag-type 'empty)))) |
43687 | 141 |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
142 (cond |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
143 (tag-start |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
144 (goto-char tag-start) |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
145 (xml-lite-make-tag tag-type tag-start tag-end name name-end)))))) |
43687 | 146 |
147 (defsubst xml-lite-inside-tag-p (tag-info &optional point) | |
148 "Return true if TAG-INFO contains the POINT." | |
149 (let ((end (xml-lite-tag-end tag-info)) | |
150 (point (or point (point)))) | |
151 (or (null end) | |
152 (> end point)))) | |
153 | |
154 (defun xml-lite-get-context (&optional full) | |
155 "Determine the context of the current position. | |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
156 If FULL is `empty', return even if the context is empty (i.e. |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
157 we just skipped over some element and got to a beginning of line). |
43687 | 158 If FULL is non-nil, parse back to the beginning of the buffer, otherwise |
159 parse until we find a start-tag as the first thing on a line. | |
160 | |
161 The context is a list of tag-info structures. The last one is the tag | |
162 immediately enclosing the current position." | |
163 (let ((here (point)) | |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
164 (ignore nil) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
165 (context nil) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
166 tag-info) |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
167 ;; CONTEXT keeps track of the tag-stack |
44201
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
168 ;; IGNORE keeps track of the nesting level of point relative to the |
2eeb8d7f1161
(xml-lite-in-string-p): Use sgml-lexical-context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44189
diff
changeset
|
169 ;; first (outermost) tag on the context. This is the list of |
44168
68fd324f9f0f
(xml-lite-at-indentation-p): Move.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43687
diff
changeset
|
170 ;; enclosing start-tags we'll have to ignore. |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
171 (skip-chars-backward " \t\n") ; Make sure we're not at indentation. |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
172 (while |
44284
f259c3857fea
Remove redundant remains of xml-lite-mode.
Mike Williams <mdub@bigfoot.com>
parents:
44243
diff
changeset
|
173 (and (or ignore |
f259c3857fea
Remove redundant remains of xml-lite-mode.
Mike Williams <mdub@bigfoot.com>
parents:
44243
diff
changeset
|
174 (not (if full (eq full 'empty) context)) |
44243
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
175 (not (xml-lite-at-indentation-p)) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
176 (and (not sgml-xml-mode) context |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
177 (/= (point) (xml-lite-tag-start (car context))) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
178 (member-ignore-case (xml-lite-tag-name (car context)) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
179 sgml-unclosed-tags))) |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
180 (setq tag-info (xml-lite-parse-tag-backward))) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
181 |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
182 ;; This tag may enclose things we thought were tags. If so, |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
183 ;; discard them. |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
184 (while (and context |
44284
f259c3857fea
Remove redundant remains of xml-lite-mode.
Mike Williams <mdub@bigfoot.com>
parents:
44243
diff
changeset
|
185 (> (xml-lite-tag-end tag-info) |
f259c3857fea
Remove redundant remains of xml-lite-mode.
Mike Williams <mdub@bigfoot.com>
parents:
44243
diff
changeset
|
186 (xml-lite-tag-end (car context)))) |
f259c3857fea
Remove redundant remains of xml-lite-mode.
Mike Williams <mdub@bigfoot.com>
parents:
44243
diff
changeset
|
187 (setq context (cdr context))) |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
188 |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
189 (cond |
43687 | 190 |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
191 ;; inside a tag ... |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
192 ((xml-lite-inside-tag-p tag-info here) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
193 (push tag-info context)) |
43687 | 194 |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
195 ;; start-tag |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
196 ((eq (xml-lite-tag-type tag-info) 'open) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
197 (cond |
44243
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
198 ((null ignore) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
199 (if (and (not sgml-xml-mode) context |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
200 (member-ignore-case (xml-lite-tag-name tag-info) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
201 sgml-unclosed-tags) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
202 (eq t (compare-strings |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
203 (xml-lite-tag-name tag-info) nil nil |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
204 (xml-lite-tag-name (car context)) nil nil t))) |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
205 ;; There was an implicit end-tag. |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
206 nil |
c3ee131a3ab1
(xml-lite-get-context): Don't stop parsing
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44242
diff
changeset
|
207 (push tag-info context))) |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
208 ((eq t (compare-strings (xml-lite-tag-name tag-info) nil nil |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
209 (car ignore) nil nil t)) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
210 (setq ignore (cdr ignore))) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
211 (t |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
212 ;; The open and close tags don't match. |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
213 (if (not sgml-xml-mode) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
214 ;; Assume the open tag is simply not closed. |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
215 (unless (member-ignore-case (xml-lite-tag-name tag-info) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
216 sgml-unclosed-tags) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
217 (message "Unclosed tag <%s>" (xml-lite-tag-name tag-info))) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
218 (message "Unmatched tags <%s> and </%s>" |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
219 (xml-lite-tag-name tag-info) (pop ignore)))))) |
43687 | 220 |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
221 ;; end-tag |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
222 ((eq (xml-lite-tag-type tag-info) 'close) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
223 (if (and (not sgml-xml-mode) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
224 (member-ignore-case (xml-lite-tag-name tag-info) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
225 sgml-empty-tags)) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
226 (message "Spurious </%s>: empty tag" (xml-lite-tag-name tag-info)) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
227 (push (xml-lite-tag-name tag-info) ignore))) |
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
228 )) |
43687 | 229 |
230 ;; return context | |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
231 context)) |
43687 | 232 |
233 (defun xml-lite-show-context (&optional full) | |
234 "Display the current context. | |
235 If FULL is non-nil, parse back to the beginning of the buffer." | |
236 (interactive "P") | |
237 (with-output-to-temp-buffer "*XML Context*" | |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
238 (pp (save-excursion (xml-lite-get-context full))))) |
43687 | 239 |
240 | |
241 ;; Editing shortcuts | |
242 | |
243 (defun xml-lite-insert-end-tag () | |
244 "Insert an end-tag for the current element." | |
245 (interactive) | |
44242
84ff52bf6d2f
(xml-lite-get-context): Allow stopping even with an empty context.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44201
diff
changeset
|
246 (let* ((context (save-excursion (xml-lite-get-context))) |
43687 | 247 (tag-info (car (last context))) |
248 (type (and tag-info (xml-lite-tag-type tag-info)))) | |
249 | |
250 (cond | |
251 | |
252 ((null context) | |
253 (error "Nothing to close")) | |
254 | |
255 ;; inside a tag | |
256 ((xml-lite-inside-tag-p tag-info) | |
44187
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
257 (insert (cond |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
258 ((eq type 'open) " />") |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
259 ((eq type 'comment) " -->") |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
260 ((eq type 'cdata) "]]>") |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
261 ((eq type 'jsp) "%>") |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
262 ((eq type 'pi) "?>") |
65437de0940f
Fix copyright notice.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44180
diff
changeset
|
263 (t ">")))) |
43687 | 264 |
265 ;; inside an element | |
266 ((eq type 'open) | |
267 (insert "</" (xml-lite-tag-name tag-info) ">") | |
44180
e7a365c909ff
Don't require `custom'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44168
diff
changeset
|
268 (indent-according-to-mode)) |
43687 | 269 |
270 (t | |
271 (error "Nothing to close"))))) | |
272 | |
273 (defun xml-lite-slash (arg) | |
274 "Insert ARG slash characters. | |
275 Behaves electrically if `xml-lite-electric-slash' is non-nil." | |
276 (interactive "p") | |
277 (cond | |
278 ((not (and (eq (char-before) ?<) (= arg 1))) | |
279 (insert-char ?/ arg)) | |
280 ((eq xml-lite-electric-slash 'indent) | |
281 (insert-char ?/ 1) | |
44180
e7a365c909ff
Don't require `custom'.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44168
diff
changeset
|
282 (indent-according-to-mode)) |
43687 | 283 ((eq xml-lite-electric-slash 'close) |
284 (delete-backward-char 1) | |
285 (xml-lite-insert-end-tag)) | |
286 (t | |
287 (insert-char ?/ arg)))) | |
288 | |
289 (provide 'xml-lite) | |
290 | |
291 ;;; xml-lite.el ends here |