-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathinit-dashboard.el
230 lines (205 loc) · 8.69 KB
/
init-dashboard.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
;; init-dashboard.el --- Initialize dashboard configurations. -*- lexical-binding: t -*-
;; Copyright (C) 2018-2023 Vincent Zhang
;; Author: Vincent Zhang <seagle0128@gmail.com>
;; URL: https://github.com/seagle0128/.emacs.d
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;; Commentary:
;;
;; Dashboard configurations.
;;
;;; Code:
(require 'init-const)
(require 'init-custom)
(require 'init-funcs)
;; Dashboard
(when centaur-dashboard
(use-package dashboard
:diminish dashboard-mode
:functions (nerd-icons-faicon
nerd-icons-mdicon
winner-undo
widget-forward)
:custom-face
(dashboard-heading ((t (:inherit (font-lock-string-face bold)))))
(dashboard-items-face ((t (:weight normal))))
(dashboard-no-items-face ((t (:weight normal))))
:pretty-hydra
((:title (pretty-hydra-title "Dashboard" 'mdicon "nf-md-view_dashboard")
:color pink :quit-key ("q" "C-g"))
("Navigator"
(("U" update-config-and-packages "update" :exit t)
("H" browse-homepage "homepage" :exit t)
("R" restore-previous-session "recover session" :exit t)
("L" restore-session "list sessions" :exit t)
("S" find-custom-file "settings" :exit t))
"Section"
(("}" dashboard-next-section "next")
("{" dashboard-previous-section "previous")
("r" dashboard-goto-recent-files "recent files")
("m" dashboard-goto-bookmarks "bookmarks")
("p" dashboard-goto-projects "projects"))
"Item"
(("RET" widget-button-press "open" :exit t)
("<tab>" widget-forward "next")
("C-i" widget-forward "next")
("<backtab>" widget-backward "previous")
("C-n" next-line "next line")
("C-p" previous-line "previous line"))
"Misc"
(("<f2>" open-dashboard "open" :exit t)
("g" dashboard-refresh-buffer "refresh" :exit t)
("Q" quit-dashboard "quit" :exit t))))
:bind (("<f2>" . open-dashboard)
:map dashboard-mode-map
("H" . browse-homepage)
("R" . restore-previous-session)
("L" . restore-session)
("S" . find-custom-file)
("U" . update-config-and-packages)
("q" . quit-dashboard)
("h" . dashboard-hydra/body)
("?" . dashboard-hydra/body))
:hook (dashboard-mode . (lambda ()
;; No title
(setq-local frame-title-format nil)
;; Enable `page-break-lines-mode'
(when (fboundp 'page-break-lines-mode)
(page-break-lines-mode 1))))
:init
(setq dashboard-banner-logo-title "CENTAUR EMACS - Enjoy Programming & Writing"
dashboard-startup-banner (or centaur-logo 'official)
dashboard-page-separator "\n\f\n"
dashboard-projects-backend 'project-el
dashboard-path-style 'truncate-middle
dashboard-path-max-length 60
dashboard-center-content t
dashboard-show-shortcuts nil
dashboard-items '((recents . 10)
(bookmarks . 5)
(projects . 5))
dashboard-set-init-info t
dashboard-display-icons-p #'icons-displayable-p
dashboard-icon-type 'nerd-icons
dashboard-set-file-icons centaur-icon
dashboard-set-heading-icons centaur-icon
dashboard-heading-icons '((recents . "nf-oct-history")
(bookmarks . "nf-oct-bookmark")
(agenda . "nf-oct-calendar")
(projects . "nf-oct-briefcase")
(registers . "nf-oct-database"))
dashboard-set-footer t
dashboard-footer-icon (cond
((icons-displayable-p)
(nerd-icons-octicon "nf-oct-heart" :height 1.2 :face 'nerd-icons-lred))
(t (propertize ">" 'face 'dashboard-footer)))
dashboard-set-navigator t
dashboard-navigator-buttons
`(((,(when (icons-displayable-p)
(nerd-icons-mdicon "nf-md-github" :height 1.5))
"Homepage" "Browse homepage"
(lambda (&rest _) (browse-url centaur-homepage)))
(,(when (icons-displayable-p)
(nerd-icons-mdicon "nf-md-backup_restore" :height 1.5))
"Restore" "Restore previous session"
(lambda (&rest _) (restore-previous-session)))
(,(when (icons-displayable-p)
(nerd-icons-mdicon "nf-md-tools" :height 1.5))
"Settings" "Open custom file"
(lambda (&rest _) (find-file custom-file)))
(,(when (icons-displayable-p)
(nerd-icons-mdicon "nf-md-update" :height 1.5))
"Update" "Update Centaur Emacs"
(lambda (&rest _) (centaur-update)))
(,(if (icons-displayable-p)
(nerd-icons-mdicon "nf-md-help" :height 1.5)
"?")
"" "Help (?/h)"
(lambda (&rest _) (dashboard-hydra/body))
font-lock-string-face))))
(dashboard-setup-startup-hook)
:config
;; Insert copyright
;; @see https://github.com/emacs-dashboard/emacs-dashboard/issues/219
(defun my-dashboard-insert-copyright ()
"Insert copyright in the footer."
(when dashboard-set-footer
(dashboard-insert-center
(propertize (format "\nPowered by Vincent Zhang, %s\n" (format-time-string "%Y"))
'face 'font-lock-comment-face))))
(advice-add #'dashboard-insert-footer :after #'my-dashboard-insert-copyright)
(defun restore-previous-session ()
"Restore the previous session."
(interactive)
(when (bound-and-true-p persp-mode)
(restore-session persp-auto-save-fname)))
(defun restore-session (fname)
"Restore the specified session."
(interactive (list (read-file-name "Load perspectives from a file: "
persp-save-dir)))
(when (bound-and-true-p persp-mode)
(message "Restoring session...")
(quit-window t)
(condition-case-unless-debug err
(persp-load-state-from-file fname)
(error "Error: Unable to restore session -- %s" err))
(message "Restoring session...done")))
(defun dashboard-goto-recent-files ()
"Go to recent files."
(interactive)
(let ((func (local-key-binding "r")))
(and func (funcall func))))
(defun dashboard-goto-projects ()
"Go to projects."
(interactive)
(let ((func (local-key-binding "p")))
(and func (funcall func))))
(defun dashboard-goto-bookmarks ()
"Go to bookmarks."
(interactive)
(let ((func (local-key-binding "m")))
(and func (funcall func))))
(defvar dashboard-recover-layout-p nil
"Wether recovers the layout.")
(defun open-dashboard ()
"Open the *dashboard* buffer and jump to the first widget."
(interactive)
;; Check if need to recover layout
(if (length> (window-list-1)
;; exclude `treemacs' window
(if (and (fboundp 'treemacs-current-visibility)
(eq (treemacs-current-visibility) 'visible))
2
1))
(setq dashboard-recover-layout-p t))
;; Display dashboard in maximized window
(delete-other-windows)
;; Refresh dashboard buffer
(dashboard-refresh-buffer)
;; Jump to the first section
(dashboard-goto-recent-files))
(defun quit-dashboard ()
"Quit dashboard window."
(interactive)
(quit-window t)
(and dashboard-recover-layout-p
(and (bound-and-true-p winner-mode) (winner-undo))
(setq dashboard-recover-layout-p nil)))))
(provide 'init-dashboard)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; init-dashboard.el ends here