summaryrefslogtreecommitdiff
path: root/dashboard.el
blob: c608b3496f30e5399d8c6574807c660fbd8e646a (plain)
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
;;; dashboard.el --- My daashboard -*- lexical-binding: t; -*-

;;;###autoload
(defvar dashboard-buffer-name "durand"
  "The name of the buffer for the dashboard.")

;;;###autoload
(defvar dashboard-cat-text
  (list
   "                                      "
   "                       /\\             "
   "                      /  \\            "
   "                     /    =\\=         "
   "                    /  -     \\=-----  "
   "                   /  |.|          /  "
   "                 \\\\    -   -      /   "
   "                  \\\\      |.|    |    "
   "                 / \\\\      -    /     "
   "                /   \\\\         /      "
   "   ||==========|     ========\\=|      "
   "   ||==========| --            |      "
   "               | ||     /====  |      "
   "               == |    /     \\  \\     "
   "                  |   |       \\  \\    "
   "                   ====        ====   ")
  "A clumsy text representation of a cute cat.")

;;;###autoload
(defun dashboard ()
  "Create the dashboard buffer."
  (interactive)
  (let ((dashboard-exists-p (get-buffer dashboard-buffer-name))
        (dashboard (get-buffer-create dashboard-buffer-name)))
    (cond
     (dashboard-exists-p (switch-to-buffer dashboard))
     (t
      (with-current-buffer dashboard
        (cond
         ((display-graphic-p)
          (let ((image (create-image "~/.doom.d/banners/default.png")))
            (insert
             (make-string 3 10)
             (center-string-in-width
              (propertize " " 'display image 'rear-nonsticky '(display))
              (round (- (window-body-width)
                        (* (car (image-size image)) 0.7)))))))
         ((mapc (function
                 (lambda (str)
                   (insert
                    (center-string-in-width str (- (window-body-width) 13))
                    "\n")))
                dashboard-cat-text)))
        (newline 5)
        (insert (center-string-in-width "Dashboard" (window-body-width)))
        (read-only-mode 1)
        (set 'mode-line-format '("%e" (:eval (modeline-format-dashboard))))
        (view-mode 1))))
    dashboard))

(set 'initial-buffer-choice #'dashboard)

;;; Modify killing buffers

;;;###autoload
(defun dont-kill-dashboard-fn ()
  "Don't kill the dashboard buffer."
  (cond
   ((eq (current-buffer) (get-buffer dashboard-buffer-name))
    ;; The function message returns the message, so applying not will
    ;; produce nil as needed.
    (not (message "Don't kill the dashboard buffer.")))
   (t)))

(add-hook 'kill-buffer-query-functions 'dont-kill-dashboard-fn)

(provide 'dashboard)
;;; dashboard.el ends here.