* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
@ 2021-11-03 6:47 Stefan Kangas
2021-11-03 10:06 ` Gregory Heytings
2022-09-20 11:55 ` Lars Ingebrigtsen
0 siblings, 2 replies; 9+ messages in thread
From: Stefan Kangas @ 2021-11-03 6:47 UTC (permalink / raw)
To: 51580
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 6:47 bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer Stefan Kangas
@ 2021-11-03 10:06 ` Gregory Heytings
2021-11-03 11:28 ` Stefan Kangas
2022-09-20 11:55 ` Lars Ingebrigtsen
1 sibling, 1 reply; 9+ messages in thread
From: Gregory Heytings @ 2021-11-03 10:06 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580
>
> 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).
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 10:06 ` Gregory Heytings
@ 2021-11-03 11:28 ` Stefan Kangas
2021-11-03 11:42 ` Gregory Heytings
0 siblings, 1 reply; 9+ messages in thread
From: Stefan Kangas @ 2021-11-03 11:28 UTC (permalink / raw)
To: Gregory Heytings; +Cc: 51580
Gregory Heytings <gregory@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)".]
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 11:28 ` Stefan Kangas
@ 2021-11-03 11:42 ` Gregory Heytings
2021-11-03 11:51 ` Gregory Heytings
2021-11-04 0:06 ` Stefan Kangas
0 siblings, 2 replies; 9+ messages in thread
From: Gregory Heytings @ 2021-11-03 11:42 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580
>>> 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))
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 11:42 ` Gregory Heytings
@ 2021-11-03 11:51 ` Gregory Heytings
2021-11-03 13:11 ` Gregory Heytings
2021-11-04 0:06 ` Stefan Kangas
1 sibling, 1 reply; 9+ messages in thread
From: Gregory Heytings @ 2021-11-03 11:51 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580
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)))
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 11:51 ` Gregory Heytings
@ 2021-11-03 13:11 ` Gregory Heytings
0 siblings, 0 replies; 9+ messages in thread
From: Gregory Heytings @ 2021-11-03 13:11 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580
[-- Attachment #1: Type: text/plain, Size: 52 bytes --]
And just in case, here's a patch with that command.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff; name=Add-command-to-toggle-global-hl-line-mode-locally.patch, Size: 1227 bytes --]
From c747dd022d133133ae9d43ca137f87f2e8203e4d Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Wed, 3 Nov 2021 13:07:05 +0000
Subject: [PATCH] Add command to toggle global-hl-line-mode locally.
* lisp/hl-line.el (global-hl-line-mode-toggle): New command.
---
lisp/hl-line.el | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lisp/hl-line.el b/lisp/hl-line.el
index 26cfcc3f9c..e63313128e 100644
--- a/lisp/hl-line.el
+++ b/lisp/hl-line.el
@@ -215,6 +215,16 @@ global-hl-line-mode
(remove-hook 'post-command-hook #'global-hl-line-highlight)
(remove-hook 'change-major-mode-hook #'global-hl-line-unhighlight)))
+;;;###autoload
+(defun global-hl-line-mode-toggle ()
+ "Toggle line highlighting in this buffer with 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)))
+
(defun global-hl-line-highlight ()
"Highlight the current line in the current window."
(when global-hl-line-mode ; Might be changed outside the mode function.
--
2.33.0
^ permalink raw reply related [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 11:42 ` Gregory Heytings
2021-11-03 11:51 ` Gregory Heytings
@ 2021-11-04 0:06 ` Stefan Kangas
2021-11-04 18:09 ` Lars Ingebrigtsen
1 sibling, 1 reply; 9+ messages in thread
From: Stefan Kangas @ 2021-11-04 0:06 UTC (permalink / raw)
To: Gregory Heytings; +Cc: 51580
Gregory Heytings <gregory@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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-04 0:06 ` Stefan Kangas
@ 2021-11-04 18:09 ` Lars Ingebrigtsen
0 siblings, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-04 18:09 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580, Gregory Heytings
Stefan Kangas <stefan@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
^ permalink raw reply [flat|nested] 9+ messages in thread
* bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer
2021-11-03 6:47 bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer Stefan Kangas
2021-11-03 10:06 ` Gregory Heytings
@ 2022-09-20 11:55 ` Lars Ingebrigtsen
1 sibling, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-20 11:55 UTC (permalink / raw)
To: Stefan Kangas; +Cc: 51580
Stefan Kangas <stefan@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.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-09-20 11:55 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 6:47 bug#51580: hl-line-mode doesn't override global-hl-line-mode in current buffer Stefan Kangas
2021-11-03 10:06 ` Gregory Heytings
2021-11-03 11:28 ` Stefan Kangas
2021-11-03 11:42 ` Gregory Heytings
2021-11-03 11:51 ` Gregory Heytings
2021-11-03 13:11 ` Gregory Heytings
2021-11-04 0:06 ` Stefan Kangas
2021-11-04 18:09 ` Lars Ingebrigtsen
2022-09-20 11:55 ` Lars Ingebrigtsen
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).