From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#18378: [Patch] wrong fontification of Java code Date: Wed, 22 Jan 2020 20:59:06 +0000 Message-ID: <20200122205906.GC4319@ACM> References: <87eevtq14x.fsf@marxist.se> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="2422"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: Jordon Biondo , 18378@debbugs.gnu.org, Paul Pogonyshev To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 22 22:00:15 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iuN6l-0000bN-1u for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jan 2020 22:00:15 +0100 Original-Received: from localhost ([::1]:46860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuN6k-0005h5-4E for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 22 Jan 2020 16:00:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57683) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iuN6a-0005gj-Ql for bug-gnu-emacs@gnu.org; Wed, 22 Jan 2020 16:00:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iuN6Z-0006Rm-IO for bug-gnu-emacs@gnu.org; Wed, 22 Jan 2020 16:00:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45463) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iuN6Y-0006PS-KJ for bug-gnu-emacs@gnu.org; Wed, 22 Jan 2020 16:00:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iuN6Y-0001aO-JT for bug-gnu-emacs@gnu.org; Wed, 22 Jan 2020 16:00:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 22 Jan 2020 21:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18378 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18378-submit@debbugs.gnu.org id=B18378.15797267546009 (code B ref 18378); Wed, 22 Jan 2020 21:00:02 +0000 Original-Received: (at 18378) by debbugs.gnu.org; 22 Jan 2020 20:59:14 +0000 Original-Received: from localhost ([127.0.0.1]:51436 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iuN5m-0001Yr-7A for submit@debbugs.gnu.org; Wed, 22 Jan 2020 15:59:14 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:50340 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1iuN5j-0001Yi-Uh for 18378@debbugs.gnu.org; Wed, 22 Jan 2020 15:59:12 -0500 Original-Received: (qmail 82123 invoked by uid 3782); 22 Jan 2020 20:59:10 -0000 Original-Received: from acm.muc.de (p4FE15DC6.dip0.t-ipconnect.de [79.225.93.198]) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 22 Jan 2020 21:59:06 +0100 Original-Received: (qmail 31974 invoked by uid 1000); 22 Jan 2020 20:59:06 -0000 Content-Disposition: inline In-Reply-To: <87eevtq14x.fsf@marxist.se> 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:175114 Archived-At: Hello, Stefan. On Mon, Jan 20, 2020 at 22:16:46 +0100, Stefan Kangas wrote: > Hi Alan, > Could you please help review the below patch for cc-fonts.el? I missed this bug report back in 2014. The code has moved around so much since then that Jordon's patch no longer applies. But a simple patch with the same idea appears to fix this bug: diff -r 3d883b66c245 cc-engine.el --- a/cc-engine.el Tue Jan 07 19:24:00 2020 +0000 +++ b/cc-engine.el Wed Jan 22 20:49:53 2020 +0000 @@ -9025,7 +9025,7 @@ (if (looking-at c-:-op-cont-regexp) (progn (goto-char (match-end 0)) t) (not - (and (c-major-mode-is 'c++-mode) + (and (c-major-mode-is '(c++-mode java-mode)) (save-excursion (and (c-go-up-list-backward) This patch should apply cleanly to the emacs-27 branch, and most probably to master, too. > Thanks in advance. > Best regards, > Stefan Kangas -- Alan Mackenzie (Nuremberg, Germany). > Paul Pogonyshev writes: > > class X > > { > > public void x () > > { > > for (int this_is_not_a_function_name : getX ()) { > > } > > } > > } > > > > In current trunk (compiled five minutes ago) > > 'this_is_not_a_function_name' above is fontified as a function > > name. This seems to depend on whether I have '()' after 'getX' or > > not. > > > > Paul > Jordon Biondo writes: > > I have a potential solution for this bug, as it has impacted me as well. > > > > Not sure what the best solution would be but I have included a patch that does > > solve the problem. From what I can tell there are no tests for java > > fortification but I have not seen any issues arising in my own java > > projects. The issue was that in java, a “:” can mark the end of a declaration in > > a foreach, not just a “;” or “,”. > > > > === modified file 'lisp/ChangeLog' > > *** lisp/ChangeLog 2014-09-01 15:03:45 +0000 > > --- lisp/ChangeLog 2014-09-01 19:11:46 +0000 > > *************** > > *** 1,3 **** > > --- 1,8 ---- > > + 2014-09-01 Jordon Biondo > > + > > + * progmodes/cc-fonts.el (c-font-lock-declarators): Special > > + case for declarations inside Java foreach loops (Bug#18378) > > + > > 2014-09-01 Eli Zaretskii > > > > * ls-lisp.el (ls-lisp-use-string-collate) > > > > === modified file 'lisp/progmodes/cc-fonts.el' > > *** lisp/progmodes/cc-fonts.el 2014-08-24 20:50:11 +0000 > > --- lisp/progmodes/cc-fonts.el 2014-09-01 19:11:59 +0000 > > *************** casts and declarations are fontified. U > > *** 1116,1123 **** > > ;; initializing brace lists. > > (let (found) > > (while > > ! (and (setq found (c-syntactic-re-search-forward > > ! "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t)) > > (eq (char-before) ?\[) > > (c-go-up-list-forward)) > > (setq brackets-after-id t)) > > --- 1116,1128 ---- > > ;; initializing brace lists. > > (let (found) > > (while > > ! (and (setq found (c-syntactic-re-search-forward > > ! (concat "[;,]\\|\\s)\\|\\'\\|\\(=\\|" > > ! (if (c-major-mode-is 'java-mode) > > ! ":\\|" > > ! "") > > ! "\\s(\\)") > > ! limit t t)) > > (eq (char-before) ?\[) > > (c-go-up-list-forward)) > > (setq brackets-after-id t))