Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iSeeU816 opened this issue Dec 3, 2020 · 3 comments
Open

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

iSeeU816 opened this issue Dec 3, 2020 · 3 comments

Comments

@iSeeU816
Copy link

iSeeU816 commented Dec 3, 2020

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

  • After step 9, if you make second line in the buffer's view visible; everything
    function as it should. Also, if the text was in first line.
  • avy-side-window is acting normal, which is what I'm using now.
  • I thought it's related to scroll-margin variable when it set to something
    else than zero, but it's not.

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

  • Emacs 27.1 (8.0; Emacs Mac port)
  • frog-menu-0.2.11
  • avy-20200624.1148; 0.5.0
  • posframe-20201201.659; 0.8.3
  • flyspell-correct-20200904.526; 0.6.1
@clemera
Copy link
Owner

clemera commented Dec 4, 2020

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
Copy link
Author

iSeeU816 commented Dec 4, 2020

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
Copy link
Owner

clemera commented Dec 4, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants