I am using
$ emacs --version
GNU Emacs 29.0.50
Development version 53c0690fa28f on master branch; build date 2022-07-07.
- Download https://www.emacswiki.org/emacs/download/highlight.el and put it under
~/src/elisp/highight.el
.
- Copy the below snippet in to a file
~/highlight-line.el
;; Ability to highlight lines
;; https://www.emacswiki.org/emacs/download/highlight.el
(load-file "~/src/elisp/highlight.el")
(defvar hlt-highlight-line-direction 1)
(defun hlt-highlight-line (start end face msgp)
(interactive
(list (save-excursion (point-at-bol))
(save-excursion (point-at-eol))
nil
t))
(hlt-highlight-region start end face msgp)
(forward-line hlt-highlight-line-direction))
(defun hlt-unhighlight-line (start end face msgp)
(interactive (list (save-excursion (point-at-bol))
(save-excursion (point-at-eol))
nil
t))
(hlt-unhighlight-region start end face msgp)
(forward-line (* -1 hlt-highlight-line-direction)))
(defun hlt-highlight-toggle-line-direction ()
(interactive)
(setq hlt-highlight-line-direction
(* -1 hlt-highlight-line-direction)))
(define-key hlt-map (kbd "l") 'hlt-highlight-line)
(define-key hlt-map (kbd "L") 'hlt-unhighlight-line)
(define-key hlt-map (kbd "X") 'hlt-highlight-toggle-line-direction)
;; (setq repeat-keep-prefix nil)
(defun make-keymap-repeatable (sym)
(map-keymap
(lambda (_key cmd)
(when (symbolp cmd)
(message "%-20s -> `%S'" (single-key-description _key) cmd)
(put cmd 'repeat-map sym)))
(symbol-value sym))
(repeat-mode -1)
(repeat-mode 1))
(make-keymap-repeatable 'hlt-map)
emacs -Q
C-x C-f highlight-line.el
M-x eval-buffer <return>
- Do some highlights
C-x C-x X l l l l l l
- Switch face with
n
- Do some more highights with
l l l l l l
- Do some unhighights with
L L L L L
- Switch face with
n
- Do some more highlights with
l l l l
- Move down few lines
<down> <down> <down> <down> <down> <down>
- Start highlighting again with
C-x X l l
.
This is what you will see

- At the end if you want to remove all the highlights do
C-x X u r
.
You can repeat the above procedure by eval
-ing the below macro, and doing M-x highlight-line-demo
(defalias 'highlight-line-demo
(kmacro "<f11> C-x C-f h i g h l i g h t - l i n e . e l <return> M-x e v a l - b u f f e r <return> C-x X l l l l l l n l l l l l l L L L L L n l l l l <down> <down> <down> <down> <down> <down> C-x X l l C-x 3 M-x v i e w - l o s s a g e <return> "))