I use this code (found here) to highlight a single line in black:
(defun find-overlays-specifying (prop pos)
(let ((overlays (overlays-at pos))
found)
(while overlays
(let ((overlay (car overlays)))
(if (overlay-get overlay prop)
(setq found (cons overlay found))))
(setq overlays (cdr overlays)))
found))
(defun highlight-or-dehighlight-line ()
(if (find-overlays-specifying
'line-highlight-overlay-marker
(line-beginning-position))
(remove-overlays (line-beginning-position) (+ 1 (line-end-position)))
(let ((overlay-highlight (make-overlay
(line-beginning-position)
(+ 1 (line-end-position)))))
(overlay-put overlay-highlight 'face '(:background "black"))
(overlay-put overlay-highlight 'line-highlight-overlay-marker t))))
(global-set-key [f9] (lambda () (interactive) (highlight-or-dehighlight-line)))
Now I want to make it more generic because I want to be able to use a few different colors. So I added a parameter color
to function highlight-or-dehighlight-line
, replaced "black"
with color
, and passed "black"
to highlight-or-dehighlight-line
:
(defun find-overlays-specifying (prop pos)
(let ((overlays (overlays-at pos))
found)
(while overlays
(let ((overlay (car overlays)))
(if (overlay-get overlay prop)
(setq found (cons overlay found))))
(setq overlays (cdr overlays)))
found))
(defun highlight-or-dehighlight-line (color)
(if (find-overlays-specifying
'line-highlight-overlay-marker
(line-beginning-position))
(remove-overlays (line-beginning-position) (+ 1 (line-end-position)))
(let ((overlay-highlight (make-overlay
(line-beginning-position)
(+ 1 (line-end-position)))))
(overlay-put overlay-highlight 'face '(:background color))
(overlay-put overlay-highlight 'line-highlight-overlay-marker t))))
(global-set-key [f9] (lambda () (interactive) (highlight-or-dehighlight-line "black")))
However, this does not seem to do anything and I cannot find my mistake. What's wrong with this code?