+(define-minor-mode global-hl-line-mode
+ "Global minor mode to highlight the line about point in the current window.
+With ARG, turn Global-Hl-Line mode on if ARG is positive, off otherwise.
+
+Global-Hl-Line mode uses the functions `global-hl-line-unhighlight' and
+`global-hl-line-highlight' on `pre-command-hook' and `post-command-hook'."
+ :global t
+ :group 'hl-line
+ (if global-hl-line-mode
+ (progn
+ (add-hook 'pre-command-hook #'global-hl-line-unhighlight)
+ (add-hook 'post-command-hook #'global-hl-line-highlight))
+ (global-hl-line-unhighlight)
+ (remove-hook 'pre-command-hook #'global-hl-line-unhighlight)
+ (remove-hook 'post-command-hook #'global-hl-line-highlight)))
+
+(defun global-hl-line-highlight ()
+ "Active the Global-Hl-Line overlay on the current line in the current window."
+ (when global-hl-line-mode ; Might be changed outside the mode function.
+ (unless (window-minibuffer-p (selected-window))
+ (unless global-hl-line-overlay
+ (setq global-hl-line-overlay (make-overlay 1 1)) ; to be moved
+ (overlay-put global-hl-line-overlay 'face hl-line-face))
+ (overlay-put global-hl-line-overlay 'window (selected-window))
+ (hl-line-move global-hl-line-overlay))))
+
+(defun global-hl-line-unhighlight ()
+ "Deactivate the Global-Hl-Line overlay on the current line."
+ (if global-hl-line-overlay
+ (delete-overlay global-hl-line-overlay)))
+
+(defun hl-line-move (overlay)
+ "Move the Hl-Line overlay.
+If `hl-line-range-function' is non-nil, move the OVERLAY to the position
+where the function returns. If `hl-line-range-function' is nil, fill
+the line including the point by OVERLAY."
+ (let (tmp b e)
+ (if hl-line-range-function
+ (setq tmp (funcall hl-line-range-function)
+ b (car tmp)
+ e (cdr tmp))
+ (setq tmp t
+ b (line-beginning-position)
+ e (line-beginning-position 2)))
+ (if tmp
+ (move-overlay overlay b e)
+ (move-overlay overlay 1 1))))