Closed fikovnik closed 4 years ago
Hey Filip,
That's a great idea. Thank you for sharing it. I am in travel mode, and will implement it once I am back to route.
On Sat, May 25, 2019 at 19:50, Filip Krikava notifications@github.com wrote:
First, thank you for this package! Perhaps it can be achieved by other means, but I was wondering if it would be possible to add a custom face that would highlight the word that is currently being corrected?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
Was thinking the same and noticed that ispell-word
is doing this. So I copied what is needed from ispell-word
and added an advice before and after flyspell-correct-at-point
to highlight and unhighlight the current spelling error. Seems to work so far.
When ispell-lazy-highlight
is non-nil (default), all text in the buffer matching the current spelling
error is highlighted lazily using isearch lazy highlighting. This might be a little bit strange in a prog-mode
as not only words in comments or strings are highlighted.
This would probably be trivial to add as a feature. Don't have the time to make a pull request unfortunately.
(defvar my-feat-spell-check/highlight-spelling-window nil
"Window which has highlighted spellings.")
(defun my-feat-spell-check/flyspell-overlay-start-and-end ()
"Return `cons' with start and end of `flyspell' overlay at point.
Returns nil if no overlay is found."
(let ((ovs (overlays-at (point)))
ov)
(while (and (not ov) ovs)
(let ((current (pop ovs)))
(when (flyspell-overlay-p current)
(setq ov current))))
(when ov
(let ((ov-start (overlay-start ov))
(ov-end (overlay-end ov)))
(cons ov-start ov-end)))))
(defun my-feat-spell-check/highlight-spelling-error ()
"Highlight the spelling error at point."
(setq my-feat-spell-check/highlight-spelling-window (selected-window))
(when-let ((ov (my-feat-spell-check/flyspell-overlay-start-and-end))
(ov-start (car ov))
(ov-end (cdr ov)))
(ispell-highlight-spelling-error ov-start ov-end t)))
(defun my-feat-spell-check/unhighlight-spelling-error ()
"Highlight the spelling error at point."
(save-window-excursion
(select-window my-feat-spell-check/highlight-spelling-window)
(ispell-highlight-spelling-error nil nil)))
(advice-add 'flyspell-correct-at-point :before #'my-feat-spell-check/highlight-spelling-error)
(advice-add 'flyspell-correct-at-point :after #'my-feat-spell-check/unhighlight-spelling-error)
Wow, thank you for sharing the code. Will take a look on my weekends.
I tried it, but it seems it doesn't play nicely with overlays from flyspell
.
Works here. What you mean by not playing nicely so I can test it in my setup?
Forgot to mention, had to set an ispell variable (had to reload emacs after).:
(setq ispell-highlight-face 'isearch)
;; defcustom ispell-highlight-face (if ispell-lazy-highlight 'isearch 'highlight)
Before correct:
While correcting (avy-menu interface):
Afterwards:
Ok, there is something funky with my faces, that's why I didn't see the difference. Thanks for pointing out the value of ispell-highlight-face
.
@hubisan I've created a PR based on your code. Would be grateful for your review ;)
@fikovnik, @gusbrs, @hubisan the feature is now available on master. Give some time for MELPA to build it :)
P. S. Don't have any plans for stable MELPA. So let me know if you really-really need it there.
I'm trying it out here already, and it looks very nice indeed.
Thank you very much @d12frosted and @hubisan !
First, thank you for this package! Perhaps it can be achieved by other means, but I was wondering if it would be possible to add a custom face that would highlight the word that is currently being corrected?