muffinmad / emacs-mini-frame

Show minibuffer in child frame on read-from-minibuffer
GNU General Public License v3.0
321 stars 20 forks source link

Redirect frame focus #37

Closed Stebalien closed 3 years ago

Stebalien commented 3 years ago

Sometimes, especially when running an interactive command with slow completion results (flyspell, consult-lines, etc.):

  1. I'll run the command.
  2. I'll start typing before the mini-frame shows up.
  3. When the frame shows up, my input focus will not properly switch to the new frame.

I've found this can bey fixed by calling (redirect-frame-focus selected-frame mini-frame-frame) right before (make-frame-visible mini-frame-frame) in mini-frame--display. This also doesn't appear to have any unwanted side effects.

I'm submitting this as a bug report, not a patch, as:

  1. I'm not sure why this is happening.
  2. Given this fix, I'd assume that the mini-frame would keep focus (making it impossible to interact with the rest of emacs while the mini-frame is in use). However, this is not the case.
muffinmad commented 3 years ago

There were similar issue #23

I think the redirect-frame-focus function is the great solution. I'll add it, thanks for the great idea!

muffinmad commented 3 years ago

@Stebalien Can you provide some receipt to reproduce this? I've tested the following code with the selectrum-mode enabled:

(completing-read
 "foo: "
 (letrec ((table
       (lazy-completion-table
        table
        (lambda ()
          (call-process "sleep" nil nil nil "3")
          (list "bar1" "bar2" "bar3")))))))

All the keys goes to the minibuffer frame.

Stebalien commented 3 years ago

Yeah, that didn't do it for me either. My reproduction process is:

  1. Open a large org mode file with lots of org source blocks.
  2. Run consult-line.

Unlike with the command above, there's a delay between running consult-line and actually displaying the mini-frame. Looking at a profile, it might be due to fontification/display.

muffinmad commented 3 years ago
  1. Open a large org mode file with lots of org source blocks.
  2. Run consult-line.

Thanks, I can reproduce it as well. Not sure about the reason of such behavior, maybe some hook in the minibuffer-setup-hook. I've added redirect-frame-focus as you suggested but after make-frame-visible. Hope this solves your issue.

Stebalien commented 3 years ago

After appears to work just as well. Thanks!