-
-
Notifications
You must be signed in to change notification settings - Fork 123
/
scimax-dashboard.el
329 lines (294 loc) · 9.04 KB
/
scimax-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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
;;; scimax-dashboard.el --- Dashboard for scimax
;;; Commentary:
;; This module creates a dashboard splash screen for scimax. It
;; builds off of https://github.com/rakanalh/emacs-dashboard to
;; provide a starting point for you when you first open emacs.
;;
;; `scimax-dashboard' will open the dashboard any time.
;;
;; Most sections are customized to be more functional than default.
;;
;; These key bindings are different than those provided by `dashboard':
;; a - jump to any button and open it
;; i - previous line
;; s-i previous section
;; k - next line
;; s-k next section
;; o - open the button at point
;; ? - show the keymap
;;; Code:
(require 'cl-lib)
(require 'avy)
(require 'counsel)
(require 'dashboard)
(defcustom scimax-dashboard-check-git-updates t
"When non-nil check for updates."
:group 'scimax-dashboard
:type 'boolean)
(use-package dashboard
:ensure t
:diminish dashboard-mode
:bind (:map dashboard-mode-map
("a" . scimax-dashboard-jump-to-button)
("i" . previous-line)
("k" . forward-line)
("s-i" . dashboard-previous-section)
("j" . dashboard-previous-section)
("s-k" . dashboard-next-section)
("l" . dashboard-next-section)
("o" . widget-button-click)
("?" . scimax-dashboard-describe-keys))
:config
(setq dashboard-banner-logo-title "Awesome editing for scientists and engineers")
(setq dashboard-startup-banner (expand-file-name "scimax.png" scimax-dir))
(setq dashboard-items '((scimax . t)
(scimax-agenda . 5)
(scimax-recentf . 5)
(scimax-bookmarks . 5)
(scimax-projects . 5)))
(dashboard-setup-startup-hook))
(defun scimax-dashboard-describe-keys ()
"Show the keybindings in the dashboard."
(interactive)
(describe-keymap dashboard-mode-map))
(defun scimax-dashboard ()
"Open the scimax dashboard."
(interactive)
(dashboard-insert-startupify-lists)
(dashboard-refresh-buffer))
(defun scimax-dashboard-jump-to-button ()
"Jump to a link in the dashboard with avy."
(interactive)
(let ((marks '())
(ovs (overlay-lists)))
(with-current-buffer "*dashboard*"
(cl-loop for ov in (append (car ovs) (cdr ovs))
do
(when (overlay-get ov 'button)
(push (ov-beg ov) marks))))
(avy-with scimax-dashboard-link
(avy-process
(reverse marks)
(avy--style-fn avy-style)))))
(defun scimax-internet-p ()
"Use ping to see if the internet is available."
(interactive)
(let* ((exe (executable-find "ping"))
(cmd (format "%s github.com"
(cond
((string= system-type "windows-nt")
"ping -n 1 ")
((string= system-type "darwin")
"ping -c 1 ")
(t "ping -c 1")))))
(if exe
(if (= 0 (shell-command cmd))
t
(message-box "%s failed. Check your internet connection." cmd))
(message "You have no ping executable! I cannot check for internet connectivity.")
nil)))
;; * scimax section
(defun scimax-dashboard-scimax-section (&rest args)
"Create the scimax dashboard section."
(dashboard-insert-heading "scimax")
(insert "\n ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(scimax-help))
:mouse-face 'highlight
:help-echo (substitute-command-keys
(format "\\[%s]\n"
"scimax-help"))
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"scimax help")
(insert " ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(scimax/body))
:mouse-face 'highlight
:help-echo (substitute-command-keys
(format "\\[%s]\n"
"scimax/body"))
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"scimax menu")
(insert " ")
(widget-create
'push-button
:action `(lambda (&rest ignore)
(browse-url "https://github.com/jkitchin/scimax"))
:mouse-face 'highlight
:help-echo "Click to open in browser."
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"scimax (Github)")
(insert " ")
(widget-create
'push-button
:action `(lambda (&rest ignore)
(scimax-customize-user))
:mouse-face 'highlight
:help-echo "Click to open user.el"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Customize user.el")
(insert " ")
(widget-create
'push-button
:action `(lambda (&rest ignore)
(customize-apropos "scimax"))
:mouse-face 'highlight
:help-echo "Click to customize scimax related variables."
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Customize scimax")
;; Check if there are updates available
(when (and scimax-dashboard-check-git-updates (scimax-internet-p))
(let ((branch (s-trim (shell-command-to-string "git rev-parse --abbrev-ref HEAD")))
(incoming (string-to-number
(s-trim (shell-command-to-string
"git rev-list master...origin/master --count")))))
(when (> incoming 0)
(insert " ")
(widget-create
'push-button
:action `(lambda (&rest ignore)
(scimax-update))
:button-face '(:foreground "red" :weight bold :underline t)
:help-echo `(format "%s updates are available" ,incoming)
:mouse-face 'highlight
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
" update scimax")))))
(add-to-list 'dashboard-item-generators '(scimax . scimax-dashboard-scimax-section))
;; * Agenda
(defun scimax-dashboard-agenda (&rest args)
"Create our version of recent"
(dashboard-insert-agenda (cdr (assoc 'scimax-agenda dashboard-items)))
(insert "\n ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(org-agenda nil "a"))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Agenda"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Open agenda")
(insert " ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(org-agenda nil "t"))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Agenda"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"TODOs")
(insert " Search by: ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(org-agenda nil "m"))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Search by tag/property"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"tag/prop")
(insert " ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(org-agenda nil "s"))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Search for keywords"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"keyword")
(insert " ")
(widget-create 'push-button
:action `(lambda (&rest ignore)
(org-agenda nil "/"))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "moccur"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"moccur"))
(add-to-list 'dashboard-item-generators '(scimax-agenda . scimax-dashboard-agenda))
;; * recentf
(defun scimax-dashboard-recentf (&rest args)
"Create our version of recent"
(dashboard-insert-recents (cdr (assoc 'scimax-recentf dashboard-items)))
(widget-create 'push-button
:action `(lambda (&rest ignore)
(counsel-recentf))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "counsel-recentf"
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Open another recent file")
(insert "\n ")
)
(add-to-list 'dashboard-item-generators '(scimax-recentf . scimax-dashboard-recentf))
;; * bookmarks
(defun scimax-dashboard-bookmarks (&rest args)
"Create our version of bookmarks"
(dashboard-insert-bookmarks (cdr (assoc 'scimax-bookmarks dashboard-items)))
(insert "\n " )
(widget-create 'push-button
:action `(lambda (&rest ignore)
(counsel-bookmark))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Open another bookmark."
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Open another bookmark"))
(add-to-list 'dashboard-item-generators '(scimax-bookmarks . scimax-dashboard-bookmarks))
;; * projects
(defun scimax-dashboard-projects (&rest args)
"Create our version of projects"
(dashboard-insert-projects (cdr (assoc 'scimax-projects dashboard-items)))
(insert "\n " (widget-create 'push-button
:action `(lambda (&rest ignore)
(projectile-switch-project))
:mouse-face 'highlight
:button-face '(:background "Lightgray" :underline t)
:help-echo "Open another project."
:follow-link "\C-m"
:button-prefix ""
:button-suffix ""
:format "%[%t%]"
"Open another project")))
(add-to-list 'dashboard-item-generators '(scimax-projects . scimax-dashboard-projects))
(provide 'scimax-dashboard)
;;; scimax-dashboard.el ends here