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*"
|
2017-09-13 20:11:16 +02:00
|
|
|
"The name to use for the dashboard buffer.")
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
(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-10-02 19:59:18 +02:00
|
|
|
(defvar +doom-dashboard-inhibit-functions ()
|
|
|
|
"A list of functions that determine whether to inhibit the dashboard the
|
|
|
|
loading.")
|
|
|
|
|
2017-12-27 13:24:14 -05:00
|
|
|
(defvar +doom-dashboard-pwd-policy 'last-project
|
|
|
|
"The policy to use when setting the `default-directory' in the dashboard.
|
|
|
|
|
|
|
|
Possible values:
|
|
|
|
|
|
|
|
'last-project the `doom-project-root' of the last open buffer
|
|
|
|
'last the `default-directory' of the last open buffer
|
|
|
|
a FUNCTION a function run with the `default-directory' of the last
|
|
|
|
open buffer, that returns a directory path
|
|
|
|
a STRING a fixed path
|
|
|
|
nil `default-directory' will never change")
|
|
|
|
|
|
|
|
;;
|
|
|
|
(defvar +doom-dashboard--last-cwd nil)
|
2017-09-13 20:15:46 +02:00
|
|
|
(defvar +doom-dashboard--width 80)
|
2017-09-13 20:11:16 +02:00
|
|
|
(defvar +doom-dashboard--height 0)
|
|
|
|
(defvar +doom-dashboard--old-fringe-indicator fringe-indicator-alist)
|
|
|
|
|
2017-12-27 13:24:14 -05:00
|
|
|
;;
|
2017-09-13 20:11:16 +02:00
|
|
|
(setq doom-fallback-buffer +doom-dashboard-name)
|
|
|
|
|
|
|
|
|
2017-06-25 02:01:05 +02:00
|
|
|
(define-derived-mode +doom-dashboard-mode special-mode
|
2017-09-29 02:41:21 +02:00
|
|
|
(format "DOOM v%s" doom-version)
|
2017-06-25 02:01:05 +02:00
|
|
|
"Major mode for the DOOM dashboard buffer."
|
|
|
|
(read-only-mode +1)
|
2017-09-29 04:00:42 +02:00
|
|
|
(setq truncate-lines t)
|
2017-12-22 16:33:08 -05:00
|
|
|
(setq-local whitespace-style nil)
|
2017-12-25 19:09:55 -05:00
|
|
|
(setq-local show-trailing-whitespace nil)
|
2017-06-25 02:01:05 +02:00
|
|
|
(cl-loop for (car . _cdr) in fringe-indicator-alist
|
|
|
|
collect (cons car nil) into alist
|
|
|
|
finally do (setq fringe-indicator-alist alist)))
|
|
|
|
|
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)
|
|
|
|
|
2017-02-20 16:33:14 -05:00
|
|
|
;;
|
2017-06-25 01:59:58 +02:00
|
|
|
(defun +doom-dashboard|init ()
|
|
|
|
"Initialize doom-dashboard and set up its hooks; possibly open the dashboard
|
|
|
|
if in a GUI/non-daemon session."
|
|
|
|
(add-hook 'window-configuration-change-hook #'+doom-dashboard-reload)
|
2017-09-13 20:15:54 +02:00
|
|
|
(add-hook 'focus-in-hook #'+doom-dashboard-reload)
|
2017-06-25 01:59:58 +02:00
|
|
|
(add-hook 'kill-buffer-query-functions #'+doom-dashboard|kill-buffer-query-fn)
|
|
|
|
(when (and (display-graphic-p) (not (daemonp)))
|
2017-09-26 19:35:44 +02:00
|
|
|
(let ((default-directory doom-emacs-dir))
|
|
|
|
(+doom-dashboard/open (selected-frame)))))
|
2017-02-20 16:33:14 -05:00
|
|
|
|
2017-06-08 11:47:56 +02:00
|
|
|
(defun +doom-dashboard|kill-buffer-query-fn ()
|
2017-12-27 13:24:14 -05:00
|
|
|
(or (unless (+doom-dashboard-p)
|
2017-12-27 17:12:50 -05:00
|
|
|
(when buffer-file-name
|
|
|
|
(setq +doom-dashboard--last-cwd default-directory))
|
2017-12-27 13:24:14 -05:00
|
|
|
t)
|
2017-12-27 17:12:50 -05:00
|
|
|
(ignore
|
|
|
|
(let (+doom-dashboard-inhibit-refresh)
|
|
|
|
(ignore-errors (+doom-dashboard-reload))))))
|
2017-06-08 11:47:56 +02:00
|
|
|
|
2017-06-25 01:59:58 +02:00
|
|
|
(defun +doom-dashboard|make-frame (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.1 nil #'+doom-dashboard/open frame))
|
|
|
|
|
|
|
|
(defun +doom-dashboard|server-visit (&rest _)
|
|
|
|
"Inhibit dashboard refresh when opening files via emacsclient."
|
|
|
|
(setq +doom-dashboard-inhibit-refresh t))
|
2017-06-28 16:30:40 +02:00
|
|
|
|
|
|
|
(add-hook 'window-setup-hook #'+doom-dashboard|init)
|
|
|
|
(add-hook 'after-make-frame-functions #'+doom-dashboard|make-frame)
|
2017-06-25 01:59:58 +02:00
|
|
|
(add-hook 'server-visit-hook #'+doom-dashboard|server-visit)
|
2017-04-22 01:49:15 -04:00
|
|
|
|
2017-02-20 16:33:14 -05:00
|
|
|
|
|
|
|
;;
|
2017-06-25 01:59:58 +02:00
|
|
|
(defun +doom-dashboard/open (frame)
|
|
|
|
(interactive (list (selected-frame)))
|
2017-10-02 19:59:18 +02:00
|
|
|
(unless (run-hook-with-args-until-success '+doom-dashboard-inhibit-functions)
|
|
|
|
(unless +doom-dashboard-inhibit-refresh
|
|
|
|
(with-selected-frame frame
|
|
|
|
(switch-to-buffer (doom-fallback-buffer))
|
|
|
|
(+doom-dashboard-reload)))
|
|
|
|
(setq +doom-dashboard-inhibit-refresh nil)))
|
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-25 02:01:05 +02:00
|
|
|
(defun +doom-dashboard-center (len s)
|
|
|
|
(concat (make-string (ceiling (max 0 (- len (length s))) 2) ? )
|
|
|
|
s))
|
|
|
|
|
2017-12-28 19:59:32 -05:00
|
|
|
(defun +doom-dashboard--get-pwd ()
|
2017-12-27 21:00:03 -05:00
|
|
|
(let ((lastcwd +doom-dashboard--last-cwd)
|
|
|
|
(policy +doom-dashboard-pwd-policy))
|
|
|
|
(cond ((null policy)
|
|
|
|
default-directory)
|
|
|
|
((null lastcwd)
|
|
|
|
default-directory)
|
|
|
|
((eq policy 'last-project)
|
|
|
|
(let ((cwd default-directory)
|
|
|
|
(default-directory lastcwd))
|
|
|
|
(if (doom-project-p)
|
|
|
|
(doom-project-root)
|
|
|
|
cwd)))
|
2017-12-28 19:58:27 -05:00
|
|
|
((eq policy 'last)
|
|
|
|
lastcwd)
|
2017-12-27 21:00:03 -05:00
|
|
|
((stringp policy)
|
|
|
|
(expand-file-name policy lastcwd))
|
|
|
|
((functionp policy)
|
|
|
|
(funcall policy lastcwd))
|
|
|
|
(t
|
|
|
|
(warn "`+doom-dashboard-pwd-policy' has an invalid value of '%s'"
|
|
|
|
+doom-dashboard-pwd-policy)))))
|
2017-12-27 13:24:14 -05:00
|
|
|
|
2017-12-28 19:59:32 -05:00
|
|
|
(defun +doom-dashboard-reload (&optional force)
|
2017-02-20 16:33:14 -05:00
|
|
|
"Update the DOOM scratch buffer (or create it, if it doesn't exist)."
|
2017-12-28 19:59:32 -05:00
|
|
|
(let ((fallback-buffer (doom-fallback-buffer)))
|
|
|
|
(when (or force
|
|
|
|
(and (get-buffer-window fallback-buffer)
|
|
|
|
(not (window-minibuffer-p (frame-selected-window)))))
|
|
|
|
(with-current-buffer fallback-buffer
|
|
|
|
(setq default-directory
|
|
|
|
(or (+doom-dashboard--get-pwd)
|
2017-12-28 20:04:46 -05:00
|
|
|
default-directory))
|
|
|
|
(unless +doom-dashboard-inhibit-refresh
|
|
|
|
(with-silent-modifications
|
|
|
|
(unless (eq major-mode '+doom-dashboard-mode)
|
|
|
|
(+doom-dashboard-mode))
|
|
|
|
(erase-buffer)
|
|
|
|
(let ((+doom-dashboard--height (window-height (get-buffer-window fallback-buffer)))
|
|
|
|
(lines 1)
|
|
|
|
content)
|
|
|
|
(with-temp-buffer
|
|
|
|
(dolist (widget-name +doom-dashboard-widgets)
|
|
|
|
(funcall (intern (format "doom-dashboard-widget--%s" widget-name)))
|
|
|
|
(insert "\n"))
|
|
|
|
(setq content (buffer-string)
|
|
|
|
lines (count-lines (point-min) (point-max))))
|
|
|
|
(insert (make-string (max 0 (- (/ +doom-dashboard--height 2)
|
|
|
|
(/ lines 2)))
|
|
|
|
?\n)
|
|
|
|
content))
|
|
|
|
(unless (button-at (point))
|
|
|
|
(goto-char (next-button (point-min))))))))
|
2017-09-13 20:15:46 +02:00
|
|
|
;; Update all 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)))))
|
2017-02-20 16:33:14 -05:00
|
|
|
t)
|
|
|
|
|
2017-06-25 02:01:05 +02:00
|
|
|
;; widgets
|
2017-02-20 16:33:14 -05:00
|
|
|
(defun doom-dashboard-widget--banner ()
|
|
|
|
(mapc (lambda (line)
|
2017-06-25 02:01:05 +02:00
|
|
|
(insert (propertize (+doom-dashboard-center +doom-dashboard--width line)
|
2017-02-20 16:33:14 -05:00
|
|
|
'face 'font-lock-comment-face) " ")
|
|
|
|
(insert "\n"))
|
|
|
|
'("================= =============== =============== ======== ========"
|
|
|
|
"\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //"
|
|
|
|
"||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||"
|
|
|
|
"|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||"
|
|
|
|
"||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||"
|
|
|
|
"|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||"
|
|
|
|
"||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||"
|
|
|
|
"|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||"
|
|
|
|
"||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||"
|
|
|
|
"|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||"
|
|
|
|
"|| `' || || `' || || `' || || | \\ / | ||"
|
|
|
|
"|| .===' `===. .==='.`===. .===' /==. | \\/ | ||"
|
|
|
|
"|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||"
|
|
|
|
"|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||"
|
|
|
|
"|| .==' _-' '-__\\._-' '-_./__-' `' |. /| | ||"
|
|
|
|
"||.==' _-' `' | /==.||"
|
|
|
|
"==' _-' E M A C S \\/ `=="
|
|
|
|
"\\ _-' `-_ /"
|
|
|
|
" `'' ``'")))
|
|
|
|
|
|
|
|
(defun doom-dashboard-widget--loaded ()
|
|
|
|
(insert
|
2017-09-29 02:42:38 +02:00
|
|
|
"\n"
|
2017-02-20 16:33:14 -05:00
|
|
|
(propertize
|
2017-06-25 02:01:05 +02:00
|
|
|
(+doom-dashboard-center
|
|
|
|
+doom-dashboard--width
|
2017-09-29 02:42:38 +02:00
|
|
|
(format "Loaded %d packages in %d modules in %.02fs"
|
2017-12-22 15:25:19 -05:00
|
|
|
(length doom--package-load-path)
|
2017-09-29 02:42:38 +02:00
|
|
|
(hash-table-size doom-modules)
|
2017-06-25 02:01:05 +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 ()
|
2017-09-29 02:42:38 +02:00
|
|
|
(let ((all-the-icons-scale-factor 1.45)
|
|
|
|
(all-the-icons-default-adjust -0.02))
|
2017-04-26 01:43:25 -04:00
|
|
|
(mapc (lambda (btn)
|
|
|
|
(when btn
|
2017-07-18 22:12:50 +02:00
|
|
|
(cl-destructuring-bind (label icon fn) btn
|
2017-04-26 01:43:25 -04:00
|
|
|
(insert
|
|
|
|
(with-temp-buffer
|
2017-02-20 16:33:14 -05:00
|
|
|
(insert-text-button
|
2017-07-18 22:12:50 +02:00
|
|
|
(concat (all-the-icons-octicon icon :face 'font-lock-keyword-face)
|
2017-04-26 01:43:25 -04:00
|
|
|
(propertize (concat " " label) 'face 'font-lock-keyword-face))
|
2017-07-18 22:12:50 +02:00
|
|
|
'action `(lambda (_) ,fn)
|
2017-04-26 01:43:25 -04:00
|
|
|
'follow-link t)
|
2017-09-29 02:42:38 +02:00
|
|
|
(+doom-dashboard-center (- +doom-dashboard--width 2) (buffer-string)))
|
2017-07-18 22:12:50 +02:00
|
|
|
"\n\n"))))
|
2017-04-26 01:43:25 -04:00
|
|
|
`(("Homepage" "mark-github"
|
2017-09-13 20:11:16 +02:00
|
|
|
(browse-url "https://github.com/hlissner/doom-emacs"))
|
2017-09-29 02:42:38 +02:00
|
|
|
,(when (and (featurep! :feature workspaces)
|
2017-09-13 20:11:16 +02:00
|
|
|
(file-exists-p (expand-file-name persp-auto-save-fname persp-save-dir)))
|
2017-04-26 01:43:25 -04:00
|
|
|
'("Reload last session" "history"
|
2017-07-26 15:45:01 +02:00
|
|
|
(+workspace/load-session)))
|
2017-09-29 02:42:46 +02:00
|
|
|
,(when (featurep! :org org)
|
|
|
|
'("See agenda for this week" "calendar"
|
|
|
|
(call-interactively 'org-agenda-list)))
|
2017-04-26 01:43:25 -04:00
|
|
|
("Recently opened files" "file-text"
|
2017-09-29 02:42:38 +02:00
|
|
|
(call-interactively (command-remapping 'recentf-open-files)))
|
|
|
|
("Open project" "briefcase"
|
2017-07-18 22:12:50 +02:00
|
|
|
(call-interactively (command-remapping 'projectile-switch-project)))
|
2017-04-26 01:43:25 -04:00
|
|
|
("Jump to bookmark" "bookmark"
|
2017-07-18 22:12:50 +02:00
|
|
|
(call-interactively (command-remapping 'bookmark-jump)))
|
2017-04-26 01:43:25 -04:00
|
|
|
("Edit emacs.d" "tools"
|
2017-07-18 22:12:50 +02:00
|
|
|
(find-file (expand-file-name "init.el" doom-emacs-dir)))))))
|