aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2007-05-08 06:57:38 +0000
committerStefan Monnier2007-05-08 06:57:38 +0000
commit121f19217db03e3c1b807c68ab5a17c773303dee (patch)
treefd9cc8bc768b2d2ccdc5097d8e5f3dd4252bf88f
parent45fd3a00715e631c6ce2632e3241b7f0d9724f0a (diff)
downloademacs-121f19217db03e3c1b807c68ab5a17c773303dee.tar.gz
emacs-121f19217db03e3c1b807c68ab5a17c773303dee.zip
(sgml-lexical-context): Add handling of XML style Processing Instructions.
(sgml-parse-tag-backward): Handle XML-style PIs. Also ensure progress. (sgml-calculate-indent): Handle `pi' context.
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/textmodes/sgml-mode.el63
2 files changed, 48 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d51f6875343..88448bc6b45 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,10 @@
12007-05-08 Stefan Monnier <monnier@iro.umontreal.ca> 12007-05-08 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * textmodes/sgml-mode.el (sgml-lexical-context): Add handling of
4 XML style Processing Instructions.
5 (sgml-parse-tag-backward): Handle XML-style PIs. Also ensure progress.
6 (sgml-calculate-indent): Handle `pi' context.
7
3 * vc.el: Ensure that update-changelog issues an error when used with 8 * vc.el: Ensure that update-changelog issues an error when used with
4 a backend that does not implement it. 9 a backend that does not implement it.
5 (vc-update-changelog-rcs2log): Rename from vc-default-update-changelog. 10 (vc-update-changelog-rcs2log): Rename from vc-default-update-changelog.
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 5e599ea10e6..0bd2d0b7e4e 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -937,7 +937,7 @@ and move to the line in the SGML document that caused it."
937(defun sgml-lexical-context (&optional limit) 937(defun sgml-lexical-context (&optional limit)
938 "Return the lexical context at point as (TYPE . START). 938 "Return the lexical context at point as (TYPE . START).
939START is the location of the start of the lexical element. 939START is the location of the start of the lexical element.
940TYPE is one of `string', `comment', `tag', `cdata', or `text'. 940TYPE is one of `string', `comment', `tag', `cdata', `pi', or `text'.
941 941
942Optional argument LIMIT is the position to start parsing from. 942Optional argument LIMIT is the position to start parsing from.
943If nil, start from a preceding tag at indentation." 943If nil, start from a preceding tag at indentation."
@@ -964,12 +964,19 @@ If nil, start from a preceding tag at indentation."
964 (let ((cdata-start (point))) 964 (let ((cdata-start (point)))
965 (unless (search-forward "]]>" pos 'move) 965 (unless (search-forward "]]>" pos 'move)
966 (list 0 nil nil 'cdata nil nil nil nil cdata-start)))) 966 (list 0 nil nil 'cdata nil nil nil nil cdata-start))))
967 ((and sgml-xml-mode (looking-at "<\\?"))
968 ;; Processing Instructions.
969 ;; In SGML, it's basically a normal tag of the form
970 ;; <?NAME ...> but in XML, it takes the form <? ... ?>.
971 (let ((pi-start (point)))
972 (unless (search-forward "?>" pos 'move)
973 (list 0 nil nil 'pi nil nil nil nil pi-start))))
967 (t 974 (t
968 ;; We've reached a tag. Parse it. 975 ;; We've reached a tag. Parse it.
969 ;; FIXME: Handle net-enabling start-tags 976 ;; FIXME: Handle net-enabling start-tags
970 (parse-partial-sexp (point) pos 0)))))) 977 (parse-partial-sexp (point) pos 0))))))
971 (cond 978 (cond
972 ((eq (nth 3 state) 'cdata) (cons 'cdata (nth 8 state))) 979 ((memq (nth 3 state) '(cdata pi)) (cons (nth 3 state) (nth 8 state)))
973 ((nth 3 state) (cons 'string (nth 8 state))) 980 ((nth 3 state) (cons 'string (nth 8 state)))
974 ((nth 4 state) (cons 'comment (nth 8 state))) 981 ((nth 4 state) (cons 'comment (nth 8 state)))
975 ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state))) 982 ((and state (> (nth 0 state) 0)) (cons 'tag (nth 1 state)))
@@ -1093,9 +1100,15 @@ Leave point at the beginning of the tag."
1093 (when (eq (char-after) ?<) 1100 (when (eq (char-after) ?<)
1094 ;; Oops!! Looks like we were not in a textual context after all!. 1101 ;; Oops!! Looks like we were not in a textual context after all!.
1095 ;; Let's try to recover. 1102 ;; Let's try to recover.
1103 ;; Remember the tag-start so we don't need to look for it later.
1104 ;; This is not just an optimization but also makes sure we don't get
1105 ;; stuck in infloops in cases where "looking back for <" would not go
1106 ;; back far enough.
1107 (setq tag-start (point))
1096 (with-syntax-table sgml-tag-syntax-table 1108 (with-syntax-table sgml-tag-syntax-table
1097 (let ((pos (point))) 1109 (let ((pos (point)))
1098 (condition-case nil 1110 (condition-case nil
1111 ;; FIXME: This does not correctly skip over PI an CDATA tags.
1099 (forward-sexp) 1112 (forward-sexp)
1100 (scan-error 1113 (scan-error
1101 ;; This < seems to be just a spurious one, let's ignore it. 1114 ;; This < seems to be just a spurious one, let's ignore it.
@@ -1110,33 +1123,41 @@ Leave point at the beginning of the tag."
1110 (cond 1123 (cond
1111 ((sgml-looking-back-at "--") ; comment 1124 ((sgml-looking-back-at "--") ; comment
1112 (setq tag-type 'comment 1125 (setq tag-type 'comment
1113 tag-start (search-backward "<!--" nil t))) 1126 tag-start (or tag-start (search-backward "<!--" nil t))))
1114 ((sgml-looking-back-at "]]") ; cdata 1127 ((sgml-looking-back-at "]]") ; cdata
1115 (setq tag-type 'cdata 1128 (setq tag-type 'cdata
1116 tag-start (re-search-backward "<!\\[[A-Z]+\\[" nil t))) 1129 tag-start (or tag-start
1130 (re-search-backward "<!\\[[A-Z]+\\[" nil t))))
1131 ((sgml-looking-back-at "?") ; XML processing-instruction
1132 (setq tag-type 'pi
1133 ;; IIUC: SGML processing instructions take the form <?foo ...>
1134 ;; i.e. a "normal" tag, handled below. In XML this is changed
1135 ;; to <?foo ... ?> where "..." can contain < and > and even <?
1136 ;; but not ?>. This means that when parsing backward, there's
1137 ;; no easy way to make sure that we find the real beginning of
1138 ;; the PI.
1139 tag-start (or tag-start (search-backward "<?" nil t))))
1117 (t 1140 (t
1118 (setq tag-start 1141 (unless tag-start
1119 (with-syntax-table sgml-tag-syntax-table 1142 (setq tag-start
1120 (goto-char tag-end) 1143 (with-syntax-table sgml-tag-syntax-table
1121 (condition-case nil 1144 (goto-char tag-end)
1122 (backward-sexp) 1145 (condition-case nil
1123 (scan-error 1146 (backward-sexp)
1124 ;; This > isn't really the end of a tag. Skip it. 1147 (scan-error
1125 (goto-char (1- tag-end)) 1148 ;; This > isn't really the end of a tag. Skip it.
1126 (throw 'found (sgml-parse-tag-backward limit)))) 1149 (goto-char (1- tag-end))
1127 (point))) 1150 (throw 'found (sgml-parse-tag-backward limit))))
1151 (point))))
1128 (goto-char (1+ tag-start)) 1152 (goto-char (1+ tag-start))
1129 (case (char-after) 1153 (case (char-after)
1130 (?! ; declaration 1154 (?! (setq tag-type 'decl)) ; declaration
1131 (setq tag-type 'decl)) 1155 (?? (setq tag-type 'pi)) ; processing-instruction
1132 (?? ; processing-instruction 1156 (?% (setq tag-type 'jsp)) ; JSP tags
1133 (setq tag-type 'pi))
1134 (?/ ; close-tag 1157 (?/ ; close-tag
1135 (forward-char 1) 1158 (forward-char 1)
1136 (setq tag-type 'close 1159 (setq tag-type 'close
1137 name (sgml-parse-tag-name))) 1160 name (sgml-parse-tag-name)))
1138 (?% ; JSP tags
1139 (setq tag-type 'jsp))
1140 (t ; open or empty tag 1161 (t ; open or empty tag
1141 (setq tag-type 'open 1162 (setq tag-type 'open
1142 name (sgml-parse-tag-name)) 1163 name (sgml-parse-tag-name))
@@ -1331,6 +1352,8 @@ LCON is the lexical context, if any."
1331 1352
1332 ;; We don't know how to indent it. Let's be honest about it. 1353 ;; We don't know how to indent it. Let's be honest about it.
1333 (cdata nil) 1354 (cdata nil)
1355 ;; We don't know how to indent it. Let's be honest about it.
1356 (pi nil)
1334 1357
1335 (tag 1358 (tag
1336 (goto-char (1+ (cdr lcon))) 1359 (goto-char (1+ (cdr lcon)))