tumashu / vertico-posframe

GNU General Public License v3.0
106 stars 16 forks source link

Posframe moving between bottom and center #20

Closed goldfita closed 1 year ago

goldfita commented 2 years ago

I was using the following vertico multiform configuration, which seemed to be working fine. This would give me the custom posframe I configured in the center of the frame for find file and projectile find file. Everything else (well execute-extended-command and switch-to-buffer anyway) is in the default location at the bottom of the frame.

  (vertico-multiform-commands
   `((find-file posframe grid (vertico-count . ,tg/vertico-center-height))
     (consult-projectile-find-file posframe (vertico-count . ,tg/vertico-center-height)))))

But I noticed that lsp-find-reference was opening in the center, which I don't want. I don't understand why, but the following seemed to fix it at first.

  (vertico-multiform-commands
   `((find-file posframe grid (vertico-count . ,tg/vertico-center-height))
     (consult-projectile-find-file posframe (vertico-count . ,tg/vertico-center-height))
     (lsp-find-references (:not posframe))))

First I noticed that it was working when I invoke lsp-find-references directly, but when I use the right-click context menu, it would open in the center again. Then I started noticing that switch-to-buffer was opening in the center, which hadn't been an issue before. The behavior seems to be erratic. I believe it works fine if I leave out the last line, but then I get the posframe in the center, which makes it hard to preview results of find references.

This is v0.54.

tumashu commented 2 years ago

Maybe you can code your own position handler:

defcustom vertico-posframe-poshandler #'posframe-poshandler-frame-center
  "The posframe poshandler used by vertico-posframe."
  :type 'function)
goldfita commented 2 years ago

I'm afraid I don't understand your suggestion. I don't think a custom position handler will fix the issue. The problem is that it uses a posframe when it should be in the minibuffer.

goldfita commented 1 year ago

Here is the problem. Something happens when using find references and possibly other commands. Then switch buffer looks like this. This is the correct view for find file and consult, but not for switch buffer. switch_buffer_posframe

If I run find file (C-x C-f), then switch buffer again, it goes back to the correct spot in the minibuffer. switch_buffer_minibuf

goldfita commented 1 year ago

I just installed which-key-posframe, and now I have this problem immediately upon Emacs starting. When I comment out the vertico-posframe package, it seems to work fine.

tumashu commented 1 year ago

I know nothing about lsp-find-references, can you provide a min example to show this issue?

goldfita commented 1 year ago

I'll try to come up with something. I don't understand what's going on, and it seems to require multiple packages.

goldfita commented 1 year ago

OK, this is my entire Emacs init. Note that lsp-find-references is not defined, but it is defined on my system. Actually, you can put pretty much any symbol there and probably get the same behavior. So, if you open a new instance of Emacs and type either 'C-x b' or 'M-x', you'll get a posframe. Cancel and type 'C-x C-f'. Then cancel that and type 'C-x b' or 'M-x' again and note that you are now in the minibuffer.

I'm not sure if this is a legitimate configuration or what the behavior should be, but I feel fairly certain that you shouldn't get a different outcome after executing find-file. Whether or not this is the same issue as the original one I reported is not exactly clear, but the behavior is similar.

(require 'package)
(unless (package-installed-p 'use-package)
  (setq use-package-always-ensure t)
  (package-refresh-contents)
  (package-install 'use-package))

(eval-when-compile
  (require 'use-package))

(use-package posframe)
(use-package vertico
  :custom
  (vertico-multiform-commands
   `((find-file posframe grid (vertico-count . 40))
     (lsp-find-reference (:not posframe))))
  :config
  (vertico-mode)
  (vertico-multiform-mode))
;; Comment this out to make C-x b work first time
(use-package vertico-posframe
  :after (vertico posframe)
  :config
  (vertico-posframe-mode 1))

I'm a bit confused now why I still see a posframe when I comment out vertico-posframe. Does vertico force it to load?

Playing with this a bit more, it looks like the following line might fix these issues. I'll have to get back to you when I've had more time to observe it.

(t (:not posframe))
tumashu commented 1 year ago

if you use posframe-multiform, you should not enable vertico-posframe-mode globally by hand, for posframe-multiform-mode will do this job

tumashu commented 1 year ago

remove the below code

(use-package vertico-posframe :after (vertico posframe) :config (vertico-posframe-mode 1))

tumashu commented 1 year ago

I try to install lsp-mode and find that lsp-find-references seem to do not use vertico, so why do you configure it with vertico-multiform-commands?

goldfita commented 1 year ago

I don't understand what posframe-multiform is.

lsp-find-references seem to do not use vertico

Let me take another look at this. I didn't realize it wasn't using vertico.

tumashu commented 1 year ago
I don't understand what posframe-multiform is.

sorry, vertico-multiform-mode

tumashu commented 1 year ago

NOTE: vertico-posframe-mode will be activated/deactivated by vertico-multiform-mode dynamically when you add ‘posframe’ setting to vertico-multiform-commands, please do not enable vertico-posframe-mode globally at the moment.

goldfita commented 1 year ago

I haven't looked at the lsp code, but when I have vertico enabled, lsp-find-reference opens a multiline minibuffer that looks the same as other minibuffers using vertico and has up/down navigation and consult preview. When I have vertico disabled lsp-find-references opens the standard single line minibuffer.

I have the following configuration now. This seems to be working correctly.

  ;; vertico
  (vertico-multiform-commands
   `((find-file posframe grid (vertico-count . ,tg/vertico-center-height))
     (consult-projectile-find-file posframe (vertico-count . ,tg/vertico-center-height))
     (t (:not posframe))))

(use-package vertico-posframe
  :after (vertico posframe)
  :custom
  (vertico-posframe-parameters   '((left-fringe  . 8)
                                   (right-fringe . 8)))
  (vertico-posframe-border-width 2)
  (vertico-posframe-height       tg/vertico-center-height)
  (vertico-posframe-width        150)
  :config
 (set-face-background 'vertico-posframe-border "#FF79CF"))
tumashu commented 1 year ago

ok