emacs-languagetool/flymake-languagetool

How to correct and accept the correction

Closed this issue · 6 comments

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).

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.

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.

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 (73a1814). 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.

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.

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.

Yes, it works much better now. Thanks.