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

From: Gregory Heytings <[email-masked]>
Date: Wed, 03 Nov 2021 13:11:24 +0000

And just in case, here's a patch with that command.

From c747dd022d133133ae9d43ca137f87f2e8203e4d Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
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