summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2023-05-28 12:48:18 +0800
committerJSDurand <mmemmew@gmail.com>2023-05-28 12:48:18 +0800
commit8b925fc10de905e80a44fa7df8262c1b39a2e829 (patch)
tree90b1e1c2efd6501608f1ca800aef763fc4dd1902
parent49003568e6d7819b955f15ac2eeb8887ded11e34 (diff)
dashboard: convenient functions
* dashboard.el (dashboard-mode): A dedicated mode with convenient access functions. (dashboard-preload): A macro to define convenient functions easily.
-rw-r--r--dashboard.el42
1 files changed, 41 insertions, 1 deletions
diff --git a/dashboard.el b/dashboard.el
index b285547..cd4886c 100644
--- a/dashboard.el
+++ b/dashboard.el
@@ -60,11 +60,51 @@ If FORCE is non-nil, re-gerenate the dashboard buffer."
(read-only-mode 1)
(set 'mode-line-format '("%e" (:eval (modeline-format-dashboard))))
(set 'default-directory user-emacs-directory)
- (view-mode 1))))
+ (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.")
+
+(define-key dashboard-mode-map (vector ?l) #'blist)
+(define-key dashboard-mode-map (vector ?b) #'bookmark-jump)
+(define-key dashboard-mode-map (vector ?a) #'dashboard-org-agenda)
+(define-key dashboard-mode-map (vector ?c) #'dashboard-org-capture)
+(define-key dashboard-mode-map (vector ?l) #'dashboard-org-store-link)
+
+;; 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")
+
;;; Modify killing buffers
;;;###autoload