[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs pretest -- electric-pair-mode change

From: João Távora
Subject: Re: Emacs pretest -- electric-pair-mode change
Date: Thu, 03 Apr 2014 12:06:39 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt)

Stefan Monnier <address@hidden> 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


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
                                 (goto-char (nth 8 selector-ppss))
                                 (forward-comment (point-max))
                                 (skip-syntax-backward " >!")
                            (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)
           (scan-error t)))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]