From: joaotavora@gmail.com (João Távora)
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org
Subject: Re: Emacs pretest -- electric-pair-mode change
Date: Thu, 03 Apr 2014 12:06:39 +0100 [thread overview]
Message-ID: <jjbd2gyvfi8.fsf@gmail.com> (raw)
In-Reply-To: <jwvsipvwdl0.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Wed, 02 Apr 2014 18:58:11 -0400")
Stefan Monnier <monnier@IRO.UMontreal.CA> writes:
>> This last behaviour is also arguable but it is "way too clever", almost
>> buggy. The trunk's behaviour is better: it always inhibits pairing, the
>> surprising electric action, whenever there is unbalance, and as such is
>> more predictable.
>
> That makes sense. But its calling (syntax-ppss (point-max)) will result
> in large delays at times
You're right. I dug up
https://github.com/capitaomorte/autopair/issues/38
https://github.com/capitaomorte/autopair/pull/30
and noticed that I managed to improve autopair there, but not beyond the
limit that you mention. In the large python file attached to the first
issue, I experience a 1 sec delay in my linux box and 5-6 secs in
windows (on par with moving to the end of the buffer).
> (since it will syntax-propertize any part of the buffer not yet
> propertized).
This suggests it's a kind of one-time delay per buffer, but that's not
the case at least for the large python above
> Maybe it's OK because the rest of the code already
> causes similar delays.
The quote part does seem to be the most problematic. In the big
lisp/ldefs-boot.el I get just under a second on windows for pairing a
parens, and should be much faster on linux.
> In many languages, strings can't span multiple
> lines, or they can only do so if end-of-lines are somehow escaped.
> Maybe we could use that to try and reduce the scope of the test.
Maybe (how?). But even even in those languages, syntax (and
fontification) works across newlines, so do we pair for the language or
for the syntax?
Anyway, best I can come up with right now is the
following, but with frequent false negatives in oversize buffers. I
don't know if I'd rather have false positives (meaning less electricity
in oversize buffers)
(defvar electric-pair-quote-scan-bound 50000
"Number of chars to search when deciding quote pairing.")
(defun electric-pair--unbalanced-strings-p (char)
"Return non-nil if there are unbalanced strings started by CHAR"
(let* ((bound (+ electric-pair-quote-scan-bound (point)))
(selector-ppss (syntax-ppss))
(relevant-ppss (save-excursion
(if (nth 4 selector-ppss) ; comment
(electric-pair--syntax-ppss
(progn
(goto-char (nth 8 selector-ppss))
(forward-comment (point-max))
(skip-syntax-backward " >!")
(point)))
(syntax-ppss (min bound (point-max))))))
(string-delim (nth 3 relevant-ppss)))
(and (or (eq t string-delim)
(eq char string-delim))
(condition-case nil
(progn (scan-sexps (nth 8 relevant-ppss) 1)
nil)
(scan-error t)))))
João
next prev parent reply other threads:[~2014-04-03 11:06 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CADWZ7fJCws0SO1hEn38CpbRMq+Uw397uCFUnA=YJvOaLVEA8UQ@mail.gmail.com>
2014-03-31 13:27 ` Emacs pretest Stefan Monnier
2014-03-31 13:52 ` Bastien
2014-03-31 14:36 ` Tassilo Horn
2014-03-31 15:55 ` João Távora
2014-03-31 16:34 ` Stefan Monnier
2014-04-02 10:11 ` Emacs pretest -- electric-pair-mode change João Távora
2014-04-02 12:58 ` Stefan Monnier
2014-04-02 17:21 ` João Távora
2014-04-02 22:58 ` Stefan Monnier
2014-04-03 11:06 ` João Távora [this message]
2014-04-03 14:22 ` Stefan Monnier
2014-04-03 16:56 ` João Távora
2014-04-03 17:33 ` Stefan Monnier
2014-04-03 20:11 ` João Távora
2014-04-03 20:54 ` Stefan Monnier
2014-04-04 8:08 ` João Távora
2014-04-04 12:53 ` Stefan Monnier
2014-04-04 23:31 ` João Távora
2014-04-05 15:29 ` Stefan Monnier
2014-04-07 7:43 ` João Távora
2014-04-07 14:04 ` Stefan Monnier
2014-04-04 7:53 ` Eli Zaretskii
2014-04-04 9:49 ` João Távora
2014-04-11 14:42 ` Kevin Rodgers
2014-04-11 15:53 ` Stefan Monnier
2014-04-11 18:23 ` João Távora
2014-04-11 19:58 ` Stefan Monnier
2014-04-12 0:42 ` João Távora
2014-04-11 16:08 ` João Távora
2014-04-03 19:13 ` Eli Zaretskii
2014-04-03 12:15 ` Dmitry Gutov
2014-04-03 13:43 ` João Távora
2014-04-03 15:24 ` Stefan Monnier
2014-04-03 14:24 ` Stefan Monnier
2014-04-01 15:15 ` Emacs pretest Dmitry Antipov
2014-04-01 16:36 ` Dmitry Antipov
2014-04-02 12:37 ` Stefan Monnier
2014-04-01 20:50 ` Stephen Berman
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=jjbd2gyvfi8.fsf@gmail.com \
--to=joaotavora@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/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).