bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19669: 25.0.50; c-mode: incorrect fontification of simple enums


From: Alan Mackenzie
Subject: bug#19669: 25.0.50; c-mode: incorrect fontification of simple enums
Date: Sun, 1 Feb 2015 17:40:57 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]