From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#5560: 23.1.92; parens matching in c-mode broken Date: Sun, 21 Feb 2016 12:35:39 +0000 Message-ID: <20160221123539.GA2220@acm.fritz.box> References: <4B60ED87-9CF5-464A-AE3F-C948ADB1C4D2@gmail.com> <20160220225723.GA10801@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1456058064 23689 80.91.229.3 (21 Feb 2016 12:34:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Feb 2016 12:34:24 +0000 (UTC) Cc: David Reitter , 5560@debbugs.gnu.org To: Andrew Hyatt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 21 13:34:12 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 1aXTDI-000348-4g for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Feb 2016 13:34:12 +0100 Original-Received: from localhost ([::1]:40522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXTDH-0001H1-Gq for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Feb 2016 07:34:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXTDC-0001Gj-Py for bug-gnu-emacs@gnu.org; Sun, 21 Feb 2016 07:34:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXTDB-0008Qy-OJ for bug-gnu-emacs@gnu.org; Sun, 21 Feb 2016 07:34:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXTD7-0008QY-U0; Sun, 21 Feb 2016 07:34:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aXTD7-0001x2-Md; Sun, 21 Feb 2016 07:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org Resent-Date: Sun, 21 Feb 2016 12:34: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.14560579957448 (code B ref 5560); Sun, 21 Feb 2016 12:34:01 +0000 Original-Received: (at 5560) by debbugs.gnu.org; 21 Feb 2016 12:33:15 +0000 Original-Received: from localhost ([127.0.0.1]:35879 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aXTCN-0001w4-Ep for submit@debbugs.gnu.org; Sun, 21 Feb 2016 07:33:15 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:31185) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aXTCM-0001vv-5f for 5560@debbugs.gnu.org; Sun, 21 Feb 2016 07:33:14 -0500 Original-Received: (qmail 2460 invoked by uid 3782); 21 Feb 2016 12:33:13 -0000 Original-Received: from acm.muc.de (p579E8505.dip0.t-ipconnect.de [87.158.133.5]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 21 Feb 2016 13:33:12 +0100 Original-Received: (qmail 3361 invoked by uid 1000); 21 Feb 2016 12:35:39 -0000 Content-Disposition: inline In-Reply-To: <20160220225723.GA10801@acm.fritz.box> User-Agent: Mutt/1.5.24 (2015-08-30) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de 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:113403 Archived-At: Hello again, David and Andrew. 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: > > 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. > > David Reitter writes: > > > Parens matching in C mode is sometimes surprising. In the example > > > below, double-clicking on either of the first two opening parentheses > > > 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. > > > #define EV_MODIFIERS(e) \ > > > ((([e modifierFlags] & NSHelpKeyMask) ? \ > > > hyper_modifier : 0) \ > > > ... > > > 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. > 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. 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. Here's the patch. Please try it out and let me know if there's anything amiss about it. Otherwise, I'll commit it. 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 (= start end) (char-after start) (= (char-syntax (char-after start)) ?\()) - (list start - (save-excursion - (goto-char start) - (forward-sexp 1) - (point)))) + (if (/= (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 (= mode 1) (= start end) (char-after start) (= (char-syntax (char-after start)) ?\))) - (list (save-excursion - (goto-char (1+ start)) - (backward-sexp 1) - (point)) - (1+ start))) + (if (/= (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 (= mode 1) (= start end) (char-after start) -- Alan Mackenzie (Nuremberg, Germany).