[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master d392b6e 09/12: change sgml-mode to help multi-html
From: |
Tom Tromey |
Subject: |
[Emacs-diffs] master d392b6e 09/12: change sgml-mode to help multi-html mode |
Date: |
Wed, 5 Apr 2017 18:17:30 -0400 (EDT) |
branch: master
commit d392b6e82460d94b11627998da87e33880664060
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>
change sgml-mode to help multi-html mode
* lisp/textmodes/sgml-mode.el (sgml-syntax-propertize-rules): New
defconst.
(sgml-syntax-propertize): Use it.
(sgml--find-<>-backward): New function.
(sgml-parse-tag-backward): Use it.
---
lisp/textmodes/sgml-mode.el | 47 ++++++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 97a1144..a6965fa 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -341,26 +341,30 @@ Any terminating `>' or `/' is not matched.")
(defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
"Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
+(eval-and-compile
+ (defconst sgml-syntax-propertize-rules
+ (syntax-propertize-precompile-rules
+ ;; Use the `b' style of comments to avoid interference with the -- ... --
+ ;; comments recognized when `sgml-specials' includes ?-.
+ ;; FIXME: beware of <!--> blabla <!--> !!
+ ("\\(<\\)!--" (1 "< b"))
+ ("--[ \t\n]*\\(>\\)" (1 "> b"))
+ ("\\(<\\)[?!]" (1 (prog1 "|>"
+ (sgml-syntax-propertize-inside end))))
+ ;; Double quotes outside of tags should not introduce strings.
+ ;; Be careful to call `syntax-ppss' on a position before the one we're
+ ;; going to change, so as not to need to flush the data we just computed.
+ ("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
+ (goto-char (match-end 0)))
+ (string-to-syntax ".")))))))
+
(defun sgml-syntax-propertize (start end)
"Syntactic keywords for `sgml-mode'."
(goto-char start)
(sgml-syntax-propertize-inside end)
(funcall
- (syntax-propertize-rules
- ;; Use the `b' style of comments to avoid interference with the -- ... --
- ;; comments recognized when `sgml-specials' includes ?-.
- ;; FIXME: beware of <!--> blabla <!--> !!
- ("\\(<\\)!--" (1 "< b"))
- ("--[ \t\n]*\\(>\\)" (1 "> b"))
- ("\\(<\\)[?!]" (1 (prog1 "|>"
- (sgml-syntax-propertize-inside end))))
- ;; Double quotes outside of tags should not introduce strings.
- ;; Be careful to call `syntax-ppss' on a position before the one we're
- ;; going to change, so as not to need to flush the data we just computed.
- ("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
- (goto-char (match-end 0)))
- (string-to-syntax ".")))))
- start end))
+ (syntax-propertize-rules sgml-syntax-propertize-rules)
+ start end))
(defun sgml-syntax-propertize-inside (end)
(let ((ppss (syntax-ppss)))
@@ -1304,13 +1308,24 @@ really isn't a tag after all."
(let ((pps (parse-partial-sexp start end 2)))
(and (= (nth 0 pps) 0))))))
+(defun sgml--find-<>-backward (limit)
+ "Search backward for a '<' or '>' character.
+The character must have open or close syntax.
+Returns t if found, nil otherwise."
+ (catch 'found
+ (while (re-search-backward "[<>]" limit 'move)
+ ;; If this character has "open" or "close" syntax, then we've
+ ;; found the one we want.
+ (when (memq (syntax-class (syntax-after (point))) '(4 5))
+ (throw 'found t)))))
+
(defun sgml-parse-tag-backward (&optional limit)
"Parse an SGML tag backward, and return information about the tag.
Assume that parsing starts from within a textual context.
Leave point at the beginning of the tag."
(catch 'found
(let (tag-type tag-start tag-end name)
- (or (re-search-backward "[<>]" limit 'move)
+ (or (sgml--find-<>-backward limit)
(error "No tag found"))
(when (eq (char-after) ?<)
;; Oops!! Looks like we were not in a textual context after all!.
- [Emacs-diffs] master updated (0074ed5 -> 04a5ce0), Tom Tromey, 2017/04/05
- [Emacs-diffs] master a2a3879 01/12: change auto-insert to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master c92bae9 04/12: change org to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master d056b1f 03/12: change semantic to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 089b159 02/12: change calc to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 5331ef8 08/12: make js.el respect prog-first-column, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 14659f6 06/12: change viper to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 95aba61 05/12: change align to use derived-mode-p, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 473a420 07/12: make smie.el respect prog-first-column, Tom Tromey, 2017/04/05
- [Emacs-diffs] master d392b6e 09/12: change sgml-mode to help multi-html mode,
Tom Tromey <=
- [Emacs-diffs] master 04a5ce0 12/12: add two more mhtml tests, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 335174e 10/12: add mhtml-mode.el, Tom Tromey, 2017/04/05
- [Emacs-diffs] master 59409f4 11/12: enable mhtml-mode by default, Tom Tromey, 2017/04/05