diff --git a/README.org b/README.org index 47df488a..8858fdfd 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 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 "<" ">"))) +#+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..967d316c 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 prefix suffix'. + +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,43 @@ 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) + (dolist (btn dashboard-navigator-buttons) + (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 + (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 prefix + :button-suffix suffix + :format "%[%t%]") + (insert " "))) + (let* ((width (current-column))) + (beginning-of-line) + (dashboard-center-line (make-string width ?\s)) + (end-of-line)) + (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. SHORTCUT is the keyboard shortcut used to access the section.