ui/doom-dashboard: add vertical centering (experimental)

This commit is contained in:
Henrik Lissner 2018-05-15 13:28:39 +02:00
parent 7eb0dd6340
commit 06c22a5af2
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -115,6 +115,7 @@ Possible values:
(defun +doom-dashboard|init ()
"Initializes Doom's dashboard."
(add-hook 'window-configuration-change-hook #'+doom-dashboard|resize)
(add-hook 'window-size-change-functions #'+doom-dashboard|resize)
(add-hook 'kill-buffer-query-functions #'+doom-dashboard|reload-on-kill)
(add-hook 'doom-after-switch-buffer-hook #'+doom-dashboard|reload-on-kill)
(unless (daemonp)
@ -146,12 +147,35 @@ If this is the dashboard buffer, reload the dashboard."
whose dimensions may not be fully initialized by the time this is run."
(run-with-timer 0.1 nil #'+doom-dashboard/open frame))
(defun +doom-dashboard|resize ()
"Resize the margins and fringes on dashboard windows."
(dolist (win (get-buffer-window-list (doom-fallback-buffer) nil t))
(set-window-fringes win 0 0)
(set-window-margins
win (max 0 (/ (- (window-total-width win) +doom-dashboard--width) 2)))))
(defun +doom-dashboard|resize (&rest _)
"Recenter the dashboard, and reset its margins and fringes."
(let ((windows (get-buffer-window-list (doom-fallback-buffer) nil t)))
(dolist (win windows)
(set-window-start win 0)
(set-window-fringes win 0 0)
(set-window-margins
win (max 0 (/ (- (window-total-width win) +doom-dashboard--width) 2))))
(when windows
(with-current-buffer (doom-fallback-buffer)
(save-excursion
(with-silent-modifications
(goto-char (point-min))
(cond ((display-graphic-p)
(delete-region (line-beginning-position) (1+ (line-end-position)))
(insert (propertize
(char-to-string ?\uE001)
'display `((space :align-to 0
:height ,(max 0 (- (/ (window-height (get-buffer-window)) 2)
(/ (count-lines (point-min) (point-max)) 2.5))))))
"\n"))
(t
(while (string-empty-p (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
(delete-region (line-beginning-position) (1+ (line-end-position))))
(insert
"\n"
(make-string (max 0 (- (/ (window-height (get-buffer-window)) 2)
(/ (count-lines (point-min) (point-max)) 2)))
?\n))))))))))
(defun +doom-dashboard|detect-project (&rest _)
"Check for a `last-project-root' parameter in the perspective, and set the
@ -212,13 +236,10 @@ controlled by `+doom-dashboard-pwd-policy'."
(unless (eq major-mode '+doom-dashboard-mode)
(+doom-dashboard-mode))
(erase-buffer)
(save-excursion (mapc #'funcall +doom-dashboard-functions))
(insert
(make-string (max 0 (- (/ (window-height (get-buffer-window)) 2)
(/ (count-lines (point-min) (point-max)) 2)))
?\n))))
(+doom-dashboard|detect-project)
(insert "\n")
(run-hooks '+doom-dashboard-functions)))
(+doom-dashboard|resize)
(+doom-dashboard|detect-project)
(+doom-dashboard-update-pwd)
(current-buffer))))