unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
@ 2019-08-21 22:20 Zachary Napier
       [not found] ` <mailman.18.1566429065.1922.bug-gnu-emacs@gnu.org>
  2019-08-25 18:12 ` Stefan Monnier
  0 siblings, 2 replies; 6+ messages in thread
From: Zachary Napier @ 2019-08-21 22:20 UTC (permalink / raw)
  To: 37137

[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]

I have in my .emacs file only these two lines:

    (custom-set-variables
     '(font-lock-keywords-case-fold-search t))

Then if I visit an empty or nonexistent C file and just type "LONG"
(in all caps or with at least one letter being capital), Emacs will
hang after typing the final G but before the G appears on
screen. Typing C-g a couple of times gets Emacs unstuck until I
continue to type. The same behavior also happens if I type "SHORT".

This happens in both Emacs 26.1 in text mode on a Linux machine and in
Emacs 25.3 in GUI mode on Windows.

After messing with GDB a bit, I am pretty sure the hang is at the
while loop in c-forward-type at cc-engine.el:7657 and its getting
stuck because looking-at matches LONG because its case insensitive,
but the c-forward-keyword-clause doesn't move forward because the
first thing it does is try to find "LONG" in c-keywords-obarray via
`intern-soft` and immediately returns because it doesn't find it
there. Here is the while loop:

    (while (progn
             (setq safe-pos (point))
             (looking-at c-opt-type-component-key))
      (when (and c-record-type-identifiers
                 (looking-at c-primitive-type-key))
        (c-record-type-id (cons (match-beginning 1)
                                (match-end 1))))
      (c-forward-keyword-clause 1))

[-- Attachment #2: Type: text/html, Size: 1537 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
       [not found] ` <mailman.18.1566429065.1922.bug-gnu-emacs@gnu.org>
@ 2019-08-25 10:22   ` Alan Mackenzie
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2019-08-25 10:22 UTC (permalink / raw)
  To: Zachary Napier; +Cc: 37137

Hello, Zachary.

In article <mailman.18.1566429065.1922.bug-gnu-emacs@gnu.org> you wrote:
> [-- text/plain, encoding 7bit, charset: UTF-8, 31 lines --]

> I have in my .emacs file only these two lines:

>     (custom-set-variables
>      '(font-lock-keywords-case-fold-search t))

May I ask why you're making this setting?

I think font-lock-keywords-case-fold-search is really intended to be set
by major modes, rather than as a user customisation.

> Then if I visit an empty or nonexistent C file and just type "LONG"
> (in all caps or with at least one letter being capital), Emacs will
> hang after typing the final G but before the G appears on
> screen. Typing C-g a couple of times gets Emacs unstuck until I
> continue to type. The same behavior also happens if I type "SHORT".

Yes.  The keywords in all the CC Mode languages are case sensitive.

Almost exactly the same bug came up in 2013, when the solution was to
bind case-fold-search to nil at every "entry point" to CC Mode.  I missed
font-lock-keywords-case-fold-search at the time.

> This happens in both Emacs 26.1 in text mode on a Linux machine and in
> Emacs 25.3 in GUI mode on Windows.

> After messing with GDB a bit, I am pretty sure the hang is at the
> while loop in c-forward-type at cc-engine.el:7657 and its getting
> stuck because looking-at matches LONG because its case insensitive,
> but the c-forward-keyword-clause doesn't move forward because the
> first thing it does is try to find "LONG" in c-keywords-obarray via
> `intern-soft` and immediately returns because it doesn't find it
> there. Here is the while loop:

>     (while (progn
>              (setq safe-pos (point))
>              (looking-at c-opt-type-component-key))
>       (when (and c-record-type-identifiers
>                  (looking-at c-primitive-type-key))
>         (c-record-type-id (cons (match-beginning 1)
>                                 (match-end 1))))
>       (c-forward-keyword-clause 1))

That's an excellent piece of debugging.  :-)

I think the best fix for the bug would be for CC Mode to set
font-lock-keywords-case-fold-search explicitly to nil (buffer locally) at
C Mode (etc.) initialisation.  This would undo the effect of your
custom-set-variables form in C Mode buffers.  Would this be a problem?

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
  2019-08-21 22:20 bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode Zachary Napier
       [not found] ` <mailman.18.1566429065.1922.bug-gnu-emacs@gnu.org>
@ 2019-08-25 18:12 ` Stefan Monnier
  2019-09-01 21:28   ` Zachary Napier
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-08-25 18:12 UTC (permalink / raw)
  To: Zachary Napier; +Cc: 37137

> I have in my .emacs file only these two lines:
>
>     (custom-set-variables
>      '(font-lock-keywords-case-fold-search t))

How did you end up with that?
font-lock-keywords-case-fold-search is not a customize variable, so you
should not set it with custom-set-variables.

> Then if I visit an empty or nonexistent C file and just type "LONG"
> (in all caps or with at least one letter being capital), Emacs will
> hang after typing the final G but before the G appears on screen

Clearly not a desirable behavior, indeed, but the above var setting is
clearly a pilot error.  Of course

    (setq-default font-lock-keywords-case-fold-search t)

would give the same result, but I'd also argue that it'd be
a pilot error.


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
  2019-08-25 18:12 ` Stefan Monnier
@ 2019-09-01 21:28   ` Zachary Napier
  2019-09-02 12:50     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Zachary Napier @ 2019-09-01 21:28 UTC (permalink / raw)
  To: Stefan Monnier, acm; +Cc: 37137

[-- Attachment #1: Type: text/plain, Size: 1554 bytes --]

Hello Alen and Stefan,

> May I ask why you're making this setting?

> How did you end up with that?
> font-lock-keywords-case-fold-search is not a customize variable, so you
> should not set it with custom-set-variables.

I inherited this .emacs file from someone else who had this
set. I'm guessing it used to be customizable? If it really isn't
proper to customize it this way thats fine. I can disable it with
no real issues. I can just change the regexps I am using in
font-lock-add-keywords. I assumed that it could be customized
because if I did a search the customize option for it showed up,
but maybe improperly setting it with custom-set-variables just
adds it to Customize.

On Sun, Aug 25, 2019 at 11:12 AM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > I have in my .emacs file only these two lines:
> >
> >     (custom-set-variables
> >      '(font-lock-keywords-case-fold-search t))
>
> How did you end up with that?
> font-lock-keywords-case-fold-search is not a customize variable, so you
> should not set it with custom-set-variables.
>
> > Then if I visit an empty or nonexistent C file and just type "LONG"
> > (in all caps or with at least one letter being capital), Emacs will
> > hang after typing the final G but before the G appears on screen
>
> Clearly not a desirable behavior, indeed, but the above var setting is
> clearly a pilot error.  Of course
>
>     (setq-default font-lock-keywords-case-fold-search t)
>
> would give the same result, but I'd also argue that it'd be
> a pilot error.
>
>
>         Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 2376 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
  2019-09-01 21:28   ` Zachary Napier
@ 2019-09-02 12:50     ` Stefan Monnier
  2019-09-02 19:26       ` Alan Mackenzie
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2019-09-02 12:50 UTC (permalink / raw)
  To: Zachary Napier; +Cc: acm, 37137

> I inherited this .emacs file from someone else who had this
> set.  I'm guessing it used to be customizable?

AFAICT it's never been custom-izable, and it really would be weird for
it to be.  I think it's more likely that this custom-set-variables was
hand-edited.

> I can just change the regexps I am using in
> font-lock-add-keywords.

That's a much safer approach.  You can also do

    (add-hook '<foo>-mode-hook
      (lambda ()
        (setq-local font-lock-case-fold-search t)))

for the specific mode where you need it: it may break the font-locking
of that mode, but if it does, at least the breakage will be limited to
that mode.


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode
  2019-09-02 12:50     ` Stefan Monnier
@ 2019-09-02 19:26       ` Alan Mackenzie
  0 siblings, 0 replies; 6+ messages in thread
From: Alan Mackenzie @ 2019-09-02 19:26 UTC (permalink / raw)
  To: Stefan Monnier, Zachary Napier; +Cc: 37137

Hello, Stefan and Zachary.

On Mon, Sep 02, 2019 at 08:50:12 -0400, Stefan Monnier wrote:
> > I inherited this .emacs file from someone else who had this
> > set.  I'm guessing it used to be customizable?

> AFAICT it's never been custom-izable, and it really would be weird for
> it to be.  I think it's more likely that this custom-set-variables was
> hand-edited.

That variable couldn't possibly have been customisable.  It's default
value being other than nil breaks font locking, in that it spikes its
active binding to t, regardless of the value supplied in (nth 2
font-lock-defaults).

> > I can just change the regexps I am using in
> > font-lock-add-keywords.

> That's a much safer approach.  You can also do

>     (add-hook '<foo>-mode-hook
>       (lambda ()
>         (setq-local font-lock-case-fold-search t)))

> for the specific mode where you need it: it may break the font-locking
> of that mode, but if it does, at least the breakage will be limited to
> that mode.

No.  font-lock-keywords-case-fold-search is purely a font-lock internal
variable.  Any buffer local value of it created outside of font-lock
gets ignored.  Setting its default value to anything other than nil will
break font-locking, as described above.

There is neither need nor sense in setting
font-lock-keywords-case-fold-search.  Instead, set element 2 of
font-lock-defaults to the desired setting.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-09-02 19:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-21 22:20 bug#37137: Setting font-lock-case-fold-search to t causes hangs on certain types in c-mode Zachary Napier
     [not found] ` <mailman.18.1566429065.1922.bug-gnu-emacs@gnu.org>
2019-08-25 10:22   ` Alan Mackenzie
2019-08-25 18:12 ` Stefan Monnier
2019-09-01 21:28   ` Zachary Napier
2019-09-02 12:50     ` Stefan Monnier
2019-09-02 19:26       ` Alan Mackenzie

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