Skip to content

Commit d392b6e

Browse files
committed
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.
1 parent 5331ef8 commit d392b6e

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

lisp/textmodes/sgml-mode.el

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,30 @@ Any terminating `>' or `/' is not matched.")
341341
(defvar sgml-font-lock-keywords sgml-font-lock-keywords-1
342342
"Rules for highlighting SGML code. See also `sgml-tag-face-alist'.")
343343

344+
(eval-and-compile
345+
(defconst sgml-syntax-propertize-rules
346+
(syntax-propertize-precompile-rules
347+
;; Use the `b' style of comments to avoid interference with the -- ... --
348+
;; comments recognized when `sgml-specials' includes ?-.
349+
;; FIXME: beware of <!--> blabla <!--> !!
350+
("\\(<\\)!--" (1 "< b"))
351+
("--[ \t\n]*\\(>\\)" (1 "> b"))
352+
("\\(<\\)[?!]" (1 (prog1 "|>"
353+
(sgml-syntax-propertize-inside end))))
354+
;; Double quotes outside of tags should not introduce strings.
355+
;; Be careful to call `syntax-ppss' on a position before the one we're
356+
;; going to change, so as not to need to flush the data we just computed.
357+
("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
358+
(goto-char (match-end 0)))
359+
(string-to-syntax ".")))))))
360+
344361
(defun sgml-syntax-propertize (start end)
345362
"Syntactic keywords for `sgml-mode'."
346363
(goto-char start)
347364
(sgml-syntax-propertize-inside end)
348365
(funcall
349-
(syntax-propertize-rules
350-
;; Use the `b' style of comments to avoid interference with the -- ... --
351-
;; comments recognized when `sgml-specials' includes ?-.
352-
;; FIXME: beware of <!--> blabla <!--> !!
353-
("\\(<\\)!--" (1 "< b"))
354-
("--[ \t\n]*\\(>\\)" (1 "> b"))
355-
("\\(<\\)[?!]" (1 (prog1 "|>"
356-
(sgml-syntax-propertize-inside end))))
357-
;; Double quotes outside of tags should not introduce strings.
358-
;; Be careful to call `syntax-ppss' on a position before the one we're
359-
;; going to change, so as not to need to flush the data we just computed.
360-
("\"" (0 (if (prog1 (zerop (car (syntax-ppss (match-beginning 0))))
361-
(goto-char (match-end 0)))
362-
(string-to-syntax ".")))))
363-
start end))
366+
(syntax-propertize-rules sgml-syntax-propertize-rules)
367+
start end))
364368

365369
(defun sgml-syntax-propertize-inside (end)
366370
(let ((ppss (syntax-ppss)))
@@ -1304,13 +1308,24 @@ really isn't a tag after all."
13041308
(let ((pps (parse-partial-sexp start end 2)))
13051309
(and (= (nth 0 pps) 0))))))
13061310

1311+
(defun sgml--find-<>-backward (limit)
1312+
"Search backward for a '<' or '>' character.
1313+
The character must have open or close syntax.
1314+
Returns t if found, nil otherwise."
1315+
(catch 'found
1316+
(while (re-search-backward "[<>]" limit 'move)
1317+
;; If this character has "open" or "close" syntax, then we've
1318+
;; found the one we want.
1319+
(when (memq (syntax-class (syntax-after (point))) '(4 5))
1320+
(throw 'found t)))))
1321+
13071322
(defun sgml-parse-tag-backward (&optional limit)
13081323
"Parse an SGML tag backward, and return information about the tag.
13091324
Assume that parsing starts from within a textual context.
13101325
Leave point at the beginning of the tag."
13111326
(catch 'found
13121327
(let (tag-type tag-start tag-end name)
1313-
(or (re-search-backward "[<>]" limit 'move)
1328+
(or (sgml--find-<>-backward limit)
13141329
(error "No tag found"))
13151330
(when (eq (char-after) ?<)
13161331
;; Oops!! Looks like we were not in a textual context after all!.

0 commit comments

Comments
 (0)