GNU bug report logs - #51580
hl-line-mode doesn't override global-hl-line-mode in current buffer

Previous Next

Package: emacs;

Reported by: Stefan Kangas <stefan <at> marxist.se>

Date: Wed, 3 Nov 2021 06:48:01 UTC

Severity: normal

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

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 51580 in the body.
You can then email your comments to 51580 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#51580; Package emacs. (Wed, 03 Nov 2021 06:48:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Kangas <stefan <at> marxist.se>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 03 Nov 2021 06:48:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: bug-gnu-emacs <at> gnu.org
Subject: hl-line-mode doesn't override global-hl-line-mode in current buffer
Date: Tue, 2 Nov 2021 23:47:14 -0700
It seems like there is currently no way to use `global-hl-line-mode'
while disabling it for individual buffers.

Steps to reproduce:

0. emacs -Q
1. M-x global-hl-line-mode
2. M-x hl-line-mode

Now, `global-hl-line-mode' is still in effect, and lines are still
highlighted.  I expect that running `hl-line-mode' turns off line
highlighting.

There is a comment in hl-line.el saying:

    ;; You could make variable `global-hl-line-mode' buffer-local and set
    ;; it to nil to avoid highlighting specific buffers, when the global
    ;; mode is used.

However, if I say M-x global-hl-line-mode and then

    M-: (setq-default global-hl-line-mode nil)

the highlighting overlay is left on the current line.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Wed, 03 Nov 2021 10:07:02 GMT) Full text and rfc822 format available.

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

From: Gregory Heytings <gregory <at> heytings.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 03 Nov 2021 10:06:01 +0000
>
> It seems like there is currently no way to use `global-hl-line-mode' 
> while disabling it for individual buffers.
>

There is one: (setq-local global-hl-line-mode nil).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Wed, 03 Nov 2021 11:30:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Gregory Heytings <gregory <at> heytings.org>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 3 Nov 2021 12:28:51 +0100
Gregory Heytings <gregory <at> heytings.org> writes:

> > It seems like there is currently no way to use `global-hl-line-mode'
> > while disabling it for individual buffers.
>
> There is one: (setq-local global-hl-line-mode nil).

Here, that leaves an overlay in the buffer.  Does it not do that for you?

[You didn't quote it, but I wrote "(setq-default global-hl-line-mode
nil)" in the bug report.  That was a typo.  I meant to write
"(setq-local global-hl-line-mode nil)".]




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Wed, 03 Nov 2021 11:43:02 GMT) Full text and rfc822 format available.

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

From: Gregory Heytings <gregory <at> heytings.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 03 Nov 2021 11:42:22 +0000
>>> It seems like there is currently no way to use `global-hl-line-mode' 
>>> while disabling it for individual buffers.
>>
>> There is one: (setq-local global-hl-line-mode nil).
>
> Here, that leaves an overlay in the buffer.  Does it not do that for 
> you?
>
> [You didn't quote it, but I wrote "(setq-default global-hl-line-mode 
> nil)" in the bug report.  That was a typo.  I meant to write 
> "(setq-local global-hl-line-mode nil)".]
>

Oh, now I see what you mean.  Indeed I had seen your setq-default, but did 
not guess it meant setq-local.  Indeed, M-: (setq-local 
global-hl-line-mode nil) leaves an overlay in the buffer.  I use this in 
buffer setup hooks, so the overlay is not created.  If you want to remove 
that overlay, you also need to call global-hl-line-unhighlight:

(defun buffer-deactivate-global-hl-line-mode ()
  (interactive)
  (global-hl-line-unhighlight)
  (setq-local global-hl-line-mode nil))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Wed, 03 Nov 2021 11:52:02 GMT) Full text and rfc822 format available.

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

From: Gregory Heytings <gregory <at> heytings.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 03 Nov 2021 11:51:49 +0000
And of course this could become a command:

(defun buffer-toggle-global-hl-line-mode ()
  (interactive)
  (make-variable-buffer-local 'global-hl-line-mode)
  (if global-hl-line-mode
      (global-hl-line-unhighlight)
    (global-hl-line-highlight))
  (setq global-hl-line-mode (not global-hl-line-mode)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Wed, 03 Nov 2021 13:12:02 GMT) Full text and rfc822 format available.

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

From: Gregory Heytings <gregory <at> heytings.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 03 Nov 2021 13:11:24 +0000
[Message part 1 (text/plain, inline)]
And just in case, here's a patch with that command.
[Add-command-to-toggle-global-hl-line-mode-locally.patch (text/x-diff, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Thu, 04 Nov 2021 00:07:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Gregory Heytings <gregory <at> heytings.org>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Wed, 3 Nov 2021 17:06:08 -0700
Gregory Heytings <gregory <at> heytings.org> writes:

>>>> It seems like there is currently no way to use `global-hl-line-mode' while
>>>> disabling it for individual buffers.
>>>
>>> There is one: (setq-local global-hl-line-mode nil).
>>
>> Here, that leaves an overlay in the buffer.  Does it not do that for you?
>>
>> [You didn't quote it, but I wrote "(setq-default global-hl-line-mode nil)" in
>> the bug report.  That was a typo.  I meant to write "(setq-local
>> global-hl-line-mode nil)".]
>>
>
> Oh, now I see what you mean.  Indeed I had seen your setq-default, but did not
> guess it meant setq-local.  Indeed, M-: (setq-local global-hl-line-mode nil)
> leaves an overlay in the buffer.  I use this in buffer setup hooks, so the
> overlay is not created.  If you want to remove that overlay, you also need to
> call global-hl-line-unhighlight:
>
> (defun buffer-deactivate-global-hl-line-mode ()
>   (interactive)
>   (global-hl-line-unhighlight)
>   (setq-local global-hl-line-mode nil))

My understanding is that our convention for minor modes that provide
both a global and local variant is that calling the local mode should
disable the global mode in the current buffer.

See for example `show-paren-mode' and `show-paren-local-mode'.

So in line with this convention, I expect that no new command is needed:
I should just be able call `M-x hl-line-mode' to disable it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Thu, 04 Nov 2021 18:10:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org, Gregory Heytings <gregory <at> heytings.org>
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Thu, 04 Nov 2021 19:09:27 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

> So in line with this convention, I expect that no new command is needed:
> I should just be able call `M-x hl-line-mode' to disable it.

Yup.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51580; Package emacs. (Tue, 20 Sep 2022 11:57:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 51580 <at> debbugs.gnu.org
Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in
 current buffer
Date: Tue, 20 Sep 2022 13:55:59 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> It seems like there is currently no way to use `global-hl-line-mode'
> while disabling it for individual buffers.
>
> Steps to reproduce:
>
> 0. emacs -Q
> 1. M-x global-hl-line-mode
> 2. M-x hl-line-mode
>
> Now, `global-hl-line-mode' is still in effect, and lines are still
> highlighted.  I expect that running `hl-line-mode' turns off line
> highlighting.

I've now fixed this in Emacs 29.




bug marked as fixed in version 29.1, send any further explanations to 51580 <at> debbugs.gnu.org and Stefan Kangas <stefan <at> marxist.se> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 20 Sep 2022 11:57:02 GMT) Full text and rfc822 format available.

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

This bug report was last modified 1 year and 189 days ago.

Previous Next


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