Open ghost opened 11 years ago
Overlays would not be easier to manage, because they need to be constantly updated as the buffer is changed. Currently, we get that for free.
I'm not convinced this issue is worth a near complete rewrite. It would probably also lead to conflicts with other packages where highlight-symbol then has too high a priority.
I don't think I'm going to do anything about this for now. Sorry.
Tide has a very similar feature called "Highlight Identifiers".
It just uses Overlays. L1337-L1434 is the implementation.
I use a tradeoff solution for this. When there is any highlighted symbol in current buffer, I change hl-line-mode
to start highlighting from the end of current line so the background created by highlight-symbol
can stay. Here's the configuration:
(defun hl-line-range-from-line-end ()
(cons (line-end-position) (line-beginning-position 2)))
(defun hl-line-range-from-line-beginning ()
(cons (line-beginning-position) (line-beginning-position 2)))
(defun user-highlight-symbol ()
"Highlight the selected text or symbol at point"
(interactive)
(funcall-try-region 'highlight-symbol)
(make-local-variable 'hl-line-range-function)
(if (> (length highlight-symbol-keyword-alist) 0)
(setq hl-line-range-function 'hl-line-range-from-line-end)
(setq hl-line-range-function 'hl-line-range-from-line-beginning)))
(defun user-highlight-symbol-remove-all ()
"Remove all highlighted symbols and restore hl-line-mode."
(interactive)
(highlight-symbol-remove-all)
(setq hl-line-range-function 'hl-line-range-from-line-beginning)
)
When I use isearch, the background of matches stays visible when it's on the current line, even though the current line has a background of its own (via hl-line-mode).
But when I use
highlight-symbol-at-point
, when a match is on the current line, it hides the match's "highlighted" background color.I'm guessing this is because isearch uses overlays and yours just propertizes the text within the buffer. Overlays would be easier to manage, too, since you just keep a list of them and when you want to un-highlight them, you just call
delete-overlay
on each.