From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: joaotavora@gmail.com (=?utf-8?B?Sm/Do28gVMOhdm9yYQ==?=) Newsgroups: gmane.emacs.devel Subject: Re: Emacs pretest -- electric-pair-mode change Date: Fri, 04 Apr 2014 09:08:28 +0100 Message-ID: <87mwg1jz43.fsf@kitaj.lan> References: <87d2h0ujls.fsf_-_@kitaj.lan> <87sipujhq2.fsf@kitaj.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1396598951 26289 80.91.229.3 (4 Apr 2014 08:09:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 4 Apr 2014 08:09:11 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 04 10:09:03 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WVzBP-0000ZA-GV for ged-emacs-devel@m.gmane.org; Fri, 04 Apr 2014 10:09:03 +0200 Original-Received: from localhost ([::1]:48345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVzBP-0002J7-0G for ged-emacs-devel@m.gmane.org; Fri, 04 Apr 2014 04:09:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVzB0-0001t6-DF for emacs-devel@gnu.org; Fri, 04 Apr 2014 04:08:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WVzAu-0002Qs-Vf for emacs-devel@gnu.org; Fri, 04 Apr 2014 04:08:38 -0400 Original-Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]:61025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WVzAu-0002Qn-OC for emacs-devel@gnu.org; Fri, 04 Apr 2014 04:08:32 -0400 Original-Received: by mail-wg0-f41.google.com with SMTP id n12so3091949wgh.24 for ; Fri, 04 Apr 2014 01:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version:content-type; bh=voc0NkZ0OngevwqM72dwaacnyL2xQfCKPt99Wyq7emo=; b=MIeCxXGhdhFMVqvlVp+ihdEU4lF0exoHVDlGICNWhvkyEqhbKnwo+YUKK+PbamRd/N cTA7EezeYRjVFGk81cdmaG2KehTgunXp50B0N0xrTkvujam8Qpd+2K2tEoYvUfB7FsCF YCwA4a22FBrbeuMSFj7O81khwXpPNjKerE0gUXUu7byMNTTFeOZD2a9Yw+T1ffgUuu/R TuHGL/KmdHTRbRAM2eq8bonp7RUvzF/2XGfnmRN0Ew3fDJNp1+CmPNwGTTTI3Ly7n65T ho3rBLba4nB/CvRvuswoZ7Rl5plyUSP+y8Ybar0xcQTZz2drIsp/GrQ5ZLlT1QOnJKcu KV1g== X-Received: by 10.194.188.68 with SMTP id fy4mr17653454wjc.30.1396598911852; Fri, 04 Apr 2014 01:08:31 -0700 (PDT) Original-Received: from kitaj.lan.yourcompany.com (66.207.108.93.rev.vodafone.pt. [93.108.207.66]) by mx.google.com with ESMTPSA id k9sm11300750wjx.37.2014.04.04.01.08.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 04 Apr 2014 01:08:30 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Thu, 03 Apr 2014 16:54:53 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::229 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:171304 Archived-At: Stefan Monnier writes: > So this heuristic reduces to "only try to pair in the last > chars of the buffer". Actually 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.