-
-
Notifications
You must be signed in to change notification settings - Fork 141
add nerd-icons support to dashboard #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jcs090218
merged 9 commits into
emacs-dashboard:master
from
rainstormstudio:feat/nerd-icons
May 2, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2a0c4c3
add nerd-icons support
rainstormstudio 02baee9
Fix icons: agenda-item and remote-path.
seagle0128 c4770ba
Refactor options.
seagle0128 505961e
Merge branch 'emacs-dashboard:master' into feat/nerd-icons
rainstormstudio aa093ea
Merge branch 'emacs-dashboard:master' into feat/nerd-icons
rainstormstudio 3bfef0e
declare nerd-icons-octicon
rainstormstudio 8822475
use `pcase` for consistency
rainstormstudio 14a0126
Merge branch 'feat/nerd-icons' of https://github.com/rainstormstudio/…
rainstormstudio e40819c
replace other `cond` with `pcase` for consistency
rainstormstudio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,10 @@ | |
(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 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") | ||
|
@@ -98,6 +102,53 @@ preserved." | |
:type 'integer | ||
:group 'dashboard) | ||
|
||
(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 | ||
: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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can use (pcase v
('all-the-icons
(unless (require 'all-the-icons nil t)
(setq v nil)))
('nerd-icons
(unless (require 'nerd-icons nil t)
(setq v nil)))) |
||
(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 | ||
(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 | ||
(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) | ||
|
||
(defcustom dashboard-set-heading-icons nil | ||
"When non nil, heading sections will have icons." | ||
:type 'boolean | ||
|
@@ -213,14 +264,43 @@ 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." | ||
(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." | ||
(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." | ||
(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 (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) | ||
(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 | ||
|
@@ -309,19 +389,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 +451,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 +545,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 +811,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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to prevent require in the top level. Let's prevent it by making sure the
dashboard-set-heading-icons
is non-nil:Make sure to place
dashboard-set-heading-icons
to the front to avoid compile error.