unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Allen Li <darkfeline@felesatra.moe>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 49629@debbugs.gnu.org
Subject: bug#49629: 27.2; electric-pair-mode doesn't work for angle brackets in HTML file
Date: Sun, 1 Aug 2021 05:06:35 +0000	[thread overview]
Message-ID: <CADbSrJwSA=HQkg306uy5xJRBN8AaqPUpDcNQsm7F-M4P5n0L7w@mail.gmail.com> (raw)
In-Reply-To: <8735rybg2f.fsf@gnus.org>

On Wed, Jul 28, 2021 at 3:42 PM Lars Ingebrigtsen <larsi@gnus.org> wrote:
>
> Allen Li <darkfeline@felesatra.moe> writes:
>
> > I tried some printf debugging and I noticed that the bug goes away
> > when I add (message "%S" (buffer-substring-no-properties (point-min)
> > (point-max))) to the top of electric-pair--balance-info.  Maybe I'm
> > being dense, but I think that expression should not have this kind of
> > side effect.
>
> It should not, but it sounds like whatever's going on might be redisplay
> dependent?  In which case it might be better to say
>
> (push (buffer-string) my-var)
>
> at strategic places in the code instead of messaging, and then examining
> my-var afterwards.

I can't reproduce my previous fix of adding `(message "%S"
(buffer-substring-no-properties (point-min) (point-max)))` to the top
of `electric-pair--balance-info`.  At the time, I had many more
`message`s scattered throughout the function, but I could reliably
make the bug disappear and reappear by adding/removing this particular
`message`.  Of course, I don't remember exactly what `message`s I had
at the time.

Thus, I resorted to actually trying to understand the code.  I've
tracked down the bug to unexpected behavior from the `scan-sexps` call
in this part of `electric-pair--balance-info`:

         (ended-prematurely-fn
          ;; called when `scan-sexps' crashed against a parenthesis
          ;; pointing opposite the direction of travel.  After
          ;; traversing that character, the idea is to travel one sexp
          ;; in the opposite direction looking for a matching
          ;; delimiter.
          #'(lambda ()
              (let* ((pos (point))
                     (matched
                      (save-excursion
                        (cond ((< direction 0)
                               (condition-case err
                                   (eq (char-after pos)
                                       (electric-pair--with-uncached-syntax
                                           (table)
                                         (debug) ;; Added by me
                                         (matching-paren
                                          (char-before
                                           (scan-sexps (point) 1)))))
                                 (scan-error nil)))

The state of my test buffer at this point is `^<p>` where ^ is point.
The buffer starts as `<p^>`, and like the comment states, we move
point past the `<` "pointing opposite the direction of travel" and
look for a match for the opening `<`.

However, the `(scan-sexps (point) 1)` here signals `Scan error:
"Unbalanced parentheses", 1, 4`.  Again, the buffer state here is
`^<p>`.  Since `scan-sexps` is C, I haven't dug into it yet, but it
seems like it should work.  I also checked `(matching-paren ?<)` and
`(matching-paren ?>)` here to see if the syntax table recognizes the
angle brackets and it appears to do so, so I don't know why
`scan-sexps` is complaining.

While I don't know how the `syntax-ppss` cache works, I tried added an
extra `syntax-ppss-flush-cache` call to the start of the
`electric-pair--with-uncached-syntax`, but that doesn't help.

My current hypothesis is some odd behavior in how setting the syntax
table works.





  reply	other threads:[~2021-08-01  5:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 23:52 bug#49629: 27.2; electric-pair-mode doesn't work for angle brackets in HTML file Allen Li
2021-07-22  7:03 ` bug#49629: Acknowledgement (27.2; electric-pair-mode doesn't work for angle brackets in HTML file) Allen Li
2021-07-22 23:34   ` bug#49629: 27.2; electric-pair-mode doesn't work for angle brackets in HTML file Lars Ingebrigtsen
2021-07-25 10:08     ` Allen Li
2021-07-28 15:42       ` Lars Ingebrigtsen
2021-08-01  5:06         ` Allen Li [this message]
2021-08-01 10:41           ` Lars Ingebrigtsen
2021-12-09 10:31             ` Allen Li
2021-12-09 13:30               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-24 10:07                 ` Allen Li
2021-12-24 14:23                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-26  8:41               ` Allen Li
2022-06-26  9:38                 ` Allen Li
2022-06-26 12:17                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-06-27  0:33                     ` Allen Li
2022-06-27 12:39                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-02 10:48                         ` Allen Li
2022-07-03 10:32                           ` Lars Ingebrigtsen

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='CADbSrJwSA=HQkg306uy5xJRBN8AaqPUpDcNQsm7F-M4P5n0L7w@mail.gmail.com' \
    --to=darkfeline@felesatra.moe \
    --cc=49629@debbugs.gnu.org \
    --cc=larsi@gnus.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).