Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include line spacing when using fixed vertical window height #432

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog].
canonical representation of a candidate has been removed ([#403]).

### Features
* Line spacing is taken into account when using a fixed window height
([#424], [#432]).
* The new option `selectrum-max-window-height` can now be used to
configure the maximal display window height analogue to the built-in
`max-mini-window-height`. The new option replaces the usage of the
Expand Down Expand Up @@ -368,11 +370,13 @@ The format is based on [Keep a Changelog].
[#413]: https://github.com/raxod502/selectrum/pull/413
[#414]: https://github.com/raxod502/selectrum/pull/414
[#420]: https://github.com/raxod502/selectrum/issues/420
[#424]: https://github.com/raxod502/selectrum/issues/424
[#425]: https://github.com/raxod502/selectrum/issues/425
[#421]: https://github.com/raxod502/selectrum/pull/421
[#427]: https://github.com/raxod502/selectrum/issues/427
[#430]: https://github.com/raxod502/selectrum/pull/430
[#431]: https://github.com/raxod502/selectrum/pull/431
[#432]: https://github.com/raxod502/selectrum/pull/432

## 3.0 (released 2020-10-20)
### Breaking changes
Expand Down
33 changes: 17 additions & 16 deletions selectrum.el
Original file line number Diff line number Diff line change
Expand Up @@ -1292,35 +1292,36 @@ window is supposed to be shown vertically."
(and (window-at-side-p window 'bottom)
(not (window-at-side-p window 'top))))
(set-window-text-height window 1)))
((and (or (bound-and-true-p selectrum-fix-minibuffer-height)
selectrum-fix-vertical-window-height)
vertical)
((and vertical selectrum-fix-vertical-window-height)
(let* ((max (selectrum--max-window-height))
(height (if selectrum-display-action
max
;; Add one for prompt.
(1+ max))))
(set-window-text-height window height)))
(lines (if selectrum-display-action
max
;; Add one for prompt.
(1+ max)))
;; Include possible line spacing.
(height (* lines (line-pixel-height))))
(selectrum--set-window-height window height)))
(t
(when-let ((expand (selectrum--expand-window-for-content-p window)))
(cond (selectrum-display-action
(selectrum--update-display-window-height window))
(selectrum--fit-window-to-buffer window))
(t
(selectrum--update-minibuffer-height window)))))))
(selectrum--set-window-height window)))))))

(defun selectrum--update-display-window-height (window)
"Update window height of WINDOW.
(defun selectrum--fit-window-to-buffer (window)
"Fit window height to its buffer contents.
Also works for frames if WINDOW is the root window of its frame."
(let ((window-resize-pixelwise t)
(window-size-fixed nil)
(fit-frame-to-buffer 'vertically)
(fit-window-to-buffer-horizontally nil))
(fit-window-to-buffer window nil 1)))

(defun selectrum--update-minibuffer-height (window)
"Update window height of minibuffer WINDOW.
WINDOW will be updated to fit its content vertically."
(let ((dheight (cdr (window-text-pixel-size window)))
(defun selectrum--set-window-height (window &optional height)
"Set window height of WINDOW to HEIGHT pixel.
If HEIGHT is not given WINDOW will be updated to fit its content
vertically."
(let ((dheight (or height (cdr (window-text-pixel-size window))))
(wheight (window-pixel-height window))
(window-resize-pixelwise t))
(window-resize
Expand Down