GNU bug report logs - #25841
25.2; Highlighting not being updated in some modes.

Previous Next

Package: emacs;

Reported by: Paul Whittaker <emacs <at> pdw.org.uk>

Date: Wed, 22 Feb 2017 21:46:02 UTC

Severity: minor

Tags: notabug

Found in version 25.2

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 25841 in the body.
You can then email your comments to 25841 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#25841; Package emacs. (Wed, 22 Feb 2017 21:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Whittaker <emacs <at> pdw.org.uk>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 22 Feb 2017 21:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Whittaker <emacs <at> pdw.org.uk>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.2; Highlighting not being updated in some modes.
Date: Wed, 22 Feb 2017 21:39:53 +0000
[Message part 1 (text/plain, inline)]
Hi,

I'm finding some problems using highlight-regexp to highlight words in
text that I'm editing.

In major modes that do not use syntax highlighting, the highlighting
from highlight-regexp is not updated when the buffer content is changed.
The highlighting appears to be static, based only on what was visible at
the time that highlight-regexp was called.

New text containing matches is not being highlighted when it is entered,
and existing highlighted text retains its highlighting even if it is
altered to no longer match the regexp.

These problems do not occur when calling highlight-regexp in major modes
that include syntax highlighting: in those modes, the correct behaviour
is observed, and highlighting is updated properly as the buffer content
is changed.

Although I'm using M-x report-emacs-bug in Emacs 24.5.1 (Ubuntu 16.04.2)
to report this, I've also reproduced it with the latest Git sources
(Emacs 25.2.1, built from commit fe91ff2), as well as with a much older
build (Emacs 23.3.1, Ubuntu 12.04.5).  It appears to be a long-standing
problem.


To reproduce:
 - Launch Emacs with `emacs -Q'.  The `*scratch*' buffer is displayed.
 - Enter the following:

     M-x fundamental-mode RET
     M-x highlight-regexp RET foo RET hi-yellow RET
     f o o SPC b a r SPC f o o SPC b a r

 - First bug: the `foo' words should be highlighted, but aren't.  The
   modeline shows `(Fundamental Hi)' at this point.

 - Correct the highlighting, so that the two `foo' words do get
   highlighted:

     M-x unhighlight-regexp RET foo RET
     M-x highlight-regexp RET foo RET hi-yellow RET

 - Move the cursor into a `foo' and change the text:

     C-a C-f C-f  x

 - Second bug: `foxo' does not match the regexp, but the highlighting
   has not been removed and the whole `foxo' word is now highlighted.

The bugs are also present if I replace `M-x fundamental-mode RET' with
`M-x text-mode RET' as the first command given inside Emacs.


If instead of Text or Fundamental modes I use a major mode that includes
syntax highlighting, I do not see these bugs.  For example, staying in
the `*scratch*' buffer's Lisp Interaction mode lets the highlighting
work correctly.  Other modes, such Java mode or C mode, also give the
correct behaviour:

Demonstrate correct highlighting behaviour:
  - Launch Emacs with `emacs -Q'.
  - Enter the following in the `*scratch*' buffer:

     M-x c-mode RET
     M-x highlight-regexp RET foo RET hi-yellow RET
     f o o SPC b a r SPC f o o SPC b a r

  - First bug is not present: the `foo' are correctly highlighted as
    soon as they are typed in.

  - Now move the cursor into a `foo' and type other letters:

     C-a C-f C-f  x

  - Second bug is not present: `foxo' immediately loses its
    highlighting.


Apologies if this problem is already known; I have seen various mentions
of highlight-regexp on the list, but none appears to cover the problems
above.





In GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
 of 2016-04-17 on lgw01-04, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11804000
System Description:    Ubuntu 16.04.2 LTS

Configured using:
 `configure --build x86_64-linux-gnu --prefix=/usr
 --sharedstatedir=/var/lib --libexecdir=/usr/lib
 --localstatedir=/var/lib --infodir=/usr/share/info
 --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
 --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib
 --libexecdir=/usr/lib --localstatedir=/var/lib
 --infodir=/usr/share/info --mandir=/usr/share/man --with-pop=yes
 --enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.5/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.5/site-lisp:/usr/share/emacs/site-lisp
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat
 -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time
 -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro''

Important settings:
  value of $LANG: en_GB.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  hi-lock-mode: t
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
You can run the command `highlight-regexp' with M-s h r
You can run the command `unhighlight-regexp' with C-x w r
You can run the command `highlight-regexp' with C-x w h

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils hi-lock time-date tooltip
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list newcomment
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame cham
georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese case-table epa-hook jka-cmpr-hook help simple
abbrev minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 71992 5923)
 (symbols 48 17620 0)
 (miscs 40 35 113)
 (strings 32 9289 4289)
 (string-bytes 1 255622)
 (vectors 16 9010)
 (vector-slots 8 384424 16510)
 (floats 8 66 318)
 (intervals 56 217 22)
 (buffers 960 11)
 (heap 1024 31760 1029))

