> You should be able to fix this problem by setting
> hl-line-range-function to a suitable function (which should be quite
> simple, AFAIU).
Not really. I tried, setting hl-line-range-function to the next-error
buffer message line after turning on hl-line:
> (with-current-buffer next-error-last-buffer
> (make-variable-buffer-local 'hl-line-range-function)
> (setf hl-line-range-function
> (lambda ()
> (save-excursion
> (goto-char compilation-current-error)
> (let ((range
> (cons (line-beginning-position) (line-end-position))))
> (message "hl-line-range-function caled. range is %s" range)
> range)))))
See gif below where hl-line-function is not called after commands invoked outside of the next-error buffer:
> Basically, the difference is that hl-line uses post-command-hooks to track the current line and put an overlay
> on it, whereas in this case highlighting only changes whenever next-error-hook is invoked.
>>
>> Is this really important? Those are just implementation details, no?
No, this is exactly the reason why hl-line-range-function doesn't work in the above example. These are
different concepts with different hooks involved that are invoked under different conditions.
post-command-hook means hook is invoked after movement commands, which should not affect err msg line
highlighting, it also means that it may not necessarily be invoked upon next-error.
hl-line-mode hooks:
> (if hl-line-mode
> (progn
> ;; In case `kill-all-local-variables' is called.
> (add-hook 'change-major-mode-hook #'hl-line-unhighlight nil t)
> (hl-line-highlight)
> (setq hl-line-overlay-buffer (current-buffer))
> (add-hook 'post-command-hook #'hl-line-highlight nil t)
> (add-hook 'post-command-hook #'hl-line-maybe-unhighlight nil t))
> (remove-hook 'post-command-hook #'hl-line-highlight t)
> (hl-line-unhighlight)
> (remove-hook 'change-major-mode-hook #'hl-line-unhighlight t)
> (remove-hook 'post-command-hook #'hl-line-maybe-unhighlight t)))
Whereas for this enhancement, the only event that affects highlight region is next-error.
Additionally, hl-line and error message highlight and face should be independent:
the user may want current-line highlighting in addition to error message highlighting.