Subject: Re: bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer

From: Stefan Kangas <[email-masked]>
Date: Wed, 3 Nov 2021 17:06:08 -0700

Gregory Heytings <[email-masked]> 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.