The thing I want to do is to highlight regions in a file covered by jest JavaScript tests. For testing I'm in an .emacs
buffer, and I'm trying to highlight a single line in another buffer that I have opened in a different window.
I was looking at this question, which uses hlt-highlight-region
from library Highlight, but I'm not able to make this work.
I have code like this that should change the single line's background to green:
(let* ((dir "/home/kuba/projects/jcubic/terminal/repo")
(buffer (get-file-buffer (concat dir "/js/jquery.terminal-src.js")))
(start '((line . 3156) (column . 0)))
(end '((line . 3156) (column . 18))))
(with-current-buffer buffer
(let* ((start-line-pos (line-beginning-position (cdr (assoc 'line start))))
(start-pos (+ start-line-pos (cdr (assoc 'column start))))
(end-line-pos (line-beginning-position (cdr (assoc 'line end))))
(end-pos (+ end-line-pos (cdr (assoc 'column end)))))
(hlt-highlight-region start-pos end-pos '((t (:background "green")))))))
But the code is returning nil
and nothing happens. What's wrong with this code?
(hlt-highlight-region N1 N2 '((t (:background "green")))
, at least. If you just do that, with two buffer positions forN1
andN2
then you'll see that it works. Try inserting(message "START: %S, END: %S" start-pos end-pos)
just before the call tohlt-highlight-region
, to see what values those vars have. Or useM-x debug-on-entry
followed by the name of your function, and walk through the debugger withd
orc
to see what happens.line-beginning-position
accepts a number of lines to move. It returns the buffer position of the beginning of the line that it arrives at after that move. (The move is temporary/simulated - point is left where it was initially.) If you want the position of the beginning of the current line then don't pass an argument.