From 07e93fe76808bff158a0405b9cd2d7412bd99655 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 4 Jun 2019 02:06:21 +0800 Subject: [PATCH 1/3] Add the navigator below the banner with the customized buttons. --- README.org | 17 ++++++++++++++ dashboard-widgets.el | 53 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 47df488a..53f98437 100644 --- a/README.org +++ b/README.org @@ -102,6 +102,23 @@ To modify heading icons with another icon from all-the-icons octicons: (bookmarks . "book"))) #+END_SRC +To show navigator below the banner: +#+BEGIN_SRC emacs-lisp +(setq dashboard-set-navigator t) +#+END_SRC + +To customize the buttons of the navigator like this: +#+BEGIN_SRC emacs-lisp +;; Format: "icon title help action face" +(setq dashboard-navigator-buttons + `((,(all-the-icons-octicon "mark-github" :height 1.1 :v-adjust 0.0) + "Homepage" + "Browse homepage" + (lambda (&rest _) (browse-url "homepage"))) + ("★" "Star" "Show stars" (lambda (&rest _) (show-stars)) 'warning) + ("?" "Help" "?/h" #'show-help nil))) +#+END_SRC + To show info about the packages loaded and the init time: #+BEGIN_SRC elisp (setq dashboard-set-init-info t) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 68220313..73400ea6 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -54,8 +54,13 @@ to the specified width, with aspect ratio preserved." :type 'boolean :group 'dashboard) +(defcustom dashboard-set-navigator nil + "When non nil, a navigator will be displayed under the banner." + :type 'boolean + :group 'dashboard) + (defcustom dashboard-set-init-info t - "When non nil, init info will be displayed under banner." + "When non nil, init info will be displayed under the banner." :type 'boolean :group 'dashboard) @@ -88,6 +93,13 @@ to the specified width, with aspect ratio preserved." (defvar dashboard-banner-logo-title "Welcome to Emacs!" "Specify the startup banner.") +(defvar dashboard-navigator-buttons nil + "Specify the navigator buttons. +The format is: 'icon title help action face'. + +Example: +'((\"☆\" \"Star\" \"Show stars\" (lambda (&rest _) (show-stars)) 'warning))") + (defvar dashboard-init-info ;; Check if package.el was loaded and if package loading was enabled (if (bound-and-true-p package-enable-at-startup) @@ -176,6 +188,11 @@ If nil it is disabled. Possible values for list-type are: "Face used for the banner title." :group 'dashboard) +(defface dashboard-navigator + '((t (:inherit font-lock-keyword-face))) + "Face used for the havigator." + :group 'dashboard) + (defface dashboard-heading '((t (:inherit font-lock-keyword-face))) "Face used for widget headings." @@ -365,8 +382,42 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (if (image-type-available-p (intern (file-name-extension banner))) (dashboard-insert-image-banner banner) (dashboard-insert-ascii-banner-centered banner)) + (dashboard-insert-navigator) (dashboard-insert-init-info))))) +(defun dashboard-insert-navigator () + "Insert Navigator of the dashboard." + (when (and dashboard-set-navigator dashboard-navigator-buttons) + (insert "\n") + (dolist (btn dashboard-navigator-buttons) + (let ((icon (car btn)) + (title (or (cadr btn) "")) + (help (or (cadr (cdr btn)) "")) + (action (cadr (cddr btn))) + (face (or (cddr (cddr btn)) 'dashboard-navigator))) + (widget-create 'item + :tag (concat + (when icon + (concat + (propertize icon 'face `(:inherit + ,(get-text-property 0 'face icon) + :inherit + ,face)) + (propertize " " 'face 'variable-pitch))) + (propertize title 'face face)) + :help-echo help + :action action + :mouse-face 'highlight + :button-prefix (propertize "[" 'face face) + :button-suffix (propertize "]" 'face face) + :format "%[%t%]") + (insert " "))) + (let* ((width (current-column))) + (beginning-of-line) + (dashboard-center-line (make-string width ?\s)) + (end-of-line)) + (insert "\n\n\n"))) + (defmacro dashboard-insert-section (section-name list list-size shortcut action &rest widget-params) "Add a section with SECTION-NAME and LIST of LIST-SIZE items to the dashboard. SHORTCUT is the keyboard shortcut used to access the section. From 180ab5bebf74eca9e867fb495d79cc6c9f1f3ed4 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 4 Jun 2019 21:30:02 +0800 Subject: [PATCH 2/3] Add options for prefix and suffix of buttons. --- README.org | 4 ++-- dashboard-widgets.el | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.org b/README.org index 53f98437..8858fdfd 100644 --- a/README.org +++ b/README.org @@ -109,14 +109,14 @@ To show navigator below the banner: To customize the buttons of the navigator like this: #+BEGIN_SRC emacs-lisp -;; Format: "icon title help action face" +;; Format: "icon title help action face prefix suffix" (setq dashboard-navigator-buttons `((,(all-the-icons-octicon "mark-github" :height 1.1 :v-adjust 0.0) "Homepage" "Browse homepage" (lambda (&rest _) (browse-url "homepage"))) ("★" "Star" "Show stars" (lambda (&rest _) (show-stars)) 'warning) - ("?" "Help" "?/h" #'show-help nil))) + ("?" "Help" "?/h" #'show-help nil "<" ">"))) #+END_SRC To show info about the packages loaded and the init time: diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 73400ea6..1f9f8f7f 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -95,10 +95,10 @@ to the specified width, with aspect ratio preserved." (defvar dashboard-navigator-buttons nil "Specify the navigator buttons. -The format is: 'icon title help action face'. +The format is: 'icon title help action face prefix suffix'. Example: -'((\"☆\" \"Star\" \"Show stars\" (lambda (&rest _) (show-stars)) 'warning))") +'((\"☆\" \"Star\" \"Show stars\" (lambda (&rest _) (show-stars)) 'warning \"[\" \"]\"))") (defvar dashboard-init-info ;; Check if package.el was loaded and if package loading was enabled @@ -390,11 +390,13 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (when (and dashboard-set-navigator dashboard-navigator-buttons) (insert "\n") (dolist (btn dashboard-navigator-buttons) - (let ((icon (car btn)) - (title (or (cadr btn) "")) - (help (or (cadr (cdr btn)) "")) - (action (cadr (cddr btn))) - (face (or (cddr (cddr btn)) 'dashboard-navigator))) + (let* ((icon (car btn)) + (title (or (cadr btn) "")) + (help (or (cadr (cdr btn)) "")) + (action (or (cadr (cddr btn)) #'ignore)) + (face (or (cadr (cddr (cdr btn))) 'dashboard-navigator)) + (prefix (or (cadr (cddr (cddr btn))) (propertize "[" 'face face))) + (suffix (or (cadr (cddr (cddr (cdr btn)))) (propertize "]" 'face face)))) (widget-create 'item :tag (concat (when icon @@ -408,8 +410,8 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." :help-echo help :action action :mouse-face 'highlight - :button-prefix (propertize "[" 'face face) - :button-suffix (propertize "]" 'face face) + :button-prefix prefix + :button-suffix suffix :format "%[%t%]") (insert " "))) (let* ((width (current-column))) From 09bbfaa0399be8a1dd7cffc827ad16eb0abc3991 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 4 Jun 2019 23:16:01 +0800 Subject: [PATCH 3/3] Make the navigator compact. --- dashboard-widgets.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 1f9f8f7f..967d316c 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -388,7 +388,6 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (defun dashboard-insert-navigator () "Insert Navigator of the dashboard." (when (and dashboard-set-navigator dashboard-navigator-buttons) - (insert "\n") (dolist (btn dashboard-navigator-buttons) (let* ((icon (car btn)) (title (or (cadr btn) "")) @@ -418,7 +417,7 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (beginning-of-line) (dashboard-center-line (make-string width ?\s)) (end-of-line)) - (insert "\n\n\n"))) + (insert "\n\n"))) (defmacro dashboard-insert-section (section-name list list-size shortcut action &rest widget-params) "Add a section with SECTION-NAME and LIST of LIST-SIZE items to the dashboard.