From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: [PATCH] Re: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode Date: Thu, 4 Jul 2019 16:58:46 +0000 Message-ID: <20190704165846.GF5564@ACM> References: <20190702131632.GA30597@ACM> <20190702160410.GB30597@ACM> <20190702182811.GC30597@ACM> <20190703105804.GA11238@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="215779"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: emacs-devel To: =?iso-8859-1?Q?Jo=E3o_T=E1vora?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 04 18:59:03 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hj54Z-000u1T-6r for ged-emacs-devel@m.gmane.org; Thu, 04 Jul 2019 18:59:03 +0200 Original-Received: from localhost ([::1]:47730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj54X-0006t8-Qm for ged-emacs-devel@m.gmane.org; Thu, 04 Jul 2019 12:59:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50639) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj54T-0006t0-MU for emacs-devel@gnu.org; Thu, 04 Jul 2019 12:58:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hj54R-0000hX-QQ for emacs-devel@gnu.org; Thu, 04 Jul 2019 12:58:57 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:25878 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1hj54Q-0000gI-VE for emacs-devel@gnu.org; Thu, 04 Jul 2019 12:58:55 -0400 Original-Received: (qmail 98286 invoked by uid 3782); 4 Jul 2019 16:58:46 -0000 Original-Received: from acm.muc.de (p4FE15EDB.dip0.t-ipconnect.de [79.225.94.219]) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 04 Jul 2019 18:58:45 +0200 Original-Received: (qmail 16136 invoked by uid 1000); 4 Jul 2019 16:58:46 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.org gmane.emacs.devel:238357 Archived-At: Hello, Joća. On Wed, Jul 03, 2019 at 14:31:58 +0100, Joćo Tįvora wrote: [ .... ] > If [you] don't agree, find a small enough solution that fixes e-p-m, > propose it here, then find a consensus that overrides my opinion, it > happens all the time, won't hold it against you or anyone else, good > luck. Here is the entire part of the fix needed for bug #36474, that should go into elec-pair-mode.el: diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 5fb9d751e2..ba86b55167 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -484,6 +484,23 @@ electric-pair-default-inhibit (electric-pair-inhibit-if-helps-balance char) (electric-pair-conservative-inhibit char))) +(defun electric-pair-cc-inhibit-predicate (char) + "Return t to inhibit the insertion of a second copy of CHAR. + +At the time of call, point is just after the newly inserted CHAR. + +When CHAR is \", t will be returned unless the \" is marked with +a string fence syntax-table text property. For other characters +`electric-pair-default-inhibit' is called and its value returned. + +This function is the appropriate value of +`electric-pair-inhibit-predicate' for CC Mode modes, which mark +invalid strings with such a syntax table text property on the +opening \" and the next unescaped end of line." + (if (eq char ?\") + (not (equal (get-text-property (1- (point)) 'syntax-table) '(15))) + (electric-pair-default-inhibit char))) + (defun electric-pair-post-self-insert-function () (let* ((pos (and electric-pair-mode (electric--after-char-pos))) (skip-whitespace-info)) You will note that it is the mere addition of a function, not used anywhere else in elec-pair.el, so cannot possibly damage its functionality. If I was being perverse, I could even put this function in cc-mode.el instead, though this would not be good practice. This new function has been tested, and it works. Now, will you please just decide to install this patch. If you like, I can write a commit message for it. > -- > Joćo Tįvora -- Alan Mackenzie (Nuremberg, Germany).