Skip to content

Commit

Permalink
Simplify resizing
Browse files Browse the repository at this point in the history
Rely on the `resize-mini-windows' setting to behave correctly. On old Emacs
versions the resizing wasn't reliable.
  • Loading branch information
minad committed Dec 8, 2024
1 parent a0d5610 commit 5c4a2cb
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Drop obsolete command alias ~vertico-repeat-last~.
- ~vertico-buffer~: Use ~display-buffer-use-least-recent-window~ as default buffer
display action.
- Simplify the mini window resizing implementation, see ~vertico--resize~.

* Version 1.9 (2024-07-26)

Expand Down
2 changes: 1 addition & 1 deletion extensions/vertico-buffer.el
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
((and (not vertico-buffer-mode) vertico-buffer--restore)
(funcall vertico-buffer--restore))))))

(cl-defmethod vertico--resize-window (_height &context (vertico-buffer-mode (eql t))))
(cl-defmethod vertico--resize (&context (vertico-buffer-mode (eql t))))

(cl-defmethod vertico--setup :after (&context (vertico-buffer-mode (eql t)))
(vertico-buffer--setup))
Expand Down
6 changes: 4 additions & 2 deletions extensions/vertico-flat.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@
(when vertico-flat-mode
(push `(vertico--input . ,vertico-flat-map) minor-mode-map-alist)))

(cl-defmethod vertico--display-candidates (candidates &context (vertico-flat-mode (eql t)))
(cl-defmethod vertico--resize (&context (vertico-flat-mode (eql t)))
(setq-local truncate-lines nil
resize-mini-windows t)
resize-mini-windows t))

(cl-defmethod vertico--display-candidates (candidates &context (vertico-flat-mode (eql t)))
(move-overlay vertico--candidates-ov (point-max) (point-max))
(overlay-put
vertico--candidates-ov 'after-string
Expand Down
3 changes: 1 addition & 2 deletions extensions/vertico-reverse.el
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@
(let ((string (apply #'concat lines)))
(add-face-text-property 0 (length string) 'default 'append string)
(overlay-put vertico--candidates-ov 'before-string string)
(overlay-put vertico--candidates-ov 'after-string nil))
(vertico--resize-window (length lines)))
(overlay-put vertico--candidates-ov 'after-string nil)))

(provide 'vertico-reverse)
;;; vertico-reverse.el ends here
22 changes: 7 additions & 15 deletions vertico.el
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and PRED."
(vertico--update 'interruptible)
(vertico--prompt-selection)
(vertico--display-count)
(vertico--display-candidates (vertico--arrange-candidates))))
(vertico--display-candidates (vertico--arrange-candidates))
(vertico--resize)))

(defun vertico--goto (index)
"Go to candidate with INDEX."
Expand Down Expand Up @@ -604,23 +605,14 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and PRED."
"Update candidates overlay `vertico--candidates-ov' with LINES."
(move-overlay vertico--candidates-ov (point-max) (point-max))
(overlay-put vertico--candidates-ov 'after-string
(apply #'concat #(" " 0 1 (cursor t)) (and lines "\n") lines))
(vertico--resize-window (length lines)))
(apply #'concat #(" " 0 1 (cursor t)) (and lines "\n") lines)))

(cl-defgeneric vertico--resize-window (height)
"Resize active minibuffer window to HEIGHT."
(cl-defgeneric vertico--resize ()
"Resize active minibuffer window."
(setq-local truncate-lines (< (point) (* 0.8 (vertico--window-width)))
resize-mini-windows 'grow-only
resize-mini-windows vertico-resize
max-mini-window-height 1.0)
(unless truncate-lines (set-window-hscroll nil 0))
(unless (frame-root-window-p (active-minibuffer-window))
(unless vertico-resize (setq height (max height vertico-count)))
(let ((dp (- (max (cdr (window-text-pixel-size))
(* (default-line-height) (1+ height)))
(window-pixel-height))))
(when (or (and (> dp 0) (/= height 0))
(and (< dp 0) (eq vertico-resize t)))
(window-resize nil dp nil nil 'pixelwise)))))
(unless truncate-lines (set-window-hscroll nil 0)))

(cl-defgeneric vertico--prepare ()
"Ensure that the state is prepared before running the next command."
Expand Down

0 comments on commit 5c4a2cb

Please sign in to comment.