2017-03-15 22:42:05 -04:00
|
|
|
;;; ui/doom-dashboard/config.el
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(defvar +doom-dashboard-name " *doom*"
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(defvar +doom-dashboard-modeline nil
|
|
|
|
"TODO")
|
|
|
|
|
2017-02-20 19:44:34 -05:00
|
|
|
(defvar +doom-dashboard-old-modeline nil
|
|
|
|
"TODO")
|
|
|
|
|
2017-02-20 16:33:14 -05:00
|
|
|
(defvar +doom-dashboard-edited-p nil
|
|
|
|
"If non-nil, the scratch buffer has been edited.")
|
|
|
|
|
|
|
|
(defvar +doom-dashboard-inhibit-refresh nil
|
|
|
|
"If non-nil, the doom buffer won't be refreshed.")
|
|
|
|
|
|
|
|
(defvar +doom-dashboard-widgets '(banner shortmenu loaded)
|
|
|
|
"List of widgets to display in a blank scratch buffer.")
|
|
|
|
|
2017-03-19 22:50:52 -04:00
|
|
|
(define-derived-mode +doom-dashboard-mode fundamental-mode
|
|
|
|
(concat "v" doom-version)
|
|
|
|
"Major mode for the DOOM dashboard buffer.")
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(defvar +doom-dashboard--width 0)
|
|
|
|
(defvar +doom-dashboard--height 0)
|
2017-03-19 22:50:52 -04:00
|
|
|
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-04-26 01:43:25 -04:00
|
|
|
(after! evil
|
|
|
|
(map! :map +doom-dashboard-mode-map
|
|
|
|
:em "j" '+doom-dashboard/next-button
|
|
|
|
:em "k" '+doom-dashboard/previous-button)
|
|
|
|
|
|
|
|
(defun +doom-dashboard/next-button ()
|
|
|
|
(interactive)
|
|
|
|
(ignore-errors
|
|
|
|
(goto-char (next-button (point)))))
|
|
|
|
|
|
|
|
(defun +doom-dashboard/previous-button ()
|
|
|
|
(interactive)
|
|
|
|
(ignore-errors
|
|
|
|
(goto-char (previous-button (point))))))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(def-package! all-the-icons :when (display-graphic-p))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(unless (display-graphic-p)
|
2017-04-17 02:17:10 -04:00
|
|
|
(defalias 'all-the-icons-octicon #'ignore)
|
|
|
|
(defalias 'all-the-icons-faicon #'ignore)
|
|
|
|
(defalias 'all-the-icons-fileicon #'ignore)
|
|
|
|
(defalias 'all-the-icons-wicon #'ignore)
|
|
|
|
(defalias 'all-the-icons-alltheicon #'ignore))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2017-02-21 00:47:34 -05:00
|
|
|
(setq doom-fallback-buffer +doom-dashboard-name)
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-04-22 01:49:15 -04:00
|
|
|
(defun +doom-dashboard|init (&rest _)
|
|
|
|
(add-hook 'after-make-frame-functions #'+doom-dashboard-deferred-reload)
|
|
|
|
(add-hook 'window-configuration-change-hook #'+doom-dashboard-reload)
|
2017-03-07 00:23:23 -05:00
|
|
|
(add-hook! 'kill-buffer-query-functions
|
2017-03-15 22:59:21 -04:00
|
|
|
(or (not (+doom-dashboard-p))
|
|
|
|
(ignore (ignore-errors (+doom-dashboard-force-reload))
|
|
|
|
(bury-buffer))))
|
2017-03-18 12:15:50 -04:00
|
|
|
(+doom-dashboard-reload)
|
|
|
|
(when (equal (buffer-name) "*scratch*")
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-04-22 01:49:15 -04:00
|
|
|
(add-hook! '(after-make-frame-functions window-setup-hook)
|
|
|
|
#'+doom-dashboard|init)
|
|
|
|
|
2017-02-20 16:33:14 -05:00
|
|
|
;; Compatibility with `midnight-mode' and `clean-buffer-list'
|
2017-02-23 00:06:12 -05:00
|
|
|
(after! midnight-mode
|
2017-02-20 16:33:14 -05:00
|
|
|
(push +doom-dashboard-name clean-buffer-list-kill-never-buffer-names)
|
|
|
|
(push "^\\s-*\\*doom.+" clean-buffer-list-kill-never-regexps))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
(defun +doom-dashboard/open ()
|
2017-02-21 00:47:34 -05:00
|
|
|
"Open the dashboard buffer."
|
2017-02-20 16:33:14 -05:00
|
|
|
(interactive)
|
|
|
|
(+doom-dashboard-reload)
|
|
|
|
(switch-to-buffer (doom-fallback-buffer)))
|
|
|
|
|
|
|
|
(defun +doom-dashboard-p (&optional buffer)
|
2017-03-15 22:59:21 -04:00
|
|
|
"Returns t if BUFFER is the dashboard buffer."
|
2017-02-20 16:33:14 -05:00
|
|
|
(let ((buffer (or buffer (current-buffer))))
|
|
|
|
(and (buffer-live-p buffer)
|
|
|
|
(eq buffer (doom-fallback-buffer)))))
|
|
|
|
|
2017-02-20 19:43:57 -05:00
|
|
|
(defun +doom-dashboard-force-reload ()
|
2017-02-20 16:33:14 -05:00
|
|
|
(setq +doom-dashboard-edited-p nil)
|
|
|
|
(+doom-dashboard-reload))
|
|
|
|
|
|
|
|
(defun +doom-dashboard|clear-on-insert ()
|
|
|
|
"Erase the buffer and prepare it to be used like a normal buffer."
|
|
|
|
(unless +doom-dashboard-edited-p
|
|
|
|
(erase-buffer)
|
|
|
|
(setq +doom-dashboard-edited-p t
|
2017-02-24 03:14:13 -05:00
|
|
|
mode-line-format +doom-dashboard-old-modeline
|
|
|
|
fringe-indicator-alist +doom-dashboard--old-fringe-indicator)
|
2017-04-17 02:17:10 -04:00
|
|
|
(remove-hook 'evil-insert-state-entry-hook #'doom|mode-erase-on-insert t)))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-02-24 03:13:23 -05:00
|
|
|
(defun +doom-dashboard-deferred-reload (&rest _)
|
|
|
|
"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."
|
2017-04-17 02:17:10 -04:00
|
|
|
(run-with-timer 0.1 nil #'+doom-dashboard-reload))
|
2017-02-24 03:13:23 -05:00
|
|
|
|
2017-02-20 16:33:14 -05:00
|
|
|
(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)
|
|
|
|
(not (minibuffer-window-active-p (minibuffer-window)))
|
|
|
|
(get-buffer-window-list (doom-fallback-buffer) nil t)
|
|
|
|
(or (not +doom-dashboard-edited-p) dir))
|
|
|
|
(unless +doom-dashboard-modeline
|
2017-02-20 19:44:34 -05:00
|
|
|
(setq +doom-dashboard-old-modeline mode-line-format)
|
2017-02-20 16:33:14 -05:00
|
|
|
(setq +doom-dashboard-modeline
|
2017-04-25 18:25:54 -04:00
|
|
|
(or (and (featurep! :ui doom-modeline)
|
|
|
|
(doom-modeline 'project))
|
|
|
|
mode-line-format)))
|
2017-02-20 16:33:14 -05:00
|
|
|
(let ((old-pwd (or dir default-directory)))
|
|
|
|
(with-current-buffer (doom-fallback-buffer)
|
2017-04-26 01:43:25 -04:00
|
|
|
(read-only-mode -1)
|
2017-02-20 16:33:14 -05:00
|
|
|
(+doom-dashboard-mode)
|
2017-04-26 01:43:25 -04:00
|
|
|
;; (add-hook 'evil-insert-state-entry-hook #'+doom-dashboard|clear-on-insert nil t)
|
|
|
|
;; (add-hook 'after-change-major-mode-hook #'+doom-dashboard|clear-on-insert nil t)
|
2017-02-20 16:33:14 -05:00
|
|
|
(setq +doom-dashboard-edited-p nil
|
|
|
|
fringe-indicator-alist (mapcar (lambda (i) (cons (car i) nil))
|
|
|
|
fringe-indicator-alist))
|
|
|
|
(erase-buffer)
|
|
|
|
(let* ((+doom-dashboard--width (window-width (get-buffer-window (doom-fallback-buffer))))
|
|
|
|
(+doom-dashboard--height (window-height (get-buffer-window (doom-fallback-buffer)))))
|
|
|
|
(insert (make-string (max 0 (- (truncate (/ +doom-dashboard--height 2)) 11)) ?\n))
|
|
|
|
(mapc (lambda (widget-name)
|
|
|
|
(funcall (intern (format "doom-dashboard-widget--%s" widget-name)))
|
|
|
|
(insert "\n"))
|
|
|
|
+doom-dashboard-widgets))
|
2017-04-26 01:43:25 -04:00
|
|
|
(setq default-directory old-pwd
|
|
|
|
mode-line-format +doom-dashboard-modeline)
|
|
|
|
(unless (button-at (point))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(goto-char (next-button (point))))
|
|
|
|
(read-only-mode +1))))
|
2017-02-20 16:33:14 -05:00
|
|
|
t)
|
|
|
|
|
|
|
|
(defun doom-dashboard-widget--banner ()
|
|
|
|
(mapc (lambda (line)
|
|
|
|
(insert (propertize (s-center +doom-dashboard--width line)
|
|
|
|
'face 'font-lock-comment-face) " ")
|
|
|
|
(insert "\n"))
|
|
|
|
'("================= =============== =============== ======== ========"
|
|
|
|
"\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //"
|
|
|
|
"||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||"
|
|
|
|
"|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||"
|
|
|
|
"||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||"
|
|
|
|
"|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||"
|
|
|
|
"||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||"
|
|
|
|
"|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||"
|
|
|
|
"||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||"
|
|
|
|
"|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||"
|
|
|
|
"|| `' || || `' || || `' || || | \\ / | ||"
|
|
|
|
"|| .===' `===. .==='.`===. .===' /==. | \\/ | ||"
|
|
|
|
"|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||"
|
|
|
|
"|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||"
|
|
|
|
"|| .==' _-' '-__\\._-' '-_./__-' `' |. /| | ||"
|
|
|
|
"||.==' _-' `' | /==.||"
|
|
|
|
"==' _-' E M A C S \\/ `=="
|
|
|
|
"\\ _-' `-_ /"
|
|
|
|
" `'' ``'")))
|
|
|
|
|
|
|
|
(defun doom-dashboard-widget--loaded ()
|
|
|
|
(insert
|
|
|
|
(propertize
|
|
|
|
(s-center +doom-dashboard--width
|
2017-02-20 16:42:30 -05:00
|
|
|
(format "Loaded %d packages in %.03fs "
|
|
|
|
(- (length load-path) (length doom--base-load-path))
|
|
|
|
doom-init-time))
|
2017-02-20 16:33:14 -05:00
|
|
|
'face 'font-lock-comment-face)
|
|
|
|
"\n"))
|
|
|
|
|
|
|
|
(defun doom-dashboard-widget--shortmenu ()
|
|
|
|
(let ((all-the-icons-scale-factor 1.3)
|
|
|
|
(all-the-icons-default-adjust -0.05)
|
|
|
|
(start (point))
|
2017-02-20 16:42:41 -05:00
|
|
|
(last-session-p (and (and (featurep 'persp-mode) persp-mode)
|
2017-02-20 16:33:14 -05:00
|
|
|
(file-exists-p (expand-file-name persp-auto-save-fname persp-save-dir)))))
|
2017-04-26 01:43:25 -04:00
|
|
|
(mapc (lambda (btn)
|
|
|
|
(when btn
|
|
|
|
(let ((label (car btn))
|
|
|
|
(icon (nth 1 btn))
|
|
|
|
(fn (nth 2 btn)))
|
|
|
|
(insert
|
|
|
|
(with-temp-buffer
|
2017-02-20 16:33:14 -05:00
|
|
|
(insert-text-button
|
|
|
|
(concat (all-the-icons-octicon
|
2017-04-26 01:43:25 -04:00
|
|
|
icon
|
2017-02-20 16:33:14 -05:00
|
|
|
:face 'font-lock-keyword-face)
|
2017-04-26 01:43:25 -04:00
|
|
|
(propertize (concat " " label) 'face 'font-lock-keyword-face))
|
|
|
|
'action fn
|
|
|
|
'follow-link t)
|
|
|
|
(s-center (1- +doom-dashboard--width) (buffer-string))))
|
|
|
|
(insert "\n\n"))))
|
|
|
|
`(("Homepage" "mark-github"
|
|
|
|
(lambda (_) (browse-url "https://github.com/hlissner/.emacs.d")))
|
|
|
|
,(when last-session-p
|
|
|
|
'("Reload last session" "history"
|
|
|
|
(lambda (_) (+workspace:load-session))))
|
|
|
|
("Recently opened files" "file-text"
|
|
|
|
(lambda (_) (call-interactively (command-remapping 'recentf))))
|
|
|
|
("Recent opened projects" "briefcase"
|
|
|
|
(lambda (_) (call-interactively (command-remapping 'projectile-switch-project))))
|
|
|
|
("Jump to bookmark" "bookmark"
|
|
|
|
(lambda (_) (call-interactively (command-remapping 'bookmark-jump))))
|
|
|
|
("Edit emacs.d" "tools"
|
|
|
|
(lambda (_) (find-file (expand-file-name "init.el" doom-emacs-dir))))))))
|