emacs-languagetool / flymake-languagetool

Flymake support for LanguageTool
GNU General Public License v3.0
33 stars 11 forks source link

How to correct and accept the correction #26

Closed jcubic closed 6 months ago

jcubic commented 6 months ago

Since there are no documentation about this in README, I was just inspecting what functions are defined by the library. And written this:

(defun flymake-languagetool-action ()
  (interactive)
  (if (flymake-languagetool--ov-at-point)
      (flymake-languagetool-correct-at-point)))

(define-key flymake-mode-map (kbd "C-c C-a") 'flymake-languagetool-action)

Is there an easier (recommended) way to fix the spelling error?

Is there a way to call a single function that will accept the default correction? Calling flymake-languagetool-correct-at-point require pressing TAB twice to get the completion and type suggested value. But it would be nice if you can just call the function that accept if there is only one correction (so far I didn't see more than one).

tpeacock19 commented 6 months ago

The README does infact have a function in the section Corrections that essentially provides what you have written in flymake-languagetool-correct-dwim.

(defun flymake-languagetool-correct-dwim ()
  "DWIM function for correcting `flymake-languagetool' diagnostics."
  (interactive)
  (if-let ((ov (flymake-languagetool--ov-at-point)))
      (funcall #'flymake-languagetool-correct-at-point ov)
    (funcall-interactively #'flymake-languagetool-correct)))

However, I would suggest looking into using great package by Daniel Mendler called Jinx for your spell checking needs. I only use LanuageTool for the grammar functionality.

jcubic commented 6 months ago

Maybe I was not clear my code and flymake-languagetool-correct-dwim prompt to type the correction. You need to press TAB twice to get the list of actions, and then type the correction yourself (or first letter and press tab).

But is there a way to just correct the mistake without the prompt?

I think that each action you can pick from the menu should have its own function.

tpeacock19 commented 6 months ago

I imagine that you are using the default completion in Emacs and not another tool like Vertico. I have made some changes to the corrections in the latest commit (https://github.com/emacs-languagetool/flymake-languagetool/commit/73a1814db4cc387854d72828c0e188c9f5b4c661). Now it should bring up the completions for you automatically.

It will also default to have the first suggestion selected. So when you select flymake-languagetool-correct-dwim you can simply hit enter after to choose the first suggestion.

I would suggest looking into Vertico, Helm or iComplete Vertical for a better completion experience.

jcubic commented 6 months ago

Thanks for the suggestion, not a lot of people know, but you can use C-s inside minibuffer for completion. Adding completion tool will break this. e.g. I can use M-x C-s and search for the function with builtin search. They broke this feature in recent Emacs, but with help from developers (on Emacs devel mailing list) I was able to get it back.

tpeacock19 commented 6 months ago

Using isearch would not be necessary if you were using a solution I suggested. I'm not even quite sure what difference using that in the minibuffer to select a command would provide.

In my experience, there is very little offered by the default completion that is not matched or improved with Vertico. You may eventually reach the same conclusion.

However, I want to keep this on topic so just let me know how the latest commit treats you. Appreciate your interest and feedback.

jcubic commented 6 months ago

Yes, it works much better now. Thanks.