emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: html, css, and js modes working together


From: Tom Tromey
Subject: Re: html, css, and js modes working together
Date: Mon, 06 Feb 2017 20:40:47 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.91 (gnu/linux)

>>>>> "Dmitry" == Dmitry Gutov <address@hidden> writes:

Dmitry> - Try this example:
Dmitry> <html>
Dmitry>   <script>
Dmitry>     var a = 4;
Dmitry>     alert(a);
Dmitry>   </script>
Dmitry> </html>

Dmitry> It indents fine. Now try replacing "4" with "4 < 5" and reindenting
Dmitry> the "alert" line. It jumps to the right.

I debugged this tonight.

The problem here is that sgml-parse-tag-backward looks for "<" or ">"
characters, but doesn't consider the syntax.  The appended patch fixes
this test case.

My hope is that the html-syntax-propertize-function -- maybe not the one
I wrote but one that's been fixed according to the various comments in
this thread -- should suffice to fix all such problems in principle.
Something like this problem in sgml-parse-tag-backward doesn't
invalidate the scheme; this is just a buglet.  What do you think?

Tom

diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index a2f132c..5e0a407 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -1290,13 +1290,24 @@ sgml-tag-text-p
       (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!.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]