unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Dima Kogan <dima@secretsauce.net>
Cc: 19669@debbugs.gnu.org
Subject: bug#19669: 25.0.50; c-mode: incorrect fontification of simple enums
Date: Sun, 1 Feb 2015 17:40:57 +0000	[thread overview]
Message-ID: <20150201174057.GA2700@acm.acm> (raw)
In-Reply-To: <87a9196pdq.fsf@secretsauce.net>

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).





  parent reply	other threads:[~2015-02-01 17:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-23 23:36 bug#19669: 25.0.50; c-mode: incorrect fontification of simple enums Dima Kogan
     [not found] ` <handler.19669.B.14220562124798.ack@debbugs.gnu.org>
2015-01-24  5:29   ` bug#19669: Acknowledgement (25.0.50; c-mode: incorrect fontification of simple enums) Dima Kogan
2015-01-24 15:27     ` Alan Mackenzie
2015-02-01 21:27       ` Alan Mackenzie
2015-02-01 17:40 ` Alan Mackenzie [this message]
2015-02-01 20:13   ` bug#19669: 25.0.50; c-mode: incorrect fontification of simple enums Dima Kogan
2015-02-01 21:58     ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150201174057.GA2700@acm.acm \
    --to=acm@muc.de \
    --cc=19669@debbugs.gnu.org \
    --cc=dima@secretsauce.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).