From 7eab6ef3cee22c5f3ada55f1a68e29cb3f23da45 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Mon, 11 May 2026 23:43:27 +0200 Subject: [PATCH] Fix 'sgml-parse-tag-backward' to handle tags in comments * lisp/textmodes/sgml-mode.el (sgml--find-<>-backward): Ignore SGML tags that happen to occur within comments. This also means that the contents of comments are not indented, but also do not affect the indentation of tags following the comments as well. (Bug#80841) --- lisp/textmodes/sgml-mode.el | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el index be14462d1a0..c9f38d1ee47 100644 --- a/lisp/textmodes/sgml-mode.el +++ b/lisp/textmodes/sgml-mode.el @@ -1397,7 +1397,13 @@ Returns t if found, nil otherwise." (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)) + (when (and (memq (syntax-class (syntax-after (point))) '(4 5)) + ;; We want to ignore tags in comments. We could also + ;; check `syntax-ppss', but that can become expensive + ;; in a busy loop, so we re-use the face instead. + (not (memq (get-text-property (point) 'face) + '(font-lock-comment-delimiter-face + font-lock-comment-face)))) (throw 'found t))))) (defun sgml-parse-tag-backward (&optional limit)