2017-06-08 11:47:56 +02:00
|
|
|
;;; ui/doom-dashboard/config.el -*- lexical-binding: t; -*-
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(defvar +doom-dashboard-name " *doom*"
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(defvar +doom-dashboard-modeline nil
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(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-06-08 11:47:56 +02:00
|
|
|
(defvar +doom-dashboard--old-modeline nil)
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
|
|
|
|
;;
|
2017-06-16 02:04:27 +02:00
|
|
|
(map! :map +doom-dashboard-mode-map
|
|
|
|
"n" #'+doom-dashboard/next-button
|
|
|
|
"p" #'+doom-dashboard/previous-button
|
|
|
|
"N" #'+doom-dashboard/last-button
|
|
|
|
"P" #'+doom-dashboard/first-button
|
|
|
|
:em "j" #'+doom-dashboard/next-button
|
|
|
|
:em "k" #'+doom-dashboard/previous-button
|
|
|
|
:em "gg" #'+doom-dashboard/first-button
|
|
|
|
:em "G" #'+doom-dashboard/last-button
|
|
|
|
[remap evil-insert] #'evil-normal-state
|
|
|
|
[remap evil-change] #'evil-normal-state
|
|
|
|
[remap evil-visual-char] #'evil-normal-state
|
|
|
|
[remap evil-visual-line] #'evil-normal-state
|
|
|
|
[remap evil-delete] #'evil-normal-state
|
|
|
|
[remap evil-delete-char] #'evil-normal-state)
|
|
|
|
|
|
|
|
(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)))))
|
|
|
|
|
|
|
|
(defun +doom-dashboard/first-button ()
|
|
|
|
(interactive)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(+doom-dashboard/next-button))
|
|
|
|
|
|
|
|
(defun +doom-dashboard/last-button ()
|
|
|
|
(interactive)
|
|
|
|
(goto-char (point-max))
|
|
|
|
(+doom-dashboard/previous-button)
|
|
|
|
(beginning-of-line-text))
|
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-06-08 11:47:56 +02:00
|
|
|
(defun +doom-dashboard|kill-buffer-query-fn ()
|
|
|
|
(or (not (+doom-dashboard-p))
|
|
|
|
(ignore (ignore-errors (+doom-dashboard-reload))
|
|
|
|
(bury-buffer))))
|
|
|
|
|
2017-04-22 01:49:15 -04:00
|
|
|
(defun +doom-dashboard|init (&rest _)
|
2017-06-14 21:14:54 +02:00
|
|
|
(unless noninteractive
|
|
|
|
(add-hook 'after-make-frame-functions #'+doom-dashboard-deferred-reload)
|
|
|
|
(add-hook 'window-configuration-change-hook #'+doom-dashboard-reload)
|
|
|
|
(add-hook 'kill-buffer-query-functions #'+doom-dashboard|kill-buffer-query-fn)
|
2017-06-16 00:08:51 +02:00
|
|
|
(unless (daemonp)
|
|
|
|
(+doom-dashboard/open t))))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-06-12 15:13:30 +02:00
|
|
|
(add-hook 'doom-post-init-hook #'+doom-dashboard|init)
|
2017-04-22 01:49:15 -04:00
|
|
|
|
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))
|
|
|
|
|
|
|
|
;;
|
2017-06-16 00:08:51 +02:00
|
|
|
(defun +doom-dashboard/open (&optional startup)
|
2017-02-21 00:47:34 -05:00
|
|
|
"Open the dashboard buffer."
|
2017-02-20 16:33:14 -05:00
|
|
|
(interactive)
|
2017-06-16 00:08:51 +02:00
|
|
|
(when (or (not startup)
|
|
|
|
(one-window-p t)
|
|
|
|
(eq (buffer-name (window-buffer (car (window-list)))) "*scratch*"))
|
|
|
|
(+doom-dashboard-reload)
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(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-06-16 00:08:51 +02:00
|
|
|
(defun +doom-dashboard-deferred-reload (frame)
|
2017-02-24 03:13:23 -05:00
|
|
|
"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-06-16 00:08:51 +02:00
|
|
|
(run-with-timer 0.05 nil
|
|
|
|
(lambda (frame)
|
|
|
|
(with-selected-frame frame
|
|
|
|
(+doom-dashboard/open t)))
|
|
|
|
frame))
|
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)))
|
2017-06-16 00:08:51 +02:00
|
|
|
(get-buffer-window-list (doom-fallback-buffer)))
|
2017-02-20 16:33:14 -05:00
|
|
|
(unless +doom-dashboard-modeline
|
2017-06-08 11:47:56 +02: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-06-16 00:43:19 +02:00
|
|
|
(let ((old-pwd (or dir default-directory)))
|
2017-02-20 16:33:14 -05:00
|
|
|
(with-current-buffer (doom-fallback-buffer)
|
2017-06-16 00:43:19 +02:00
|
|
|
(with-silent-modifications
|
|
|
|
(read-only-mode +1)
|
|
|
|
(+doom-dashboard-mode)
|
|
|
|
(cl-loop for (car . _cdr) in fringe-indicator-alist
|
|
|
|
collect (cons car nil) into alist
|
|
|
|
finally do (setq fringe-indicator-alist alist))
|
|
|
|
(erase-buffer)
|
|
|
|
(let ((+doom-dashboard--width (window-width))
|
|
|
|
(+doom-dashboard--height (window-height)))
|
|
|
|
(insert (make-string (max 0 (- (truncate (/ +doom-dashboard--height 2)) 16)) ?\n))
|
|
|
|
(dolist (widget-name +doom-dashboard-widgets)
|
|
|
|
(funcall (intern (format "doom-dashboard-widget--%s" widget-name)))
|
|
|
|
(insert "\n")))
|
|
|
|
(setq default-directory old-pwd
|
|
|
|
mode-line-format +doom-dashboard-modeline)
|
|
|
|
(unless (button-at (point))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(goto-char (next-button (point))))))))
|
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))
|
2017-06-14 12:17:36 +02:00
|
|
|
(if (floatp doom-init-time) doom-init-time 0.0)))
|
2017-02-20 16:33:14 -05:00
|
|
|
'face 'font-lock-comment-face)
|
|
|
|
"\n"))
|
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defvar all-the-icons-scale-factor)
|
|
|
|
(defvar all-the-icons-default-adjust)
|
2017-02-20 16:33:14 -05:00
|
|
|
(defun doom-dashboard-widget--shortmenu ()
|
|
|
|
(let ((all-the-icons-scale-factor 1.3)
|
|
|
|
(all-the-icons-default-adjust -0.05)
|
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"
|
2017-05-25 12:12:15 +02:00
|
|
|
(lambda (_) (+workspace/load-session))))
|
2017-04-26 01:43:25 -04:00
|
|
|
("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))))))))
|