From: Alan Mackenzie <acm@muc.de>
To: 31290@debbugs.gnu.org
Subject: bug#31290: Fundamental bugs in syntax-propertize
Date: Fri, 27 Apr 2018 21:08:59 +0000 [thread overview]
Message-ID: <20180427210859.GA6023@ACM> (raw)
Hello, Emacs.
There are fundamental bugs in syntax-propertize and
syntax-propertize-function. The doc string of the latter states:
The specified function may call `syntax-ppss' on any position before
END, ....
This is untrue. True is that syntax-ppss can be called on a position
only up to syntax-propertize--done. After this point, the syntax-table
properties haven't been applied, so calling syntax-ppss is, in general,
going to give a false result.
At least that would be true if syntax-propertize--done hadn't been
prematurely and spuriously increased, crudely to prevent an infinite
recursion, falsely indicating to the syntax-ppss infrastructure that the
syntax-table properties have already been applied to the region (BEGIN
END).
.... but it should not call `syntax-ppss-flush-cache', ....
Why not? Because syntax-ppss-flush-cache sets syntax-propertize--done
back to its true value, allowing the wrongly allowed syntax-ppss calls at
a later position to cause a recursive loop.
.... which means that it should not call `syntax-ppss' on some
position and later modify the buffer on some earlier position.
This is a bad restriction, because sometimes syntax-table properties can
only be correctly determined by examining the syntax of later buffer
positions. An example of this is giving the string-fence syntax-table
text property to an unbalanced opening string quote, but not to correctly
matched quotes.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The plain fact is that (syntax-ppss pos) calls (syntax-propertize pos),
so syntax-propertize cannot itself use syntax-ppss because of the
recursive loop thus created.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Proposed solutions:
1. Major modes' syntax-propertize-function's are somehow given read
access to syntax-propertize--done, and may call syntax-ppss up to that
point only. syntax-propertize--done is updated only after the
syntax-table properties have been applied. Or....
2. syntax-propertize-function's are banned from using syntax-ppss, the
documentation instead directing them to use parse-partial-sexp directly.
In either solution, the restriction on using syntax-ppss-flush-cache
would no longer be necessary, and there would be no restriction on
setting syntax-table text properties at an earlier position than the one
currently being analysed.
I think solution 2 is the better one.
--
Alan Mackenzie (Nuremberg, Germany).
next reply other threads:[~2018-04-27 21:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-27 21:08 Alan Mackenzie [this message]
2018-05-08 12:35 ` bug#31290: Fundamental bugs in syntax-propertize Dmitry Gutov
2018-05-12 11:26 ` Alan Mackenzie
2018-05-13 7:33 ` Andreas Röhler
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180427210859.GA6023@ACM \
--to=acm@muc.de \
--cc=31290@debbugs.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.