aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2004-11-10 14:39:40 +0000
committerStefan Monnier2004-11-10 14:39:40 +0000
commite9146d5accb44e7c00a350a95492b3db6f1ee980 (patch)
treec0cdf482cc868c1cfabb2ea7a51bfecbfec12738 /lisp
parent86523fac0bb1cb56517780dd6289a92fa608c65d (diff)
downloademacs-e9146d5accb44e7c00a350a95492b3db6f1ee980.tar.gz
emacs-e9146d5accb44e7c00a350a95492b3db6f1ee980.zip
(sgml-tag-text-p): New fun.
(sgml-parse-tag-backward): Use it to skip spurious < or >.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog15
-rw-r--r--lisp/textmodes/sgml-mode.el117
2 files changed, 83 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 00f7d381254..c6587f7d5ea 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12004-11-10 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * textmodes/sgml-mode.el (sgml-tag-text-p): New fun.
4 (sgml-parse-tag-backward): Use it to skip spurious < or >.
5
12004-11-10 Thien-Thi Nguyen <ttn@gnu.org> 62004-11-10 Thien-Thi Nguyen <ttn@gnu.org>
2 7
3 * ebuff-menu.el: Doc fixes throughout. 8 * ebuff-menu.el: Doc fixes throughout.
@@ -15,6 +20,10 @@
15 20
16 * files.el (auto-mode-alist, magic-mode-alist): Use it. 21 * files.el (auto-mode-alist, magic-mode-alist): Use it.
17 22
232004-11-09 Stefan Monnier <monnier@iro.umontreal.ca>
24
25 * international/iso-cvt.el (iso-cvt-define-menu): Clean up namespace.
26
182004-11-09 Jay Belanger <belanger@truman.edu> 272004-11-09 Jay Belanger <belanger@truman.edu>
19 28
20 * calc/calc-ext.el (calc-init-extensions): Remove old code. 29 * calc/calc-ext.el (calc-init-extensions): Remove old code.
@@ -37,8 +46,8 @@
37 * calc/calc-poly.el (math-expand-form): Use declared variable 46 * calc/calc-poly.el (math-expand-form): Use declared variable
38 math-mt-many. 47 math-mt-many.
39 48
40 * calc/calc-rewr.el (math-rewrite, math-rewrite-phase): Use 49 * calc/calc-rewr.el (math-rewrite, math-rewrite-phase):
41 declared variable math-mt-many. 50 Use declared variable math-mt-many.
42 (math-rewrite): Use declared variable math-mt-func. 51 (math-rewrite): Use declared variable math-mt-func.
43 52
44 * calc/calc-vec.el (math-read-brackets, math-read-vector) 53 * calc/calc-vec.el (math-read-brackets, math-read-vector)
@@ -104,8 +113,6 @@
104 113
1052004-11-08 Stefan Monnier <monnier@iro.umontreal.ca> 1142004-11-08 Stefan Monnier <monnier@iro.umontreal.ca>
106 115
107 * international/mule.el: Fix some warnings.
108
109 * international/mule-cmds.el: Change coding-system to utf-8. 116 * international/mule-cmds.el: Change coding-system to utf-8.
110 (select-safe-coding-system-interactively): 117 (select-safe-coding-system-interactively):
111 New function extracted from select-safe-coding-system. 118 New function extracted from select-safe-coding-system.
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 4ac96b2e4b0..dd606a53434 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -1,6 +1,7 @@
1;;; sgml-mode.el --- SGML- and HTML-editing modes 1;;; sgml-mode.el --- SGML- and HTML-editing modes
2 2
3;; Copyright (C) 1992,95,96,98,2001,2002, 2003 Free Software Foundation, Inc. 3;; Copyright (C) 1992, 1995, 1996, 1998, 2001, 2002, 2003, 2004
4;; Free Software Foundation, Inc.
4 5
5;; Author: James Clark <jjc@jclark.com> 6;; Author: James Clark <jjc@jclark.com>
6;; Maintainer: FSF 7;; Maintainer: FSF
@@ -1053,53 +1054,79 @@ You might want to turn on `auto-fill-mode' to get better results."
1053 (and (>= start (point-min)) 1054 (and (>= start (point-min))
1054 (equal str (buffer-substring-no-properties start (point)))))) 1055 (equal str (buffer-substring-no-properties start (point))))))
1055 1056
1057(defun sgml-tag-text-p (start end)
1058 "Return non-nil if text between START and END is a tag.
1059Checks among other things that the tag does not contain spurious
1060unquoted < or > chars inside, which would indicate that it
1061really isn't a tag after all."
1062 (save-excursion
1063 (with-syntax-table sgml-tag-syntax-table
1064 (let ((pps (parse-partial-sexp start end 2)))
1065 (and (= (nth 0 pps) 0))))))
1066
1056(defun sgml-parse-tag-backward (&optional limit) 1067(defun sgml-parse-tag-backward (&optional limit)
1057 "Parse an SGML tag backward, and return information about the tag. 1068 "Parse an SGML tag backward, and return information about the tag.
1058Assume that parsing starts from within a textual context. 1069Assume that parsing starts from within a textual context.
1059Leave point at the beginning of the tag." 1070Leave point at the beginning of the tag."
1060 (let (tag-type tag-start tag-end name) 1071 (catch 'found
1061 (or (re-search-backward "[<>]" limit 'move) 1072 (let (tag-type tag-start tag-end name)
1062 (error "No tag found")) 1073 (or (re-search-backward "[<>]" limit 'move)
1063 (when (eq (char-after) ?<) 1074 (error "No tag found"))
1064 ;; Oops!! Looks like we were not in a textual context after all!. 1075 (when (eq (char-after) ?<)
1065 ;; Let's try to recover. 1076 ;; Oops!! Looks like we were not in a textual context after all!.
1066 (with-syntax-table sgml-tag-syntax-table 1077 ;; Let's try to recover.
1067 (forward-sexp) 1078 (with-syntax-table sgml-tag-syntax-table
1068 (forward-char -1))) 1079 (let ((pos (point)))
1069 (setq tag-end (1+ (point))) 1080 (condition-case nil
1070 (cond 1081 (forward-sexp)
1071 ((sgml-looking-back-at "--") ; comment 1082 (scan-error
1072 (setq tag-type 'comment 1083 ;; This < seems to be just a spurious one, let's ignore it.
1073 tag-start (search-backward "<!--" nil t))) 1084 (goto-char pos)
1074 ((sgml-looking-back-at "]]") ; cdata 1085 (throw 'found (sgml-parse-tag-backward limit))))
1075 (setq tag-type 'cdata 1086 ;; Check it is really a tag, without any extra < or > inside.
1076 tag-start (re-search-backward "<!\\[[A-Z]+\\[" nil t))) 1087 (unless (sgml-tag-text-p pos (point))
1077 (t 1088 (goto-char pos)
1078 (setq tag-start 1089 (throw 'found (sgml-parse-tag-backward limit)))
1079 (with-syntax-table sgml-tag-syntax-table 1090 (forward-char -1))))
1080 (goto-char tag-end) 1091 (setq tag-end (1+ (point)))
1081 (backward-sexp) 1092 (cond
1082 (point))) 1093 ((sgml-looking-back-at "--") ; comment
1083 (goto-char (1+ tag-start)) 1094 (setq tag-type 'comment
1084 (case (char-after) 1095 tag-start (search-backward "<!--" nil t)))
1085 (?! ; declaration 1096 ((sgml-looking-back-at "]]") ; cdata
1086 (setq tag-type 'decl)) 1097 (setq tag-type 'cdata
1087 (?? ; processing-instruction 1098 tag-start (re-search-backward "<!\\[[A-Z]+\\[" nil t)))
1088 (setq tag-type 'pi)) 1099 (t
1089 (?/ ; close-tag 1100 (setq tag-start
1090 (forward-char 1) 1101 (with-syntax-table sgml-tag-syntax-table
1091 (setq tag-type 'close 1102 (goto-char tag-end)
1092 name (sgml-parse-tag-name))) 1103 (condition-case nil
1093 (?% ; JSP tags 1104 (backward-sexp)
1094 (setq tag-type 'jsp)) 1105 (scan-error
1095 (t ; open or empty tag 1106 ;; This > isn't really the end of a tag. Skip it.
1096 (setq tag-type 'open 1107 (goto-char (1- tag-end))
1097 name (sgml-parse-tag-name)) 1108 (throw 'found (sgml-parse-tag-backward limit))))
1098 (if (or (eq ?/ (char-before (- tag-end 1))) 1109 (point)))
1099 (sgml-empty-tag-p name)) 1110 (goto-char (1+ tag-start))
1100 (setq tag-type 'empty)))))) 1111 (case (char-after)
1101 (goto-char tag-start) 1112 (?! ; declaration
1102 (sgml-make-tag tag-type tag-start tag-end name))) 1113 (setq tag-type 'decl))
1114 (?? ; processing-instruction
1115 (setq tag-type 'pi))
1116 (?/ ; close-tag
1117 (forward-char 1)
1118 (setq tag-type 'close
1119 name (sgml-parse-tag-name)))
1120 (?% ; JSP tags
1121 (setq tag-type 'jsp))
1122 (t ; open or empty tag
1123 (setq tag-type 'open
1124 name (sgml-parse-tag-name))
1125 (if (or (eq ?/ (char-before (- tag-end 1)))
1126 (sgml-empty-tag-p name))
1127 (setq tag-type 'empty))))))
1128 (goto-char tag-start)
1129 (sgml-make-tag tag-type tag-start tag-end name))))
1103 1130
1104(defun sgml-get-context (&optional until) 1131(defun sgml-get-context (&optional until)
1105 "Determine the context of the current position. 1132 "Determine the context of the current position.
@@ -1966,5 +1993,5 @@ Can be used as a value for `html-mode-hook'."
1966 1993
1967(provide 'sgml-mode) 1994(provide 'sgml-mode)
1968 1995
1969;;; arch-tag: 9675da94-b7f9-4bda-ad19-73ed7b4fb401 1996;; arch-tag: 9675da94-b7f9-4bda-ad19-73ed7b4fb401
1970;;; sgml-mode.el ends here 1997;;; sgml-mode.el ends here