emacs-devel
[Top][All Lists]
Advanced

[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: Fri, 04 Apr 2014 09:08:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

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



reply via email to

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