unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 3faa29461152ea7a735355013f12519be200b241 5359 bytes (raw)
name: lisp/hl-line.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
 
;;; hl-line.el --- highlight the current line  -*- lexical-binding:t -*-

;; Copyright (C) 1998, 2000-2022 Free Software Foundation, Inc.

;; Author: Dave Love <fx@gnu.org>
;; Maintainer: emacs-devel@gnu.org
;; Created: 1998-09-13
;; Keywords: faces, frames, emulations

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;  Proper scuttling of unsticky overlays relies on `post-command-hook`
;;  being called on a buffer switch and the stationarity of
;;  `hl-line--buffer` across switches.  One could easily imagine
;;  programatically defeating unsticky overlays by bypassing
;; `post-command-hook`.

;;; Code:

(make-obsolete-variable 'hl-line-overlay 'hl-line--overlay "29.1")
(make-obsolete-variable 'global-hl-line-overlay nil "29.1")
(make-obsolete-variable 'global-hl-line-overlays nil "29.1")
(make-obsolete-variable 'global-hl-line-sticky-flag nil "29.1")
(make-obsolete-variable 'hl-line-overlay-buffer 'hl-line--buffer "29.1")
(make-obsolete-variable 'hl-line-range-function nil "29.1")

(defvar-local hl-line--overlay nil
  "The prevailing highlighting overlay per buffer.")

(defvar hl-line--buffer nil
  "Track last buffer in lieu of nontrivial inference from
`window-prev-buffers`.")

;; 1. define-minor-mode creates buffer-local hl-line--overlay
;; 2. overlay wiped by kill-all-local-variables
;; 3. post-command-hook dupes overlay
;; Solution: prevent step 2.
(put 'hl-line--overlay 'permanent-local t)

(defgroup hl-line nil
  "Highlight the current line."
  :version "21.1"
  :group 'convenience)

(defface hl-line '((t :inherit highlight :extend t))
  "Default face for highlighting the current line in hl-line-mode."
  :version "22.1"
  :group 'hl-line)

(defcustom hl-line-face 'hl-line
  "Face with which to highlight the current line in Hl-Line mode."
  :type 'face
  :group 'hl-line
  :set (lambda (symbol value)
	 (set symbol value)
	 (dolist (buffer (buffer-list))
	   (with-current-buffer buffer
	     (when hl-line--overlay
	       (overlay-put hl-line--overlay 'face hl-line-face))))))

(defcustom hl-line-sticky-flag t
  "Non-nil to preserve highlighting overlay when focus leaves window."
  :type 'boolean
  :version "22.1"
  :group 'hl-line
  :initialize #'custom-initialize-default
  :set (lambda (symbol value)
         (set-default symbol value)
         (unless value
           (let ((selected (window-buffer (selected-window))))
             (dolist (buffer (buffer-list))
               (unless (eq buffer selected)
                 (with-current-buffer buffer
                   (hl-line-unhighlight))))))))

(defcustom hl-line-overlay-priority -50
  "Priority used on the overlay used by hl-line."
  :type 'integer
  :version "22.1"
  :group 'hl-line)

(defcustom hl-line-highlight-hook nil
  "After hook for `hl-line-highlight'.
Currently used in calendar/todo-mode."
  :type 'hook
  :group 'hl-line)

;;;###autoload
(define-minor-mode hl-line-mode
  "Toggle highlighting of the current line."
  :group 'hl-line
  (if hl-line-mode
      (progn
        (hl-line-highlight)
        (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t)
	(add-hook 'post-command-hook #'hl-line-highlight nil t))
    (remove-hook 'post-command-hook #'hl-line-highlight t)
    (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t)
    (hl-line-unhighlight)))

(defun hl-line-unhighlight ()
  (when hl-line--overlay
    (delete-overlay hl-line--overlay)
    (setq hl-line--overlay nil)))

(defun hl-line-highlight ()
  (unless (minibufferp)
    (unless hl-line--overlay
      (setq hl-line--overlay
            (let ((ol (make-overlay (point) (point))))
              (prog1 ol
                (overlay-put ol 'priority hl-line-overlay-priority)
                (overlay-put ol 'face hl-line-face)))))
    (move-overlay hl-line--overlay
                  (line-beginning-position)
                  (line-beginning-position 2))
    (when (and (not (eq hl-line--buffer (current-buffer)))
               (not hl-line-sticky-flag)
               (buffer-live-p hl-line--buffer))
      (with-current-buffer hl-line--buffer
        (hl-line-unhighlight)))
    (setq hl-line--buffer (current-buffer))
    (run-hooks 'hl-line-highlight-hook)))

(defun hl-line-turn-on ()
  (unless (minibufferp)
    (let (inhibit-quit)
      (hl-line-mode 1))))

(defun hl-line-unload-function ()
  "Unload the Hl-Line library."
  (global-hl-line-mode -1)
  (save-current-buffer
    (dolist (buffer (buffer-list))
      (set-buffer buffer)
      (when hl-line-mode (hl-line-mode -1))))
  ;; continue standard unloading
  nil)

;;;###autoload
(define-globalized-minor-mode global-hl-line-mode
  hl-line-mode hl-line-turn-on
  :group 'hl-line
  :version "29.1")

(provide 'hl-line)

;;; hl-line.el ends here

debug log:

solving 3faa2946115 ...
found 3faa2946115 in https://yhetil.org/emacs-bugs/87a6di3wkj.fsf@dick/ ||
	https://yhetil.org/emacs-bugs/87bkxy3wkx.fsf@dick/
found 70ba0fcfc28 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 70ba0fcfc286d3b55baabebf02d059c6058dde7e	lisp/hl-line.el

applying [1/1] https://yhetil.org/emacs-bugs/87a6di3wkj.fsf@dick/
diff --git a/lisp/hl-line.el b/lisp/hl-line.el
index 70ba0fcfc28..3faa2946115 100644

Checking patch lisp/hl-line.el...
Applied patch lisp/hl-line.el cleanly.

skipping https://yhetil.org/emacs-bugs/87bkxy3wkx.fsf@dick/ for 3faa2946115
index at:
100644 3faa29461152ea7a735355013f12519be200b241	lisp/hl-line.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).