;;; 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 (&optional force) "Create the dashboard buffer. If FORCE is non-nil, re-gerenate the dashboard buffer." (interactive) (let ((dashboard-exists-p (get-buffer dashboard-buffer-name)) (dashboard (get-buffer-create dashboard-buffer-name)) (inhibit-read-only t)) (cond ((and (not force) dashboard-exists-p) (switch-to-buffer dashboard)) (t (with-current-buffer dashboard (setq buffer-undo-list t) (erase-buffer) (cond ((display-graphic-p) (let ((image (create-image (expand-file-name "cat.png" user-emacs-directory)))) (insert (make-string 3 10) (center-string-in-width (propertize " " 'display image 'rear-nonsticky '(display)) (round (- (window-body-width) (* (car (image-size image)) 1))))))) ((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))) (set-buffer-modified-p nil) (read-only-mode 1) (set 'mode-line-format '("%e" (:eval (modeline-format-dashboard)))) (set 'default-directory user-emacs-directory) (view-mode 1) (dashboard-mode)))) dashboard)) (set 'initial-buffer-choice #'dashboard) ;;; Dedicated major mode (define-derived-mode dashboard-mode nil "Dashboard" "Major mode for the dashboard buffer. The main purpose is to provide a dedicated keymap to access common functionalities more conveniently.") (let ((m dashboard-mode-map)) (define-key m (vector ?l) #'blist) (define-key m (vector ?L) #'rlist-list-registers) (define-key m (vector ?b) #'bookmark-jump) (define-key m (vector ?B) #'durand-jump-bookmark-new-tab) (define-key m (vector ?T) #'modeline-toggle) (define-key m (vector ?t) #'durand-view-timers-or-temps) (define-key m (vector ?o) #'durand-open-object) (define-key m (vector ?g) #'gnus) (define-key m (vector ?a) #'dashboard-org-agenda) (define-key m (vector ?c) #'dashboard-clear) (define-key m (vector ?C) #'dashboard-org-capture) (define-key m (vector ?p) #'project-switch-project) (define-key m (vector ?x) #'execute-extended-command)) ;; load Org if not loaded already (defmacro dashboard-preload (symbol file-to-load) "Define a dispatch function for the symbol." (list 'defun (intern (format "dashboard-%s" (symbol-name symbol))) (list (intern "&rest") 'args) (format "A dispatch function for `%s'. This function loads \"%s\" if `%s' is not already loaded, and calls `%s' otherwise." (symbol-name symbol) file-to-load (symbol-name symbol) (symbol-name symbol)) (list 'interactive (list #'list 'current-prefix-arg t)) (list 'cond (list (list 'not (list #'functionp `(quote ,symbol))) (list #'load-config file-to-load)) (list (list #'funcall `(quote ,symbol) 'args))))) (dashboard-preload org-agenda "org-conf.el") (dashboard-preload org-capture "org-conf.el") (dashboard-preload org-store-link "org-conf.el") ;; ibuffer clear (defun dashboard-clear () "Run `durand-ibuffer-clear' while in the dashboard." (interactive) (let ((inhibit-message t)) (ibuffer) (durand-ibuffer-clear))) ;;; 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. ;; "Please don't kill the dashboard buffer" (not (message "न निहन्याद्घाटीफलकनिधानकम्"))) (t))) (add-hook 'kill-buffer-query-functions 'dont-kill-dashboard-fn) (provide 'dashboard) ;;; dashboard.el ends here.