From f7e737c1f1a9e5a7fecd402e9f1773e6d8f3954c Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 13 Sep 2017 20:11:16 +0200 Subject: [PATCH] doom-dashboard: refactor --- modules/ui/doom-dashboard/config.el | 42 +++++++++++------------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/modules/ui/doom-dashboard/config.el b/modules/ui/doom-dashboard/config.el index 565724ea5..ee47f91aa 100644 --- a/modules/ui/doom-dashboard/config.el +++ b/modules/ui/doom-dashboard/config.el @@ -1,10 +1,10 @@ ;;; ui/doom-dashboard/config.el -*- lexical-binding: t; -*- (defvar +doom-dashboard-name " *doom*" - "TODO") + "The name to use for the dashboard buffer.") (defvar +doom-dashboard-modeline nil - "TODO") + "The modeline format for the doom dashboard buffer.") (defvar +doom-dashboard-inhibit-refresh nil "If non-nil, the doom buffer won't be refreshed.") @@ -12,6 +12,14 @@ (defvar +doom-dashboard-widgets '(banner shortmenu loaded) "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 (concat "v" doom-version) "Major mode for the DOOM dashboard buffer." @@ -22,16 +30,6 @@ collect (cons car nil) into 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 "n" #'+doom-dashboard/next-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) ? ) 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) "Update the DOOM scratch buffer (or create it, if it doesn't exist)." (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 (+doom-dashboard-center +doom-dashboard--width - (format "Loaded %d packages in %.03fs " + (format "Loaded %d packages in %.02fs" (- (length load-path) (length doom--base-load-path)) (if (floatp doom-init-time) doom-init-time 0.0))) '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) (defun doom-dashboard-widget--shortmenu () (let ((all-the-icons-scale-factor 1.3) - (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))))) + (all-the-icons-default-adjust -0.05)) (mapc (lambda (btn) (when 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))) "\n\n")))) `(("Homepage" "mark-github" - (browse-url "https://github.com/hlissner/.emacs.d")) - ,(when last-session-p + (browse-url "https://github.com/hlissner/doom-emacs")) + ,(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" (+workspace/load-session))) ("Recently opened files" "file-text"