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#23818: 25.0.95.3: c-beginning-of-defun misbehaviour Date: 24 Jun 2016 15:02:34 -0000 Organization: muc.de e.V. Message-ID: <20160624150234.66344.qmail@mail.muc.de> References: <87ziqeaxdi.fsf@linux-qg7d.fritz.box> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1466780604 6702 80.91.229.3 (24 Jun 2016 15:03:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 24 Jun 2016 15:03:24 +0000 (UTC) Cc: 23818@debbugs.gnu.org To: Rolf Ade Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jun 24 17:03:16 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 1bGSdX-0004Nx-OB for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Jun 2016 17:03:15 +0200 Original-Received: from localhost ([::1]:44135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSdX-0006us-0m for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Jun 2016 11:03:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSdN-0006tR-RS for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 11:03:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bGSdK-0000DI-Fa for bug-gnu-emacs@gnu.org; Fri, 24 Jun 2016 11:03:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bGSdK-0000DD-Bq; Fri, 24 Jun 2016 11:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bGSdK-0005Lg-6V; Fri, 24 Jun 2016 11:03:02 -0400 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: Fri, 24 Jun 2016 15:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23818 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 23818-submit@debbugs.gnu.org id=B23818.146678055620526 (code B ref 23818); Fri, 24 Jun 2016 15:03:02 +0000 Original-Received: (at 23818) by debbugs.gnu.org; 24 Jun 2016 15:02:36 +0000 Original-Received: from localhost ([127.0.0.1]:54454 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGScu-0005Kz-D3 for submit@debbugs.gnu.org; Fri, 24 Jun 2016 11:02:36 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:55277) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bGSct-0005Kr-C1 for 23818@debbugs.gnu.org; Fri, 24 Jun 2016 11:02:35 -0400 Original-Received: (qmail 66345 invoked by uid 3782); 24 Jun 2016 15:02:34 -0000 In-Reply-To: X-Newsgroups: gnu.emacs.bug User-Agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.3-RELEASE-p4 (amd64)) 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" Xref: news.gmane.org gmane.emacs.bugs:120005 Archived-At: Hello, Rolf In article you wrote: > The same in 24.5 and 25.0.95.3: > emacs -Q > Open some random emtpy buffer foo.c, put it in c-mode (M-x c-mode) and > insert the following C code: > #define DBG(x) x > DBG( > static void __dbgAttr () { > /* something */ > } > ) > int main (void) > { > int i; > i++; > i++; > return i; > } > int foo () > { > int i; > i++; > i++; > return 1; > } > Put the point inside function main and C-M-home (or M-x > c-beginning-of-defun). Instead of the beginning of main() the point is > here: > _P_DBG( > ... > Far away from > _P_int main(void) > ... Thank you for the bug report, and thanks even more for making it a nice concise easy to work with example. > This isn't "unbalanced braces in preprocessor statements are > horrendously difficult to parse" as in bug #23775, there are no > unbalanced braces everywhere. It's that some code above the code of a > syntactical correct function disturbs c-beginning-of-defun in finding > the beginning of the function. There are two things here. The first is that you must configure "DBG" as a "macro with a semicolon", as detailed in the CC Mode manual, page "Macros with ;". For example, you could put the following into your c-mode-common-hook: (setq c-macro-names-with-semicolon '("DBG")) (c-make-macro-with-semi-re) . That would set up that macro for all your C files. c-mode-common-hook is more precisely described on pages "Configuration Basics" and "CC Hooks" in the CC Mode manual. The second part of the fix is an actual bug where the software fails to check for "macros with semicolons" at a critical point. For that, could you install the following patch, please, then byte-compile cc-engine.el: diff -r 4c8ccaedfd6a cc-engine.el --- a/cc-engine.el Fri Jun 24 13:06:30 2016 +0000 +++ b/cc-engine.el Fri Jun 24 14:55:30 2016 +0000 @@ -9135,7 +9135,8 @@ (/= last-stmt-start (point)) (progn (c-backward-syntactic-ws lim) - (not (memq (char-before) '(?\; ?} ?: nil)))) + (not (or (memq (char-before) '(?\; ?} ?: nil)) + (c-at-vsemi-p)))) (save-excursion (backward-char) (not (looking-at "\\s("))) If you want any help with applying the patch, or byte compiling, or setting up a hook, etc., feel free to send me a private email. [ .... ] When you've done all this, could you please confirm that it fixes the problem so I can close the bug, or tell me what's still buggy. Thanks! -- Alan Mackenzie (Nuremberg, Germany).