unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Tom Tromey <tom@tromey.com>, Emacs discussions <emacs-devel@gnu.org>
Subject: Re: html, css, and js modes working together
Date: Mon, 06 Feb 2017 20:40:47 -0700	[thread overview]
Message-ID: <87zihy7jnk.fsf@tromey.com> (raw)
In-Reply-To: <e0514b19-7953-bc07-d9ed-d5152ced94e9@yandex.ru> (Dmitry Gutov's message of "Mon, 6 Feb 2017 05:08:05 +0200")

>>>>> "Dmitry" == Dmitry Gutov <dgutov@yandex.ru> 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!.



  parent reply	other threads:[~2017-02-07  3:40 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-31 20:34 html, css, and js modes working together Tom Tromey
2017-02-01  7:29 ` Clément Pit-Claudel
2017-02-07  4:33   ` Tom Tromey
2017-02-10  2:31     ` Tom Tromey
2017-02-02 14:19 ` Stefan Monnier
     [not found]   ` <87mvdy7f2g.fsf@tromey.com>
2017-02-07 14:33     ` Stefan Monnier
2017-02-06  3:08 ` Dmitry Gutov
2017-02-06  3:26   ` Tom Tromey
2017-02-06  3:46     ` Dmitry Gutov
2017-02-06  6:50       ` Clément Pit-Claudel
2017-02-06 14:17       ` Stefan Monnier
2017-02-06 20:25         ` Tom Tromey
2017-02-06 20:58           ` Dmitry Gutov
2017-02-06 22:42             ` Stefan Monnier
2017-02-06 23:51         ` Lennart Borgman
2017-02-07  3:40   ` Tom Tromey [this message]
2017-02-07 11:28     ` Dmitry Gutov
2017-02-09 23:45 ` Tom Tromey
2017-02-10 20:05   ` Stefan Monnier
2017-02-10 21:15     ` Tom Tromey
2017-02-10 23:45       ` Stefan Monnier
2017-02-11 17:46         ` Tom Tromey
2017-02-11 20:20           ` Stefan Monnier
2017-02-12 16:17             ` Dmitry Gutov
2017-02-12 16:20           ` Dmitry Gutov
2017-02-12 16:52             ` Tom Tromey
2017-02-13  1:12               ` Dmitry Gutov
2017-02-13  1:59               ` Dmitry Gutov
2017-02-13  2:48                 ` Tom Tromey
2017-02-14  1:34                   ` Dmitry Gutov
2017-03-19 17:30                     ` Tom Tromey
2017-03-21  9:15                       ` Dmitry Gutov
2017-03-24  3:18                         ` Tom Tromey
2017-03-24 12:02                           ` Stefan Monnier
2017-03-24 12:08                           ` Toon Claes
2017-03-24 12:59                             ` Noam Postavsky
2017-03-24 14:17                               ` Tom Tromey
2017-04-05 22:01                           ` Tom Tromey
2017-04-06  2:28                             ` Leo Liu
2017-04-06 14:12                             ` Dmitry Gutov
2017-02-11 17:39       ` Tom Tromey
2017-02-11 19:48         ` Stefan Monnier
2017-02-12  3:49           ` Tom Tromey
2017-02-12  5:26             ` Stefan Monnier
2017-02-12  6:14               ` Tom Tromey
2017-02-12  7:02                 ` Stefan Monnier
2017-02-12  7:22                   ` Tom Tromey
2017-02-12 11:14             ` martin rudalics
2017-02-12 16:01               ` Eli Zaretskii
2017-02-12 16:32                 ` Tom Tromey
2017-02-12 17:14                   ` Stefan Monnier
2017-02-12 17:36                     ` Tom Tromey
2017-02-12 18:17                   ` Eli Zaretskii
2017-02-12 16:59                 ` Stefan Monnier
2017-02-11  0:28   ` Please ack Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zihy7jnk.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).