Force redisplay to trigger height calculations

ertain functions, including e.g. `fit-window-to-buffer', base
their size calculations on values that are incorrect if the
mode-line has a height different from that of the `default' face
and certain other calculations have not yet taken place for the
window in question.

Force a redisplay before `fit-window-to-buffer' using an advice,
like we already did for `resize-temp-buffer-window'.

Close #183.

Reference:
https://github.com/tarsius/moody/issues/19
https://github.com/magit/transient/issues/63
This commit is contained in:
Vincent Zhang 2019-10-25 02:46:09 +08:00
parent 54fe24786a
commit a3b6432569

View file

@ -125,7 +125,6 @@ It returns a file name which can be used directly as argument of
("battery-three-quarters" . "\xf241"))) ("battery-three-quarters" . "\xf241")))
(doom-moddeline--set-font-widths doom-modeline-rhs-icons-alist) (doom-moddeline--set-font-widths doom-modeline-rhs-icons-alist)
;; ;;
;; Customizations ;; Customizations
;; ;;
@ -612,6 +611,24 @@ It respects `doom-modeline-icon' and `all-the-icons-color-icons'."
;; Plugins ;; Plugins
;; ;;
(defun doom-modeline-redisplay (&rest _)
"Call `redisplay' to trigger mode-line height calculations.
Certain functions, including e.g. `fit-window-to-buffer', base
their size calculations on values which are incorrect if the
mode-line has a height different from that of the `default' face
and certain other calculations have not yet taken place for the
window in question.
These calculations can be triggered by calling `redisplay'
explicitly at the appropriate time and this functions purpose
is to make it easier to do so.
This function is like `redisplay' with non-nil FORCE argument.
It accepts an arbitrary number of arguments making it suitable
as a `:before' advice for any function."
(redisplay t))
(advice-add #'fit-window-to-buffer :before #'doom-modeline-redisplay)
(advice-add #'resize-temp-buffer-window :before #'doom-modeline-redisplay)
;; Keep `doom-modeline-current-window' up-to-date ;; Keep `doom-modeline-current-window' up-to-date
(defun doom-modeline--get-current-window () (defun doom-modeline--get-current-window ()
"Get the current window but should exclude the child windows." "Get the current window but should exclude the child windows."