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#19669: 25.0.50; c-mode: incorrect fontification of simple enums Date: Sun, 1 Feb 2015 17:40:57 +0000 Message-ID: <20150201174057.GA2700@acm.acm> References: <87a9196pdq.fsf@secretsauce.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1422812542 9343 80.91.229.3 (1 Feb 2015 17:42:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Feb 2015 17:42:22 +0000 (UTC) Cc: 19669@debbugs.gnu.org To: Dima Kogan Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Feb 01 18:42:17 2015 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 1YHyXJ-0007lD-5q for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Feb 2015 18:42:17 +0100 Original-Received: from localhost ([::1]:51293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHyXI-0007Ot-9U for geb-bug-gnu-emacs@m.gmane.org; Sun, 01 Feb 2015 12:42:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHyXE-0007Ok-I6 for bug-gnu-emacs@gnu.org; Sun, 01 Feb 2015 12:42:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YHyXD-0004Wy-H0 for bug-gnu-emacs@gnu.org; Sun, 01 Feb 2015 12:42:12 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40320) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YHyX4-0004WS-IG; Sun, 01 Feb 2015 12:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YHyX4-0001Vt-BP; Sun, 01 Feb 2015 12:42:02 -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, 01 Feb 2015 17:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 19669 X-GNU-PR-Package: emacs,cc-mode X-GNU-PR-Keywords: Original-Received: via spool by 19669-submit@debbugs.gnu.org id=B19669.14228124995786 (code B ref 19669); Sun, 01 Feb 2015 17:42:02 +0000 Original-Received: (at 19669) by debbugs.gnu.org; 1 Feb 2015 17:41:39 +0000 Original-Received: from localhost ([127.0.0.1]:59793 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YHyWh-0001VG-0s for submit@debbugs.gnu.org; Sun, 01 Feb 2015 12:41:39 -0500 Original-Received: from colin.muc.de ([193.149.48.1]:29378 helo=mail.muc.de) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YHyWe-0001V7-GW for 19669@debbugs.gnu.org; Sun, 01 Feb 2015 12:41:37 -0500 Original-Received: (qmail 35629 invoked by uid 3782); 1 Feb 2015 17:41:34 -0000 Original-Received: from acm.muc.de (pD951AF36.dip0.t-ipconnect.de [217.81.175.54]) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 01 Feb 2015 18:41:34 +0100 Original-Received: (qmail 2785 invoked by uid 1000); 1 Feb 2015 17:40:57 -0000 Content-Disposition: inline In-Reply-To: <87a9196pdq.fsf@secretsauce.net> User-Agent: Mutt/1.5.21 (2010-09-15) 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.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.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:98954 Archived-At: Hello, Dima. On Fri, Jan 23, 2015 at 03:36:33PM -0800, Dima Kogan wrote: > Hi. I'm running a very recent build of emacs from git revision 253d44b > (2015/01/08). I'm loading a very simple C file that has some enums > defined (attached). The enum elements all should have been rendered with > font-lock-variable-name-face > However at startup with > emacs -Q -nw > only some of the elements get this face; many have just the default > face. Pressing M-x changes things: some elements actually lose the > correct face. In general, using emacs tends to change what is or isn't > rendered properly. I'm attaching screenshots of the state at startup and > after M-x. > This is 100% reproducible on my end. > enum xxx_xxxxxxxxxx_x > {XXX_XXXX_XXXX_XXXXX_XXXXX, > XXX_XXXX_XXXX_XXXXX_XXXXX, > XXX_XXXX_XXXXXX_XXXXXXXX_XXXXXXX, > XXX_XXXX_XXXXXX_XXXXXXXX_XXXXXXX, > XXX_XXXX_XXXX_XXXXXXXX, > XXXXXX_XXXXXXX_XXXX_XXXXXXXX, > XXXXX_XXXXXX_XXXX_XXXXXXXX, > XXX_XXXXXXX, > XXX_XXX_XXXXXXXX, > XXX_XXX_XXX_XXXXXXXXX, > XXXXXX_XXX_XXXXXXX, > X_XXXXXXXXXX}; > enum xxx_xxxx_xxxxxxxxxx_x > {XXX_XXXXXX_XXXX_XXX, > XXX_XXXXXX_XXXX_XX, > XXX_XXXXXXXX_XXXX_XXX, > XXX_XXXX_XXXXXXX, > XXX_XX_XXXXX_XXXX_XXXXXXX, > XXXXXX_XXXXXX_XXXX_XXXXXXXX, > XXX_XXXX_XXXXXXX, > // xxx > XXXXXX_XXXXXXXX}; What is triggering this bug is the fact you have the first enum element, "XXX_XXXX_XXXX_XXXXX_XXXXX", on the same line as the "{". On redisplay, CC Mode calculates a syntactically critical point, here the beginning of "XXX_XXXX_XXXX_XXXXX_XXXXX" and requests fontification starting there. Font lock, however, decides to start fontification, instead, at the BEGINNING OF THE LINE, which here is outside the "{", hence things go wrong. The solution is to remove the function from `font-lock-extend-region-functions' which does this. Please try out the following patch, and confirm that is does indeed solve the problem (or tell me what isn't yet fixed). Thanks for such a high quality bug report! diff -r 33a71629ac14 cc-mode.el --- a/cc-mode.el Sun Jan 11 22:37:23 2015 +0000 +++ b/cc-mode.el Sun Feb 01 17:34:19 2015 +0000 @@ -1242,6 +1242,14 @@ (font-lock-mark-block-function . c-mark-function))) + ;; Prevent `font-lock-default-fontify-region' extending the region it will + ;; fontify to whole lines by removing `font-lock-extend-region-whole-lines' + ;; (and, coincidentally, `font-lock-extend-region-multiline' (which we do + ;; not need)) from `font-lock-extend-region-functions'. (Emacs only). This + ;; fixes Emacs bug #19669. + (when (boundp 'font-lock-extend-region-functions) + (setq font-lock-extend-region-functions nil)) + (make-local-variable 'font-lock-fontify-region-function) (setq font-lock-fontify-region-function 'c-font-lock-fontify-region) -- Alan Mackenzie (Nuremberg, Germany).