flyg0dx__ · 2022-03-12 16:47
Hi all, I'm looking into writing some new functionality for emacs and as part of it need to be able to dynamically highlight individual characters, I've looked into messing with `font-lock-mode` briefly but that seems to be more geared to syntax highlighting based on regex.
I also tried using `put-overlay` and am now trying the `highlight.el` package but the way I've written it so far doesn't actually work and I'm not sure why. Can anyone point me in a better direction if this ain't the way/tell me where I'm screwing up?
first I define a face:
(defface position-1-face
'((t (:foreground "#FF0000" :weight bold)))
"The face for the first increment out of from the cursor"
:group 'increment-faces)
Then I apply it like this
(when (<= plus (point-max))
(hlt-highlight-region plus plus 'position-1-face))
(when (>= neg (point-min))
(hlt-highlight-region neg neg 'position-1-face))
Where `plus` and `neg` are values that are 10 characters from the current point in either direction. My eventual goal with this is to have characters like 10, 20 and 30 characters out from the cursor highlighted so I can jump around more easily without having to figure out distances.
I know the faces are getting applied from the output of `describe-char` but they do not seem to actually show up.
Ideally I'd like to drop the dependence on `highlight.el` so if there is a better built in way then please do let me know
00-11 · 2022-03-12 20:40
I don't quite understand what you're trying to do; sorry.
> I know the faces are getting applied from the output of describe-char but they do not seem to actually show up.
If the `START` and `END` args to `hlt-highlight-region` are the same, as they are in your code, then you've effectively highlighted ***no*** characters. If you want to highlight a region of one character then buffer position `START` should be one less than `END`.
organic-bookworm · 2022-03-12 20:48
> tell me where I'm screwing up
Pretty sure it's because of empty region
(hlt-highlight-region plus plus 'position-1-face)
For 1 char region do
(hlt-highlight-region plus (+ plus 1) 'position-1-face)
> Ideally I'd like to drop the dependence on `highlight.el`
See [Overlays](https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html).
(let ((ov (make-overlay neg (+ neg 1))))
(overlay-put ov 'face 'position-1-face))
organic-bookworm · 2022-03-12 20:51
> My eventual goal \[...\] jump around more easily
Don't mean to discourage your experiments, but check out [avy](https://github.com/abo-abo/avy/tree/master).
> jumping to visible text using a char-based decision tree
flyg0dx__ · 2022-03-12 22:31
Cheers man, fixed it with this
flyg0dx__ · 2022-03-12 22:31
> Don't mean to discourage your experiments, but check out avy.
Checked out avy before, while cool its not precisely what im after
dpoggio · 2022-03-13 07:18
Changing properties is enough. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Properties.html and remember than many times you need to change on `font-lock-face` instead of `face`, because `font-lock` is active. Also, see `add-text-properties` here: https://www.gnu.org/software/emacs/manual/html_node/elisp/Changing-Properties.html