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.bugs Subject: bug#35768: 27.0.50; CC-Mode problems with function definitions with macro names Date: Sat, 18 May 2019 12:56:28 +0000 Message-ID: <20190518125628.GA6231__38303.471302946$1558184389$gmane$org@ACM> References: <87k1eqdkzk.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="94241"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: 35768@debbugs.gnu.org, Noam Postavsky To: Mauro Aranda Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 18 14:59:44 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hRyw6-000OGz-Na for geb-bug-gnu-emacs@m.gmane.org; Sat, 18 May 2019 14:59:38 +0200 Original-Received: from localhost ([127.0.0.1]:33783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRyw5-00007d-Ps for geb-bug-gnu-emacs@m.gmane.org; Sat, 18 May 2019 08:59:37 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:40930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRytf-0007EH-9S for bug-gnu-emacs@gnu.org; Sat, 18 May 2019 08:57:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRytd-0000yJ-To for bug-gnu-emacs@gnu.org; Sat, 18 May 2019 08:57:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46723) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRyta-0000wc-Dv; Sat, 18 May 2019 08:57:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hRyta-0007aV-8o; Sat, 18 May 2019 08:57: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: Sat, 18 May 2019 12:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35768 X-GNU-PR-Package: emacs,cc-mode Original-Received: via spool by 35768-submit@debbugs.gnu.org id=B35768.155818419829128 (code B ref 35768); Sat, 18 May 2019 12:57:02 +0000 Original-Received: (at 35768) by debbugs.gnu.org; 18 May 2019 12:56:38 +0000 Original-Received: from localhost ([127.0.0.1]:60267 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hRytA-0007Zh-CM for submit@debbugs.gnu.org; Sat, 18 May 2019 08:56:38 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:18188 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1hRyt8-0007ZW-9O for 35768@debbugs.gnu.org; Sat, 18 May 2019 08:56:35 -0400 Original-Received: (qmail 70315 invoked by uid 3782); 18 May 2019 12:56:30 -0000 Original-Received: from acm.muc.de (p2E5D5A2C.dip0.t-ipconnect.de [46.93.90.44]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 18 May 2019 14:56:28 +0200 Original-Received: (qmail 6335 invoked by uid 1000); 18 May 2019 12:56:28 -0000 Content-Disposition: inline In-Reply-To: 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: 209.51.188.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:159486 Archived-At: Hello, Mauro. On Fri, May 17, 2019 at 09:40:09 -0300, Mauro Aranda wrote: [ .... ] > However, the following recipe exposes another problem, I think: > 1) emacs -Q > 2) Eval the following: > (defun my-c-mode-hook () > (setq c-noise-macro-with-parens-names (append > c-noise-macro-with-parens-names > '("DUMMY_1" "DUMMY_2"))) > (c-make-noise-macro-regexps)) > (add-hook 'c-mode-hook 'my-c-mode-hook) > 3) C-x C-f test.c > 4) Type the following (no need to type the #define lines, that's just for > completion) > #define DUMMY_1(params) > #define DUMMY_2(params) > int DUMMY_1 (1) DUMMY_2 (2) > foo (void) > { > return 0; > } > 5) Observe that DUMMY_1 (1) is ignored as expected, but DUMMY_2 gets > font-lock-type-face. I think that's not right. It's not right, no. > 6) To be sure that I customized c-noise-macro-with-parens-names correctly, I > tried a regexp search with c-noise-macro-with-parens-name-re, from the > beginning of the buffer: > (re-search-forward c-noise-macro-with-parens-name-re) > That gets four hits, as it should (2 for DUMMY_1 and 2 for DUMMY_2), meaning > that it does find DUMMY_2 as a noise macro with parens. Just as a matter of interest, I also tried putting "DUMMY_3" into c-noise-macro-names, and inserting it in the middle of the pertinent line in your test file. > Is that a bug? Or is there something else I can use to help CC Mode not get > confused? It's a bug. I hope the following patch fixes it. Would you please apply this patch, try it out in your real code, and confirm it fixes the bug, or tell me what's still not working. Thanks! diff -r 43b8aba74b73 cc-engine.el --- a/cc-engine.el Wed May 15 08:45:55 2019 +0000 +++ b/cc-engine.el Sat May 18 12:45:53 2019 +0000 @@ -4500,6 +4500,30 @@ (goto-char pos)))))) (< (point) start))) +(defun c-end-of-token (&optional back-limit) + ;; Move to the end of the token we're just before or in the middle of. + ;; BACK-LIMIT may be used to bound the backward search; if given it's + ;; assumed to be at the boundary between two tokens. Return non-nil if the + ;; point is moved, nil otherwise. + ;; + ;; This function might do hidden buffer changes. + (let ((start (point))) + (cond ;; ((< (skip-syntax-backward "w_" (1- start)) 0) + ;; (skip-syntax-forward "w_")) + ((> (skip-syntax-forward "w_") 0)) + ((< (skip-syntax-backward ".()" back-limit) 0) + (while (< (point) start) + (if (looking-at c-nonsymbol-token-regexp) + (goto-char (match-end 0)) + ;; `c-nonsymbol-token-regexp' should always match since + ;; we've skipped backward over punctuation or paren + ;; syntax, but move forward in case it doesn't so that + ;; we don't leave point earlier than we started with. + (forward-char)))) + (t (if (looking-at c-nonsymbol-token-regexp) + (goto-char (match-end 0))))) + (> (point) start))) + (defun c-end-of-current-token (&optional back-limit) ;; Move to the end of the current token. Do not move if not in the ;; middle of one. BACK-LIMIT may be used to bound the backward @@ -5885,9 +5909,14 @@ ;; comment style has removed face properties from a construct, ;; and is relying on `c-font-lock-declarations' to add them ;; again. - (and (< (point) cfd-limit) - (looking-at c-doc-line-join-re) - (goto-char (match-end 0))))) + (cond + ((looking-at c-noise-macro-name-re) + (c-forward-noise-clause-not-macro-decl nil)) ; Returns t. + ((looking-at c-noise-macro-with-parens-name-re) + (c-forward-noise-clause-not-macro-decl t)) ; Always returns t. + ((and (< (point) cfd-limit) + (looking-at c-doc-line-join-re)) + (goto-char (match-end 0)))))) ;; Set the position to continue at. We can avoid going over ;; the comments skipped above a second time, but it's possible ;; that the comment skipping has taken us past `cfd-prop-match' @@ -5916,6 +5945,8 @@ ;; o The first token after the end of submatch 1 in ;; `c-decl-prefix-or-start-re' when that submatch matches. This ;; submatch is typically a (L or R) brace or paren, a ;, or a ,. + ;; As a special case, noise macros are skipped over and the next + ;; token regarded as the spot. ;; o The start of each `c-decl-prefix-or-start-re' match when ;; submatch 1 doesn't match. This is, for example, the keyword ;; "class" in Pike. @@ -7452,6 +7483,21 @@ (c-forward-syntactic-ws)) t) +(defun c-forward-noise-clause-not-macro-decl (maybe-parens) + ;; Point is at a noise macro identifier, which, when MAYBE-PARENS is + ;; non-nil, optionally takes paren arguments. Go forward over this name, + ;; and when there may be optional parens, any parenthesis expression which + ;; follows it, but DO NOT go over any macro declaration which may come + ;; between them. Always return t. + (c-end-of-token) + (when maybe-parens + (let ((here (point))) + (c-forward-comments) + (if (not (and (eq (char-after) ?\() + (c-go-list-forward))) + (goto-char here)))) + t) + (defun c-forward-keyword-clause (match) ;; Submatch MATCH in the current match data is assumed to surround a ;; token. If it's a keyword, move over it and any immediately @@ -9060,7 +9106,10 @@ ((and c-opt-cpp-prefix (looking-at c-noise-macro-with-parens-name-re)) (setq noise-start (point)) - (c-forward-noise-clause) + (while + (and + (c-forward-noise-clause) + (looking-at c-noise-macro-with-parens-name-re))) (setq kwd-clause-end (point)))) (when (setq found-type (c-forward-type t)) ; brace-block-too > Best regards, > Mauro. -- Alan Mackenzie (Nuremberg, Germany).