radian-software / selectrum

đź”” Better solution for incremental narrowing in Emacs.
MIT License
739 stars 33 forks source link

Fix buffer error with selectrum-display-action #572

Closed TikhonJelvis closed 2 years ago

TikhonJelvis commented 3 years ago

This fixes the error described in #571.

When using selectrum-display-action, selectrum--update would raise the following error when the candidate list is empty (eg calling find-file from an empty directory):

Error in post-command-hook (selectrum--update): (error "No buffer named  *selectrum*")

Poking around in selectrum.el, I found this happens because selectrum--update uses selectrum--display-action-buffer:

(if selectrum-display-action
    ;; Insert candidates into action buffer.
    (with-current-buffer selectrum--display-action-buffer
      (erase-buffer)
      (insert inserted-string))
  ...)

selectrum--display-action-buffer is created in selectrum--get-display-window, but selectrum--update explicitly does not call selectrum--get-display-window when the candidate list is empty:

(let* (...
       (window (if selectrum-display-action
                   (and selectrum--refined-candidates
                        (selectrum--get-display-window))
                 (active-minibuffer-window)))
       ...)
  ...)

With my setup, removing the check fixes the problem.

I'm not sure if this is a general solution—I assume the check is there for a reason, but I don't know what that is :).

TikhonJelvis commented 3 years ago

Ah, after using my fix for a bit longer, I think I found the reason for the check—seems that without it, a window briefly pops up in the wrong place before being populated and moved to where it should be.

For now that's still better than the error I was getting earlier, but I can investigate a bit more and see if there's a fix that doesn't create this problem.

TikhonJelvis commented 3 years ago

Oh, never mind, the window flickering issue is present either way—I guess it's an artifact of my posframe configuration that I just never noticed before modifying and testing the code in this PR. The problem remains with or without the change in this PR.

I'll have to investigate that separately. In the meantime, the change in this PR fixes the problem I was seeing. I've been using the modification from this PR for a few hours of active work in Emacs now and it has been working well.

okamsn commented 2 years ago

Thank you. I opted to just make sure the buffer exists in #587. The behavior of not displaying the buffer until it has candidates has been kept since it seems intentional, but the problem itself should be fixed.

TikhonJelvis commented 2 years ago

Awesome, thanks for the fix. Sounds like you've thought through how to fix the error while minimizing changes that could affect anything else—better than the workaround I came up with :)