Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(icons): Add custom arguments for icons #461

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
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* Agenda tags format (#441)
* Make icon display predicate customizeable (#442)
* Add support for nerd-icons (#451)
* Add custom variables for icon's arguments (#461)

## 1.7.0
> Released Feb 21, 2020
Expand Down
66 changes: 35 additions & 31 deletions dashboard-widgets.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@ If nil it is disabled. Possible values for list-type are:
:type '(repeat (alist :key-type symbol :value-type string))
:group 'dashboard)

(defcustom dashboard-heading-icon-height 1.2
"The height of the heading icon."
:type 'float
:group 'dashboard)

(defcustom dashboard-heading-icon-v-adjust 0.0
"The v-adjust of the heading icon."
:type 'float
: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))
Expand Down Expand Up @@ -298,17 +308,15 @@ or `:face' properties."

(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."
ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties."
(dashboard-replace-displayable
(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."
ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties."
(dashboard-replace-displayable
(pcase dashboard-icon-type
('all-the-icons (apply #'all-the-icons-octicon name args))
Expand Down Expand Up @@ -571,33 +579,29 @@ 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)
(insert
(pcase heading
("Recent Files:"
(dashboard-octicon (cdr (assoc 'recents dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
("Bookmarks:"
(dashboard-octicon (cdr (assoc 'bookmarks dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
((or "Agenda for today:"
"Agenda for the coming week:")
(dashboard-octicon (cdr (assoc 'agenda dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
("Registers:"
(dashboard-octicon (cdr (assoc 'registers dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
("Projects:"
(dashboard-octicon (cdr (assoc 'projects dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
("List Directories:"
(dashboard-octicon (cdr (assoc 'ls-directories dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
("List Files:"
(dashboard-octicon (cdr (assoc 'ls-files dashboard-heading-icons))
:height 1.2 :v-adjust 0.0 :face 'dashboard-heading))
(_
(if (null icon) " " icon))))
(insert " "))
(let ((args `( :height ,dashboard-heading-icon-height
:v-adjust ,dashboard-heading-icon-v-adjust
:face dashboard-heading)))
(insert
(pcase heading
("Recent Files:"
(apply #'dashboard-octicon (cdr (assoc 'recents dashboard-heading-icons)) args))
("Bookmarks:"
(apply #'dashboard-octicon (cdr (assoc 'bookmarks dashboard-heading-icons)) args))
((or "Agenda for today:"
"Agenda for the coming week:")
(apply #'dashboard-octicon (cdr (assoc 'agenda dashboard-heading-icons)) args))
("Registers:"
(apply #'dashboard-octicon (cdr (assoc 'registers dashboard-heading-icons)) args))
("Projects:"
(apply #'dashboard-octicon (cdr (assoc 'projects dashboard-heading-icons)) args))
("List Directories:"
(apply #'dashboard-octicon (cdr (assoc 'ls-directories dashboard-heading-icons)) args))
("List Files:"
(apply #'dashboard-octicon (cdr (assoc 'ls-files dashboard-heading-icons)) args))
(_
(if (null icon) " " icon))))
(insert " ")))

(insert (propertize heading 'face 'dashboard-heading))

Expand Down