clemera / frog-menu

Quickly pick items from ad hoc menus in Emacs
https://with-emacs.com/posts/frog-menu/catch-flyspell-errors-using-frog-menus/
106 stars 7 forks source link

Bug: Posframe UI covers misspelled word's line #12

Open iSeeU816 opened 3 years ago

iSeeU816 commented 3 years ago

Hello,

While I'm testing this package I fall into a bug causing the line where the misspelled word to be covered with Posframe UI; that makes choosing the proper word hard as its context is hidden.

The bug

Here are the steps to reproduce this bug:

  1. Paste this in a new init file.
(add-to-list 'load-path (concat user-emacs-directory "test"))

(require 'flyspell-correct)
(require 'frog-menu)

;; From: https://github.com/clemera/frog-menu
(defun frog-menu-flyspell-correct (candidates word)
  "Run `frog-menu-read' for the given CANDIDATES.

List of CANDIDATES is given by flyspell for the WORD.

Return selected word to use as a replacement or a tuple
of (command . word) to be used by `flyspell-do-correct'."
  (let* ((corrects (if flyspell-sort-corrections
                       (sort candidates 'string<)
                     candidates))
         (actions `(("C-s" "Save word"         (save    . ,word))
                    ("C-a" "Accept (session)"  (session . ,word))
                    ("C-b" "Accept (buffer)"   (buffer  . ,word))
                    ("C-c" "Skip"              (skip    . ,word))))
         (prompt   (format "Dictionary: [%s]"  (or ispell-local-dictionary
                                                   ispell-dictionary
                                                   "default")))
         (res      (frog-menu-read prompt corrects actions)))
    (unless res
      (error "Quit"))
    res))

(setq flyspell-correct-interface #'frog-menu-flyspell-correct)
  1. Place source code of these libraries into test directory:

    • flyspell-correct.el.
    • frog-menu.el.
    • avy.el.
    • posframe.el.
  2. Launch Emacs.

  3. C-x b and type foo.txt to create a dump buffer and then hit RET (return/enter).

  4. Enable Flyspell mode M-x flyspell-mode RET.

  5. Type this in foo.txt buffer:

    <note_1>
    There is something coool over there.
    <note_2>
    Check now.<cursor_position>
  6. Fro <note_1> make sure it's empty. As for <note_2> keep hitting return or enter to make the text in line two disappear from the buffer's view.

  7. In <cursor_position>, call M-x flyspell-correct-wrapper.

  8. Notice how the line (2nd line where the text is) is covered with Posframe UI.

Notes

Thank you for this package. Before this, I had to type save in Minibuffer as I couldn't assign a command to type that for me in default flyspell-correct interface using Embark package. Anyway, now all good with a simple keybinding C-s!

Software info

clemera commented 3 years ago

Thanks, I can reproduce it. Maybe this is a problem of posframe position function when scrolling is involved. As a temporary workaround you could include the word into the prompt so you at least know which word is queried for:

(defun frog-menu-flyspell-correct (candidates word)
  "Run `frog-menu-read' for the given CANDIDATES.

List of CANDIDATES is given by flyspell for the WORD.

Return selected word to use as a replacement or a tuple
of (command . word) to be used by `flyspell-do-correct'."
  (let* ((corrects (if flyspell-sort-corrections
                       (sort candidates 'string<)
                     candidates))
         (actions `(("C-s" "Save word"         (save    . ,word))
                    ("C-a" "Accept (session)"  (session . ,word))
                    ("C-b" "Accept (buffer)"   (buffer  . ,word))
                    ("C-c" "Skip"              (skip    . ,word))))
         (prompt   (format "Word: [%s], Dictionary: [%s]"
                           word
                           (or ispell-local-dictionary
                               ispell-dictionary
                               "default")))
         (res      (frog-menu-read prompt corrects actions)))
    (unless res
      (error "Quit"))
    res))

Alternatively you could also use the side window type which does not has this problem:

(setq frog-menu-type-function
      (lambda () 'avy-side-window))
iSeeU816 commented 3 years ago

You're welcome.

Maybe, but I'm afraid I've no idea. I could file an issue in Posframe tracker but I don't know any technical details of the package.

Thanks for the improvement of the function, I thought about having the word with the UI to help knowing what word to correct. A little mixed up in the function regarding the order that %s was assigned to; I mean word will have dictionary output, and vice versa.

Alternatively you could also use the side window type which does not has this problem:

I have created a function to handle this, but your way is much better, thanks.

clemera commented 3 years ago

A little mixed up in the function regarding the order that %s was assigned to; I mean word will have dictionary output, and vice versa.

Thanks, edited the example!