[Message part 2 (text/html, inline)]
[signature.asc (application/pgp-signature, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25841; Package emacs. (Wed, 22 Feb 2017 22:03:01 GMT) Full text and rfc822 format available.

Message #8 received at 25841 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Paul Whittaker <emacs <at> pdw.org.uk>
Cc: 25841 <at> debbugs.gnu.org
Subject: Re: bug#25841: 25.2; Highlighting not being updated in some modes.
Date: Wed, 22 Feb 2017 17:02:47 -0500
Paul Whittaker wrote:

> In major modes that do not use syntax highlighting, the highlighting
> from highlight-regexp is not updated when the buffer content is changed.
> The highlighting appears to be static, based only on what was visible at
> the time that highlight-regexp was called.

This is the documented way highlight-regexp behaves:

    Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
    use overlays for highlighting.  If overlays are used, the
    highlighting will not update as you type.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25841; Package emacs. (Thu, 23 Feb 2017 12:22:01 GMT) Full text and rfc822 format available.

Message #11 received at 25841 <at> debbugs.gnu.org (full text, mbox):

From: Paul Whittaker <emacs <at> pdw.org.uk>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 25841 <at> debbugs.gnu.org
Subject: Re: bug#25841: 25.2; Highlighting not being updated in some modes.
Date: Thu, 23 Feb 2017 12:21:38 +0000
[Message part 1 (text/plain, inline)]
On 22/02/17 22:02, Glenn Morris wrote:
> This is the documented way highlight-regexp behaves:
>
>     Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
>     use overlays for highlighting.  If overlays are used, the
>     highlighting will not update as you type.

Thanks, I'd missed that.

I'm trying to get dynamic (non-overlay) highlighting working in a plain
text mode.  That documentation makes me think that I just need to enable
font-lock mode, but doing that doesn't appear to make any difference.

  emacs -Q
  M-x fundamental-mode RET
  M-1 M-x font-lock-mode RET
  M-x highlight-regexp RET foo RET hi-yellow RET

  f o o SPC b a r  ;; Not highlighted, as before.

Would you expect that to work, or is there something else that I'm
missing here?  Apologies if this is a stupid question: I suspect I'm not
seeing all of the picture.

Thanks in advance,

Paul.

-- 
Paul Whittaker
DRisQ Ltd. Company number 7754903, registered in England and Wales.
Registered office: Malvern Hills Science Park, Malvern, UK, WR14 3SZ.
Tel: +44(0)1684 252452  Web: www.drisq.com

CONFIDENTIALITY NOTICE: This email and any attachments are confidential and may be privileged.  If you are not the
intended recipient, please notify us immediately.  Please note that in these circumstances, you should not copy or
use this information for any purpose, nor disclose its contents to any other person.  Although we have scanned this
email and any attachments for viruses, it is your responsibility to ensure that they are actually virus free.

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#25841; Package emacs. (Thu, 23 Feb 2017 15:01:02 GMT) Full text and rfc822 format available.

Message #14 received at 25841 <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Paul Whittaker <emacs <at> pdw.org.uk>
Cc: Glenn Morris <rgm <at> gnu.org>, 25841 <at> debbugs.gnu.org
Subject: Re: bug#25841: 25.2; Highlighting not being updated in some modes.
Date: Thu, 23 Feb 2017 16:00:04 +0100
On Thu, 23 Feb 2017 12:21:38 +0000 Paul Whittaker <emacs <at> pdw.org.uk> wrote:

> On 22/02/17 22:02, Glenn Morris wrote:
>> This is the documented way highlight-regexp behaves:
>>
>>     Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
>>     use overlays for highlighting.  If overlays are used, the
>>     highlighting will not update as you type.
>
> Thanks, I'd missed that.
>
> I'm trying to get dynamic (non-overlay) highlighting working in a plain
> text mode.  That documentation makes me think that I just need to enable
> font-lock mode, but doing that doesn't appear to make any difference.
>
>   emacs -Q
>   M-x fundamental-mode RET
>   M-1 M-x font-lock-mode RET
>   M-x highlight-regexp RET foo RET hi-yellow RET
>
>   f o o SPC b a r  ;; Not highlighted, as before.
>
> Would you expect that to work, or is there something else that I'm
> missing here?  Apologies if this is a stupid question: I suspect I'm not
> seeing all of the picture.

I can't explain how font-lock works, but by experimenting it appears you
have to set font-lock-defaults to a non-nil value in the buffer (it
seems before enabling font-lock-mode, though there's an interaction I
don't understand).  Here's a recipe:

0. emacs -Q
1. C-x b a RET ; Switch to new buffer "a".
2. Enter some text, e.g. "foo".
3. M-x font-lock-mode RET ; Disable font-lock-mode in the buffer --
                          ; by default it's enabled globally .
4. M-: (setq-local font-lock-defaults (list 'bla)) RET
5. M-x font-lock-mode RET ; Re-enable font-lock-mode.  On one test I
                          ; thought this was sufficient, but on
                          ; subsequent repetition I've consistently
                          ; gotten a void variable error and had to
                          ; disable and then re-enable font-lock-mode
                          ; again. 
6. M-x highlight-regexp (or M-s h r) RET foo RET hi-yellow RET
=> Now "foo" is highlighted, and deleting a letter from it unhighlights
   it.

Steve Berman




Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Wed, 21 Aug 2019 02:10:02 GMT) Full text and rfc822 format available.

Notification sent to Paul Whittaker <emacs <at> pdw.org.uk>:
bug acknowledged by developer. (Wed, 21 Aug 2019 02:10:02 GMT) Full text and rfc822 format available.

Message #19 received at 25841-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Stephen Berman <stephen.berman <at> gmx.net>
Cc: Glenn Morris <rgm <at> gnu.org>, Paul Whittaker <emacs <at> pdw.org.uk>,
 25841-done <at> debbugs.gnu.org
Subject: Re: bug#25841: 25.2; Highlighting not being updated in some modes.
Date: Wed, 21 Aug 2019 04:09:38 +0200
Stephen Berman <stephen.berman <at> gmx.net> writes:

> On Thu, 23 Feb 2017 12:21:38 +0000 Paul Whittaker <emacs <at> pdw.org.uk> wrote:
>
>> On 22/02/17 22:02, Glenn Morris wrote:
>>> This is the documented way highlight-regexp behaves:
>>>
>>>     Use Font lock mode, if enabled, to highlight REGEXP.  Otherwise,
>>>     use overlays for highlighting.  If overlays are used, the
>>>     highlighting will not update as you type.
>>
>> Thanks, I'd missed that.
>>
>> I'm trying to get dynamic (non-overlay) highlighting working in a plain
>> text mode.  That documentation makes me think that I just need to enable
>> font-lock mode, but doing that doesn't appear to make any difference.
>>
>>   emacs -Q
>>   M-x fundamental-mode RET
>>   M-1 M-x font-lock-mode RET
>>   M-x highlight-regexp RET foo RET hi-yellow RET
>>
>>   f o o SPC b a r  ;; Not highlighted, as before.
>>
>> Would you expect that to work, or is there something else that I'm
>> missing here?  Apologies if this is a stupid question: I suspect I'm not
>> seeing all of the picture.
>
> I can't explain how font-lock works, but by experimenting it appears you
> have to set font-lock-defaults to a non-nil value in the buffer (it
> seems before enabling font-lock-mode, though there's an interaction I
> don't understand).  Here's a recipe:
>
> 0. emacs -Q
> 1. C-x b a RET ; Switch to new buffer "a".
> 2. Enter some text, e.g. "foo".
> 3. M-x font-lock-mode RET ; Disable font-lock-mode in the buffer --
>                           ; by default it's enabled globally .
> 4. M-: (setq-local font-lock-defaults (list 'bla)) RET
> 5. M-x font-lock-mode RET ; Re-enable font-lock-mode.  On one test I
>                           ; thought this was sufficient, but on
>                           ; subsequent repetition I've consistently
>                           ; gotten a void variable error and had to
>                           ; disable and then re-enable font-lock-mode
>                           ; again.
> 6. M-x highlight-regexp (or M-s h r) RET foo RET hi-yellow RET
> => Now "foo" is highlighted, and deleting a letter from it unhighlights
>    it.

This seems to be the documented behaviour for highlight-regexp.  Since
there's nothing more to do here, and it was already tagged notabug,
I'm closing this bug report.  If anyone disagrees, feel free to
re-open.

Thanks,
Stefan Kangas




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 18 Sep 2019 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.