tumashu / vertico-posframe

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

Feature request: Per command posframe position like ivy-posframe #24

Closed farazshaikh closed 1 year ago

farazshaikh commented 1 year ago

Ivy posframe position can be customized per command using the following

(setq ivy-posframe-display-functions-alist
          '((swiper-isearch  . ivy-posframe-display-at-window-bottom-left)
            (complete-symbol . ivy-posframe-display-at-point)
            (counsel-M-x     . ivy-posframe-display-at-point)
            (counsel-mark-ring . ivy-posframe-display-at-window-bottom-left)
            (ivy-switch-buffer . ivy-posframe-display-at-window-bottom-left)
            (t               . ivy-posframe-display-at-point)))

With the above feature vertico-posframe is very difficult to use, esp for commands like consult-line (swiper-eqivalent). The posframe blocks the search results.

It's ideal to sometimes have the posframe displayed at point, and sometimes at the bottom of the frame.

tumashu commented 1 year ago

maybe useful https://github.com/minad/vertico/blob/main/extensions/vertico-multiform.el

farazshaikh commented 1 year ago

Vertico multi form controls the layout vertico contents ie to display content as grid, vs a list. It won't help to position the pos frame.

At a minimum, there should be a way to disable posframe completely for certain command like vertico-line and display content in the mini buffer instead

tumashu commented 1 year ago

you can try the below config:

(setq vertico-multiform-commands
      '((consult-imenu buffer)
        (t posframe)))

(vertico-multiform-mode 1)

(setq vertico-posframe-poshandler
      #'my-vertico-posframe-poshandler)

(defun my-vertico-posframe-poshandler (info)
  (pcase this-command
    (`complete-symbol (posframe-poshandler-frame-top-center info))
    (`consult-line  (posframe-poshandler-frame-bottom-center info))
    (t  (posframe-poshandler-frame-center info))))
farazshaikh commented 1 year ago

With the above snippet, the consult-line posframe starts at the bottom center. But, as soon as you type anything, the posframe moves back to the center of the window.

Thanks -Fs

 (use-package vertico
    :init
    (vertico-mode)
    (vertico-multiform-mode)
    :bind (:map vertico-map
                ("M-v" . #'vertico-multiform-vertical)
                ("M-g" . #'vertico-multiform-grid)
                ("M-f" . #'vertico-multiform-flat)
                ("M-R" . #'vertico-multiform-reverse)
                ("M-u" . #'vertico-multiform-unobtrusive))
    :config
    ;; Different scroll margin
    ;; (setq vertico-scroll-margin 0)

    ;; Show more candidates
    ;; (setq vertico-count 20)

    ;; Grow and shrink the Vertico minibuffer
    ;; (setq vertico-resize t)

    ;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
    (setq vertico-cycle t))

  (use-package vertico-posframe
    :disabled
    :init
    (vertico-posframe-mode)
    :config
    (setq vertico-posframe-poshandler #'posframe-poshandler-window-bottom-center)) 
tumashu commented 1 year ago

try this:

(setq vertico-multiform-commands
      '((consult-imenu buffer)
        (t posframe)))

(vertico-multiform-mode 1)

(setq vertico-posframe-poshandler
      #'my-vertico-posframe-poshandler)

(defun my-vertico-posframe-poshandler (info)
  (cond
   ((my-cmdp 'complete-symbol) (posframe-poshandler-frame-top-center info))
   ((my-cmdp `consult-line)  (posframe-poshandler-frame-bottom-center info))
   ((my-cmdp `consult-recent-file)  (posframe-poshandler-frame-bottom-center info))
   (t  (posframe-poshandler-frame-center info))))

(defun my-cmdp (cmd)
  (or (equal this-command cmd)
      (equal last-command cmd)))
farazshaikh commented 1 year ago

Same behavior, box moves to the center start end

tumashu commented 1 year ago

Update to newest code, and try:

(setq vertico-multiform-commands
      '((consult-line posframe (vertico-posframe-poshandler . posframe-poshandler-frame-top-center))
        (t buffer)))
farazshaikh commented 1 year ago

Thanks it works, I had to add the posframe position for default case.

  (setq vertico-multiform-commands
        '((consult-line posframe (vertico-posframe-poshandler . posframe-poshandler-frame-bottom-center))
          (consult-buffer posframe (vertico-posframe-poshandler . posframe-poshandler-frame-bottom-center))
          (t posframe (vertico-posframe-poshandler . posframe-poshandler-point-bottom-left-corner))))

2022-12-18_20-59um 2022-12-18_21-00 2022-12-18_21-02 2022-12-18_21-02_1

tumashu commented 1 year ago

ok