From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Reitter Newsgroups: gmane.emacs.bugs Subject: bug#5560: 23.1.92; parens matching in c-mode broken Date: Sun, 21 Feb 2016 16:40:09 -0500 Message-ID: <00B53025-4477-4BBC-961A-0B8DF4234C19@gmail.com> References: <4B60ED87-9CF5-464A-AE3F-C948ADB1C4D2@gmail.com> <20160220225723.GA10801@acm.fritz.box> <20160221123539.GA2220@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1456090882 20969 80.91.229.3 (21 Feb 2016 21:41:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Feb 2016 21:41:22 +0000 (UTC) Cc: Andrew Hyatt , 5560@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 21 22:41:11 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1aXbkb-0005iE-Mn for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Feb 2016 22:41:09 +0100 Original-Received: from localhost ([::1]:44330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXbkb-0005tm-0w for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Feb 2016 16:41:09 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXbkX-0005te-Ey for bug-gnu-emacs@gnu.org; Sun, 21 Feb 2016 16:41:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXbkU-0002HU-77 for bug-gnu-emacs@gnu.org; Sun, 21 Feb 2016 16:41:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:39503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXbkU-0002HA-3k; Sun, 21 Feb 2016 16:41:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aXbkT-0006ad-TX; Sun, 21 Feb 2016 16:41:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: David Reitter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Sun, 21 Feb 2016 21:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 5560 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 5560-submit@debbugs.gnu.org id=B5560.145609081125222 (code B ref 5560); Sun, 21 Feb 2016 21:41:01 +0000 Original-Received: (at 5560) by debbugs.gnu.org; 21 Feb 2016 21:40:11 +0000 Original-Received: from localhost ([127.0.0.1]:36630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aXbje-0006Yk-Uf for submit@debbugs.gnu.org; Sun, 21 Feb 2016 16:40:11 -0500 Original-Received: from mail-qg0-f53.google.com ([209.85.192.53]:34621) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aXbje-0006YY-0f for 5560@debbugs.gnu.org; Sun, 21 Feb 2016 16:40:10 -0500 Original-Received: by mail-qg0-f53.google.com with SMTP id b67so99246759qgb.1 for <5560@debbugs.gnu.org>; Sun, 21 Feb 2016 13:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=izG5x2rmEPH/YXD2LfsMXw0yomDN71S/dujWb/gM4Ew=; b=smcmF+I38wov9zGFrWftLMHXqOKbi4IN8ebXsDJZnvDGo1o3uLI4BIDowFggCpXk85 8QRKuRm5Bp3cf1ZM1ycai8OpLIz1Z/tqPhHeFWeZDqwRBo3LT+mpR3HA6PPnUOHGYR6a rN10r8teC1Ggp4A2TTo8OrDJdWtV7cZQ0/F3chFLlDayl4nt7uPc0v3GM0uWI9JXuOp5 7bjcKPDBqdcxvJd0c0GHPR0oytn03aaL9tneXzu+Fu1mdA0sNGPgBM/KoH16v60wSN+z 97NvFYhQTP1nrhSl7tTOuCG28q58eUgi+x4G6usFAp7vxYdmj1f3/oC0og247bUAquXd +bmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=izG5x2rmEPH/YXD2LfsMXw0yomDN71S/dujWb/gM4Ew=; b=RmDR4uwfrHOTK1/IOfP/COExyHOwph1EPsKuuU5dH039mtdN0FNdCpvko09pLvAeey 29TQGbzhcERDxqsldKTVLsUcHich7p0L+uUrnPlFF7JLROVPTG4gqOfCI4oZJYt8iYgq +QiVQuTbHIb47UWwEuSGYhDXOkPnQGHZEE0qjj8sLdHlR2VXJmEGbbxzaYRSNykE1aLB PIIZdbHQtGSy5g1Ql46IFmXAbH0/Xqfb2eMPClchRl90C2Toj7t2lJlCsm3qOAzeX3ze sRX1cLrD/1hsI60S4/bX98OcEpwqz5sZfDRsu62WnO8em6feMbhzSoKy6U22xSSKozWu I+Rw== X-Gm-Message-State: AG10YOQMA2W9A7OV7dfNIm9NybgHHc/5c9KbXD5VY9hjVCoBabOgskrAgOygBhTApCXJfA== X-Received: by 10.140.128.21 with SMTP id 21mr29281956qha.36.1456090804502; Sun, 21 Feb 2016 13:40:04 -0800 (PST) Original-Received: from [10.0.1.7] (c-71-58-212-112.hsd1.pa.comcast.net. [71.58.212.112]) by smtp.gmail.com with ESMTPSA id a102sm5388574qgf.21.2016.02.21.13.40.02 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 21 Feb 2016 13:40:02 -0800 (PST) In-Reply-To: <20160221123539.GA2220@acm.fritz.box> X-Mailer: Apple Mail (2.3112) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:113428 Archived-At: Alan, Your patch works as advertised for my test case. It=E2=80=99s certainly = better to error out than to do the wrong thing. I think you are catching the right situations, but my confidence is low = because of the readability of the code (what is 4, 5?). I think the question is whether that fix is appropriate for the 25.1 = release. If you want to apply it there, I would probably test a whole = lot of cases in modes that are derivates of c-mode. - David > On Feb 21, 2016, at 7:35 AM, Alan Mackenzie wrote: >=20 > Hello again, David and Andrew. >=20 > On Sat, Feb 20, 2016 at 10:57:23PM +0000, Alan Mackenzie wrote: >> On Tue, Feb 16, 2016 at 10:56:34PM -0500, Andrew Hyatt wrote: >=20 >>> I can confirm this still doesn't work right in Emacs 25. However, I = get >>> a slightly different experience, with clicking on all 3 left parens >>> highlighting until the first right paren only. Similarly, that = right >>> paren seems to be the matching paren for all 3 left parens. >=20 >>> David Reitter writes: >=20 >>>> Parens matching in C mode is sometimes surprising. In the example >>>> below, double-clicking on either of the first two opening = parentheses=20 >>>> will mark the text until the " hyper_modifier : 0)", but that = is correct >>>> only for the second paren, while the first one is unmatched due to = a space >>>> following the backslash. >=20 >>>> #define EV_MODIFIERS(e) \ >>>> ((([e modifierFlags] & NSHelpKeyMask) ? \=20 >>>> hyper_modifier : 0) \ =20 >>>> ... >=20 >=20 >>>> It would be more useful if an "unmatched parentheses" was shown, or >>>> if the region up to the end of the scan process (i.e. the >>>> space+newline) was marked. >=20 >> Giving a decent error message here would be difficult. We're down in = the >> depths of the mouse code, but the strategem of giving syntax-table = text >> properties to parentheses is a pure CC Mode one. Signaling an error = if >> a paren has other than paren syntax is liable to have unforseen side >> effects somewhere, somehow, some time. >=20 > After a night's sleep, I've changed my mind about the advisability of > such a fix. So, here is a fix. It works as indicated last night: if = a > character whose normal syntax is open/close-paren has a different = syntax > due to syntax-table text properties, a 'scan-error error is signaled: > either "Containing expression ends prematurely" for an open paren, or > "Unbalanced parentheses" for a close paren. >=20 > Here's the patch. Please try it out and let me know if there's = anything > amiss about it. Otherwise, I'll commit it. >=20 >=20 >=20 > diff --git a/lisp/mouse.el b/lisp/mouse.el > index 85ffc43..22c5b48 100644 > --- a/lisp/mouse.el > +++ b/lisp/mouse.el > @@ -931,20 +931,29 @@ mouse-start-end > (=3D start end) > (char-after start) > (=3D (char-syntax (char-after start)) ?\()) > - (list start > - (save-excursion > - (goto-char start) > - (forward-sexp 1) > - (point)))) > + (if (/=3D (car (syntax-after start)) 4) > + ;; This happens in CC Mode when unbalanced parens in CPP > + ;; constructs are given punctuation syntax with > + ;; syntax-table text properties. (2016-02-21). > + (signal 'scan-error (list "Containing expression ends = prematurely" > + start start)) > + (list start > + (save-excursion > + (goto-char start) > + (forward-sexp 1) > + (point))))) > ((and (=3D mode 1) > (=3D start end) > (char-after start) > (=3D (char-syntax (char-after start)) ?\))) > - (list (save-excursion > - (goto-char (1+ start)) > - (backward-sexp 1) > - (point)) > - (1+ start))) > + (if (/=3D (car (syntax-after start)) 5) > + ;; See above comment about CC Mode. > + (signal 'scan-error (list "Unbalanced parentheses" start = start)) > + (list (save-excursion > + (goto-char (1+ start)) > + (backward-sexp 1) > + (point)) > + (1+ start)))) > ((and (=3D mode 1) > (=3D start end) > (char-after start) >=20 >=20 >=20 > --=20 > Alan Mackenzie (Nuremberg, Germany).