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: Fri, 04 Apr 2014 09:08:28 +0100 [thread overview]
Message-ID: <87mwg1jz43.fsf@kitaj.lan> (raw)
In-Reply-To: <jwvd2gyrvir.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Thu, 03 Apr 2014 16:54:53 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> So this heuristic reduces to "only try to pair in the last <constant>
> chars of the buffer".
Actually <constant + average length of non-string segments intended> or
some function of the latter, since it is also right when the probe falls
within the last unbalanced string. But you've convinced me that it sucks
more that I already suspected it did...
>> Hmmm I understand your idea better. Using that with a default
>> implementation returning (point-max) might be a good idea, modes that are
>> experiencing trouble can then write their complicated versions.
> Right.
OK so something like this is acceptable for trunk & 24.4?
(defvar electric-pair-string-bound-function 'point-max
"Next buffer position where strings are syntatically unexpected.
Value is a function called with no arguments and returning a
buffer position. Major modes should set this variable
buffer-locally if they experience slowness with
`electric-pair-mode' when pairing quotes.")
(defun electric-pair--unbalanced-strings-p (char)
"Return non-nil if there are unbalanced strings started by CHAR"
(let* ((selector-ppss (syntax-ppss))
(relevant-ppss (save-excursion
(if (nth 4 selector-ppss) ; in comment
(let ((comment-start
(progn
(goto-char (line-beginning-position))
(forward-comment (- (point-max)))
(skip-syntax-forward " >!")
(point)))
(comment-end
(progn
(goto-char (line-beginning-position))
(forward-comment (point-max))
(skip-syntax-backward " >!")
(point))))
(with-syntax-table prog-mode-syntax-table
(parse-partial-sexp comment-start comment-end)))
(syntax-ppss
(funcall electric-pair-string-bound-function)))))
(string-delim (nth 3 relevant-ppss)))
(or (eq t string-delim)
(eq char string-delim))))
Notice that the "in comment" bit is a completely independent improvement
and little ugly. The previous `electric-pair--syntax-ppss' technique
worked in comments but not across comment lines.
next prev parent reply other threads:[~2014-04-04 8:08 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
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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mwg1jz43.fsf@kitaj.lan \
--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 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.