From 2a0c4c3b80d49c024e3b0604efcb06009c3a9cb0 Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Fri, 14 Apr 2023 14:53:26 -0400 Subject: [PATCH 1/6] add nerd-icons support --- dashboard-widgets.el | 148 +++++++++++++++++++++++++++++-------------- 1 file changed, 102 insertions(+), 46 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index fff700e..d438d8e 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -31,6 +31,9 @@ (declare-function all-the-icons-icon-for-file "ext:all-the-icons.el") (declare-function all-the-icons-fileicon "ext:data-fileicons.el") (declare-function all-the-icons-octicon "ext:data-octicons.el") +(declare-function nerd-icons-icon-for-dir "ext:nerd-icons.el") +(declare-function nerd-icons-icon-for-file "ext:nerd-icons.el") +(declare-function nerd-icons-sucicon "ext:nerd-icons.el") (declare-function bookmark-get-filename "ext:bookmark.el") (declare-function bookmark-all-names "ext:bookmark.el") (declare-function calendar-date-compare "ext:calendar.el") @@ -98,6 +101,53 @@ preserved." :type 'integer :group 'dashboard) +(defcustom dashboard-heading-icons + '((recents . "history") + (bookmarks . "bookmark") + (agenda . "calendar") + (projects . "rocket") + (registers . "database")) + + "Association list for the icons of the heading sections. +Will be of the form `(list-type . icon-name-string)`. +If nil it is disabled. Possible values for list-type are: +`recents' `bookmarks' `projects' `agenda' `registers'" + :type '(repeat (alist :key-type symbol :value-type string)) + :group 'dashboard) + +(defvar dashboard--agenda-item-icon nil) +(defvar dashboard--remote-path-icon nil) +(defcustom dashboard-icon-type 'all-the-icons + "Icon type used for dashboard. +The value can be one of: `all-the-icons', `nerd-icons'." + :type 'symbol + :group 'dashboard + :set + (lambda (k v) + (and (eq v 'all-the-icons) (not (require 'all-the-icons nil t)) (setq v nil)) + (and (eq v 'nerd-icons) (not (require 'nerd-icons nil t)) (setq v nil)) + (set k v) + (setq dashboard--agenda-item-icon + (pcase (symbol-value k) + ('all-the-icons (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) + ('nerd-icons (nerd-icons-octicon "nf-oct-primitive_dot" :height 1.0 :v-adjust 0.01)))) + (setq dashboard--remote-path-icon + (pcase (symbol-value k) + ('all-the-icons (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) + ('nerd-icons (nerd-icons-octicon "nf-oct-radio_tower" :height 1.0 :v-adjust 0.01)))) + (setq dashboard-heading-icons + (pcase (symbol-value k) + ('all-the-icons '((recents . "history") + (bookmarks . "bookmark") + (agenda . "calendar") + (projects . "rocket") + (registers . "database"))) + ('nerd-icons '((recents . "nf-oct-history") + (bookmarks . "nf-oct-bookmark") + (agenda . "nf-oct-calendar") + (projects . "nf-oct-rocket") + (registers . "nf-oct-database"))))))) + (defcustom dashboard-set-heading-icons nil "When non nil, heading sections will have icons." :type 'boolean @@ -213,14 +263,40 @@ predicate value." (funcall dashboard-display-icons-p) dashboard-display-icons-p)) +(defun dashboard-icon-for-dir (dir &rest args) + "Get the formatted icon for DIR. +ARGS should be a plist containing `:height', `:v-adjust', +or `:face' properties." + (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-icon-for-dir dir args)) + ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-icon-for-dir dir args)))) + +(defun dashboard-icon-for-file (file &rest args) + "Get the formatted icon for FILE. +ARGS should be a plist containing `:height', `:v-adjust', +or `:face' properties." + (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-icon-for-file file args)) + ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-icon-for-file file args)))) + +(defun dashboard-octicon (name &rest args) + "Get the formatted octicon. +ARGS should be a plist containing `:height', `:v-adjust', +or `:face' properties." + (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-octicon name args)) + ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-octicon name args)))) + (defcustom dashboard-footer-icon - (if (and (dashboard-display-icons-p) - (or (fboundp 'all-the-icons-fileicon) - (require 'all-the-icons nil 'noerror))) - (all-the-icons-fileicon "emacs" - :height 1.1 - :v-adjust -0.05 - :face 'font-lock-keyword-face) + (if (dashboard-display-icons-p) + (cond + ((eq dashboard-icon-type 'all-the-icons) + (all-the-icons-fileicon "emacs" + :height 1.1 + :v-adjust -0.05 + :face 'font-lock-keyword-face)) + ((eq dashboard-icon-type 'nerd-icons) + (nerd-icons-sucicon "nf-custom-emacs" + :height 1.1 + :v-adjust -0.05 + :face 'font-lock-keyword-face))) (propertize ">" 'face 'dashboard-footer)) "Footer's icon." :type 'string @@ -309,19 +385,6 @@ Set to nil for unbounded." :type 'integer :group 'dashboard) -(defcustom dashboard-heading-icons - '((recents . "history") - (bookmarks . "bookmark") - (agenda . "calendar") - (projects . "rocket") - (registers . "database")) - "Association list for the icons of the heading sections. -Will be of the form `(list-type . icon-name-string)`. -If nil it is disabled. Possible values for list-type are: -`recents' `bookmarks' `projects' `agenda' `registers'" - :type '(repeat (alist :key-type symbol :value-type string)) - :group 'dashboard) - (defcustom dashboard-path-style nil "Style to display path." :type '(choice @@ -384,11 +447,11 @@ If nil it is disabled. Possible values for list-type are: :group 'dashboard) (define-obsolete-face-alias - 'dashboard-text-banner-face 'dashboard-text-banner "1.2.6") + 'dashboard-text-banner-face 'dashboard-text-banner "1.2.6") (define-obsolete-face-alias - 'dashboard-banner-logo-title-face 'dashboard-banner-logo-title "1.2.6") + 'dashboard-banner-logo-title-face 'dashboard-banner-logo-title "1.2.6") (define-obsolete-face-alias - 'dashboard-heading-face 'dashboard-heading "1.2.6") + 'dashboard-heading-face 'dashboard-heading "1.2.6") ;; ;; Util @@ -478,28 +541,23 @@ If MESSAGEBUF is not nil then MSG is also written in message buffer." (defun dashboard-insert-heading (heading &optional shortcut icon) "Insert a widget HEADING in dashboard buffer, adding SHORTCUT, ICON if provided." (when (and (dashboard-display-icons-p) dashboard-set-heading-icons) - ;; Try loading `all-the-icons' - (unless (or (fboundp 'all-the-icons-octicon) - (require 'all-the-icons nil 'noerror)) - (error "Package `all-the-icons' isn't installed")) - (insert (cond ((string-equal heading "Recent Files:") - (all-the-icons-octicon (cdr (assoc 'recents dashboard-heading-icons)) - :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) + (dashboard-octicon (cdr (assoc 'recents dashboard-heading-icons)) + :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) ((string-equal heading "Bookmarks:") - (all-the-icons-octicon (cdr (assoc 'bookmarks dashboard-heading-icons)) - :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) + (dashboard-octicon (cdr (assoc 'bookmarks dashboard-heading-icons)) + :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) ((or (string-equal heading "Agenda for today:") (string-equal heading "Agenda for the coming week:")) - (all-the-icons-octicon (cdr (assoc 'agenda dashboard-heading-icons)) - :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) + (dashboard-octicon (cdr (assoc 'agenda dashboard-heading-icons)) + :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) ((string-equal heading "Registers:") - (all-the-icons-octicon (cdr (assoc 'registers dashboard-heading-icons)) - :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) + (dashboard-octicon (cdr (assoc 'registers dashboard-heading-icons)) + :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) ((string-equal heading "Projects:") - (all-the-icons-octicon (cdr (assoc 'projects dashboard-heading-icons)) - :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) + (dashboard-octicon (cdr (assoc 'projects dashboard-heading-icons)) + :height 1.2 :v-adjust 0.0 :face 'dashboard-heading)) ((not (null icon)) icon) (t " "))) (insert " ")) @@ -749,21 +807,19 @@ to widget creation." (insert "\n ") (when (and (dashboard-display-icons-p) - dashboard-set-file-icons - (or (fboundp 'all-the-icons-icon-for-dir) - (require 'all-the-icons nil 'noerror))) + dashboard-set-file-icons) (let* ((path (car (last (split-string ,@rest " - ")))) (icon (if (and (not (file-remote-p path)) (file-directory-p path)) - (all-the-icons-icon-for-dir path nil "") + (dashboard-icon-for-dir path nil "") (cond ((or (string-equal ,section-name "Agenda for today:") (string-equal ,section-name "Agenda for the coming week:")) - (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) + (dashboard--agenda-item-icon)) ((file-remote-p path) - (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) - (t (all-the-icons-icon-for-file (file-name-nondirectory path) - :v-adjust -0.05)))))) + (dashboard--remote-path-icon)) + (t (dashboard-icon-for-file (file-name-nondirectory path) + :v-adjust -0.05)))))) (setq tag (concat icon " " ,@rest)))) (widget-create 'item From 02baee9eaf6b06e814c11c280f739ea63b8bf5d9 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 17 Apr 2023 10:18:53 +0800 Subject: [PATCH 2/6] Fix icons: agenda-item and remote-path. --- dashboard-widgets.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index d438d8e..6a11d48 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -815,9 +815,9 @@ to widget creation." (cond ((or (string-equal ,section-name "Agenda for today:") (string-equal ,section-name "Agenda for the coming week:")) - (dashboard--agenda-item-icon)) + dashboard--agenda-item-icon) ((file-remote-p path) - (dashboard--remote-path-icon)) + dashboard--remote-path-icon) (t (dashboard-icon-for-file (file-name-nondirectory path) :v-adjust -0.05)))))) (setq tag (concat icon " " ,@rest)))) From c4770bab8455c0e4b6f2e5c7f9da692c1cdecf30 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Mon, 17 Apr 2023 11:17:25 +0800 Subject: [PATCH 3/6] Refactor options. --- dashboard-widgets.el | 80 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 6a11d48..6ad03ec 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -101,23 +101,8 @@ preserved." :type 'integer :group 'dashboard) -(defcustom dashboard-heading-icons - '((recents . "history") - (bookmarks . "bookmark") - (agenda . "calendar") - (projects . "rocket") - (registers . "database")) - - "Association list for the icons of the heading sections. -Will be of the form `(list-type . icon-name-string)`. -If nil it is disabled. Possible values for list-type are: -`recents' `bookmarks' `projects' `agenda' `registers'" - :type '(repeat (alist :key-type symbol :value-type string)) - :group 'dashboard) - -(defvar dashboard--agenda-item-icon nil) -(defvar dashboard--remote-path-icon nil) -(defcustom dashboard-icon-type 'all-the-icons +(defcustom dashboard-icon-type (or (require 'nerd-icons nil t) + (require 'all-the-icons nil t)) "Icon type used for dashboard. The value can be one of: `all-the-icons', `nerd-icons'." :type 'symbol @@ -126,27 +111,42 @@ The value can be one of: `all-the-icons', `nerd-icons'." (lambda (k v) (and (eq v 'all-the-icons) (not (require 'all-the-icons nil t)) (setq v nil)) (and (eq v 'nerd-icons) (not (require 'nerd-icons nil t)) (setq v nil)) - (set k v) - (setq dashboard--agenda-item-icon - (pcase (symbol-value k) - ('all-the-icons (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) - ('nerd-icons (nerd-icons-octicon "nf-oct-primitive_dot" :height 1.0 :v-adjust 0.01)))) - (setq dashboard--remote-path-icon - (pcase (symbol-value k) - ('all-the-icons (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) - ('nerd-icons (nerd-icons-octicon "nf-oct-radio_tower" :height 1.0 :v-adjust 0.01)))) - (setq dashboard-heading-icons - (pcase (symbol-value k) - ('all-the-icons '((recents . "history") - (bookmarks . "bookmark") - (agenda . "calendar") - (projects . "rocket") - (registers . "database"))) - ('nerd-icons '((recents . "nf-oct-history") - (bookmarks . "nf-oct-bookmark") - (agenda . "nf-oct-calendar") - (projects . "nf-oct-rocket") - (registers . "nf-oct-database"))))))) + (set k v))) + +(defcustom dashboard-heading-icons + (pcase dashboard-icon-type + ('all-the-icons '((recents . "history") + (bookmarks . "bookmark") + (agenda . "calendar") + (projects . "rocket") + (registers . "database"))) + ('nerd-icons '((recents . "nf-oct-history") + (bookmarks . "nf-oct-bookmark") + (agenda . "nf-oct-calendar") + (projects . "nf-oct-rocket") + (registers . "nf-oct-database")))) + "Association list for the icons of the heading sections. +Will be of the form `(list-type . icon-name-string)`. +If nil it is disabled. Possible values for list-type are: +`recents' `bookmarks' `projects' `agenda' `registers'" + :type '(repeat (alist :key-type symbol :value-type string)) + :group 'dashboard) + +(defcustom dashboard-agenda-item-icon + (cond + ((eq dashboard-icon-type 'all-the-icons) (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) + ((eq dashboard-icon-type 'nerd-icons) (nerd-icons-octicon "nf-oct-primitive_dot" :height 1.0 :v-adjust 0.01))) + "Agenda item icon." + :type 'string + :group 'dashboard) + +(defcustom dashboard-remote-path-icon + (cond + ((eq dashboard-icon-type 'all-the-icons) (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) + ((eq dashboard-icon-type 'nerd-icons) (nerd-icons-octicon "nf-oct-radio_tower" :height 1.0 :v-adjust 0.01))) + "Remote path icon." + :type 'string + :group 'dashboard) (defcustom dashboard-set-heading-icons nil "When non nil, heading sections will have icons." @@ -815,9 +815,9 @@ to widget creation." (cond ((or (string-equal ,section-name "Agenda for today:") (string-equal ,section-name "Agenda for the coming week:")) - dashboard--agenda-item-icon) + dashboard-agenda-item-icon) ((file-remote-p path) - dashboard--remote-path-icon) + dashboard-remote-path-icon) (t (dashboard-icon-for-file (file-name-nondirectory path) :v-adjust -0.05)))))) (setq tag (concat icon " " ,@rest)))) From 3bfef0eecab5e2576576ea580585eb7c076c214a Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Tue, 2 May 2023 17:30:08 -0400 Subject: [PATCH 4/6] declare nerd-icons-octicon --- dashboard-widgets.el | 1 + 1 file changed, 1 insertion(+) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 6ad03ec..7a2b4f4 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -34,6 +34,7 @@ (declare-function nerd-icons-icon-for-dir "ext:nerd-icons.el") (declare-function nerd-icons-icon-for-file "ext:nerd-icons.el") (declare-function nerd-icons-sucicon "ext:nerd-icons.el") +(declare-function nerd-icons-octicon "ext:nerd-icons.el") (declare-function bookmark-get-filename "ext:bookmark.el") (declare-function bookmark-all-names "ext:bookmark.el") (declare-function calendar-date-compare "ext:calendar.el") From 88224756542d3ecdabca4027aa715b2f373728e5 Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Tue, 2 May 2023 17:33:50 -0400 Subject: [PATCH 5/6] use `pcase` for consistency --- dashboard-widgets.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 7a2b4f4..515c218 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -134,17 +134,17 @@ If nil it is disabled. Possible values for list-type are: :group 'dashboard) (defcustom dashboard-agenda-item-icon - (cond - ((eq dashboard-icon-type 'all-the-icons) (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) - ((eq dashboard-icon-type 'nerd-icons) (nerd-icons-octicon "nf-oct-primitive_dot" :height 1.0 :v-adjust 0.01))) + (pcase dashboard-icon-type + ('all-the-icons (all-the-icons-octicon "primitive-dot" :height 1.0 :v-adjust 0.01)) + ('nerd-icons (nerd-icons-octicon "nf-oct-primitive_dot" :height 1.0 :v-adjust 0.01))) "Agenda item icon." :type 'string :group 'dashboard) (defcustom dashboard-remote-path-icon - (cond - ((eq dashboard-icon-type 'all-the-icons) (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) - ((eq dashboard-icon-type 'nerd-icons) (nerd-icons-octicon "nf-oct-radio_tower" :height 1.0 :v-adjust 0.01))) + (pcase dashboard-icon-type + ('all-the-icons (all-the-icons-octicon "radio-tower" :height 1.0 :v-adjust 0.01)) + ('nerd-icons (nerd-icons-octicon "nf-oct-radio_tower" :height 1.0 :v-adjust 0.01))) "Remote path icon." :type 'string :group 'dashboard) From e40819c8b76cf7184fb0099e1ca1a83968f7464f Mon Sep 17 00:00:00 2001 From: Daniel Ding Date: Tue, 2 May 2023 17:45:15 -0400 Subject: [PATCH 6/6] replace other `cond` with `pcase` for consistency --- dashboard-widgets.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/dashboard-widgets.el b/dashboard-widgets.el index 515c218..5ab1ea2 100644 --- a/dashboard-widgets.el +++ b/dashboard-widgets.el @@ -268,36 +268,39 @@ predicate value." "Get the formatted icon for DIR. ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties." - (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-icon-for-dir dir args)) - ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-icon-for-dir dir args)))) + (pcase dashboard-icon-type + ('all-the-icons (apply #'all-the-icons-icon-for-dir dir args)) + ('nerd-icons (apply #'nerd-icons-icon-for-dir dir args)))) (defun dashboard-icon-for-file (file &rest args) "Get the formatted icon for FILE. ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties." - (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-icon-for-file file args)) - ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-icon-for-file file args)))) + (pcase dashboard-icon-type + ('all-the-icons (apply #'all-the-icons-icon-for-file file args)) + ('nerd-icons (apply #'nerd-icons-icon-for-file file args)))) (defun dashboard-octicon (name &rest args) "Get the formatted octicon. ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties." - (cond ((eq dashboard-icon-type 'all-the-icons) (apply #'all-the-icons-octicon name args)) - ((eq dashboard-icon-type 'nerd-icons) (apply #'nerd-icons-octicon name args)))) + (pcase dashboard-icon-type + ('all-the-icons (apply #'all-the-icons-octicon name args)) + ('nerd-icons (apply #'nerd-icons-octicon name args)))) (defcustom dashboard-footer-icon (if (dashboard-display-icons-p) - (cond - ((eq dashboard-icon-type 'all-the-icons) - (all-the-icons-fileicon "emacs" - :height 1.1 - :v-adjust -0.05 - :face 'font-lock-keyword-face)) - ((eq dashboard-icon-type 'nerd-icons) - (nerd-icons-sucicon "nf-custom-emacs" - :height 1.1 - :v-adjust -0.05 - :face 'font-lock-keyword-face))) + (pcase dashboard-icon-type + ('all-the-icons + (all-the-icons-fileicon "emacs" + :height 1.1 + :v-adjust -0.05 + :face 'font-lock-keyword-face)) + ('nerd-icons + (nerd-icons-sucicon "nf-custom-emacs" + :height 1.1 + :v-adjust -0.05 + :face 'font-lock-keyword-face))) (propertize ">" 'face 'dashboard-footer)) "Footer's icon." :type 'string