doom-dashboard: refactor

This commit is contained in:
Henrik Lissner 2017-09-13 20:11:16 +02:00
parent 895d59f9b4
commit f7e737c1f1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,10 +1,10 @@
;;; ui/doom-dashboard/config.el -*- lexical-binding: t; -*- ;;; ui/doom-dashboard/config.el -*- lexical-binding: t; -*-
(defvar +doom-dashboard-name " *doom*" (defvar +doom-dashboard-name " *doom*"
"TODO") "The name to use for the dashboard buffer.")
(defvar +doom-dashboard-modeline nil (defvar +doom-dashboard-modeline nil
"TODO") "The modeline format for the doom dashboard buffer.")
(defvar +doom-dashboard-inhibit-refresh nil (defvar +doom-dashboard-inhibit-refresh nil
"If non-nil, the doom buffer won't be refreshed.") "If non-nil, the doom buffer won't be refreshed.")
@ -12,6 +12,14 @@
(defvar +doom-dashboard-widgets '(banner shortmenu loaded) (defvar +doom-dashboard-widgets '(banner shortmenu loaded)
"List of widgets to display in a blank scratch buffer.") "List of widgets to display in a blank scratch buffer.")
(defvar +doom-dashboard--width 0)
(defvar +doom-dashboard--height 0)
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
(defvar +doom-dashboard--old-modeline nil)
(setq doom-fallback-buffer +doom-dashboard-name)
(define-derived-mode +doom-dashboard-mode special-mode (define-derived-mode +doom-dashboard-mode special-mode
(concat "v" doom-version) (concat "v" doom-version)
"Major mode for the DOOM dashboard buffer." "Major mode for the DOOM dashboard buffer."
@ -22,16 +30,6 @@
collect (cons car nil) into alist collect (cons car nil) into alist
finally do (setq fringe-indicator-alist alist))) finally do (setq fringe-indicator-alist alist)))
(defvar +doom-dashboard--width 0)
(defvar +doom-dashboard--height 0)
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
(defvar +doom-dashboard--old-modeline nil)
(setq doom-fallback-buffer +doom-dashboard-name)
;;
(map! :map +doom-dashboard-mode-map (map! :map +doom-dashboard-mode-map
"n" #'+doom-dashboard/next-button "n" #'+doom-dashboard/next-button
"p" #'+doom-dashboard/previous-button "p" #'+doom-dashboard/previous-button
@ -96,15 +94,6 @@ whose dimensions may not be fully initialized by the time this is run."
(concat (make-string (ceiling (max 0 (- len (length s))) 2) ? ) (concat (make-string (ceiling (max 0 (- len (length s))) 2) ? )
s)) s))
(defun +doom-dashboard-deferred-reload (frame)
"Reload the dashboard after a brief pause. This is necessary for new frames,
whose dimensions may not be fully initialized by the time this is run."
(run-with-timer 0.05 nil
(lambda (frame)
(with-selected-frame frame
(+doom-dashboard/open t)))
frame))
(defun +doom-dashboard-reload (&optional dir) (defun +doom-dashboard-reload (&optional dir)
"Update the DOOM scratch buffer (or create it, if it doesn't exist)." "Update the DOOM scratch buffer (or create it, if it doesn't exist)."
(when (and (not +doom-dashboard-inhibit-refresh) (when (and (not +doom-dashboard-inhibit-refresh)
@ -169,7 +158,7 @@ whose dimensions may not be fully initialized by the time this is run."
(propertize (propertize
(+doom-dashboard-center (+doom-dashboard-center
+doom-dashboard--width +doom-dashboard--width
(format "Loaded %d packages in %.03fs " (format "Loaded %d packages in %.02fs"
(- (length load-path) (length doom--base-load-path)) (- (length load-path) (length doom--base-load-path))
(if (floatp doom-init-time) doom-init-time 0.0))) (if (floatp doom-init-time) doom-init-time 0.0)))
'face 'font-lock-comment-face) 'face 'font-lock-comment-face)
@ -179,9 +168,7 @@ whose dimensions may not be fully initialized by the time this is run."
(defvar all-the-icons-default-adjust) (defvar all-the-icons-default-adjust)
(defun doom-dashboard-widget--shortmenu () (defun doom-dashboard-widget--shortmenu ()
(let ((all-the-icons-scale-factor 1.3) (let ((all-the-icons-scale-factor 1.3)
(all-the-icons-default-adjust -0.05) (all-the-icons-default-adjust -0.05))
(last-session-p (and (and (featurep 'persp-mode) persp-mode)
(file-exists-p (expand-file-name persp-auto-save-fname persp-save-dir)))))
(mapc (lambda (btn) (mapc (lambda (btn)
(when btn (when btn
(cl-destructuring-bind (label icon fn) btn (cl-destructuring-bind (label icon fn) btn
@ -195,8 +182,9 @@ whose dimensions may not be fully initialized by the time this is run."
(+doom-dashboard-center (1- +doom-dashboard--width) (buffer-string))) (+doom-dashboard-center (1- +doom-dashboard--width) (buffer-string)))
"\n\n")))) "\n\n"))))
`(("Homepage" "mark-github" `(("Homepage" "mark-github"
(browse-url "https://github.com/hlissner/.emacs.d")) (browse-url "https://github.com/hlissner/doom-emacs"))
,(when last-session-p ,(when (and (and (featurep 'persp-mode) persp-mode)
(file-exists-p (expand-file-name persp-auto-save-fname persp-save-dir)))
'("Reload last session" "history" '("Reload last session" "history"
(+workspace/load-session))) (+workspace/load-session)))
("Recently opened files" "file-text" ("Recently opened files" "file-text"