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

Skip to content

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
merged 9 commits into from
May 2, 2023
Merged

add nerd-icons support to dashboard #451

merged 9 commits into from
May 2, 2023

Conversation

rainstormstudio
Copy link
Contributor

demo
(Ubuntu 20.04, Gnome Desktop, Alacritty terminal, FiraCode Nerd Fonts)
image

Major Changes
I added dashboard-icon-type which specifies which icon package to use (either 'all-the-icons or 'nerd-icons). Based on dashboard-icon-type, other icon related custom variables such as dashboard-heading-icons will have corresponding default values.

Configuration for using Nerd Icons

(setq dashboard-display-icons-p t) ;; to use icons under terminal
(setq dashboard-icon-type 'nerd-icons)

Things I am not sure about
I'm not sure if my implementation for setting default values for some custom variables based on dashboard-icon-type is good. Let's say I set dashboard-icon-type to 'nerd-icons. My current implementation for setting the default value of dashboard-heading-icons is to use a pcase statement. Does setting dashboard-icon-type trigger the evaluation of dashboard-heading-icons's pcase? If I want to set a new value for dashboard-heading-icons in a init file, does it require some kind of ordering like I must setting dashboard-icon-type before setting dashboard-heading-icons?

Other comments
I have been using this dashboard for a few weeks now, and no issues so far. However, it might still have bugs that I did not think of. I'll be tracking nerd icons related issues here in emacs-dashboard, and I will try my best to solve them :)

Copy link
Member

@jcs090218 jcs090218 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits. Everything else LGTM!

@jcs090218
Copy link
Member

Can you resolve the compile error? See https://github.com/emacs-dashboard/emacs-dashboard/actions/runs/4864724799/jobs/8675087587?pr=451#step:5:116.

In end of data:
dashboard-widgets.el:138:43: Warning: the function `nerd-icons-octicon' is not
    known to be defined.

I'm not sure if my implementation for setting default values for some custom variables based on dashboard-icon-type is good. Let's say I set dashboard-icon-type to 'nerd-icons. My current implementation for setting the default value of dashboard-heading-icons is to use a pcase statement. Does setting dashboard-icon-type trigger the evaluation of dashboard-heading-icons's pcase?

Yeah, you are right. Users will have to set up the dashboard config early. If you want to change the icon type, they would have to restart Emacs or set them all manually. I don't know if there is a better solution than this, but I don't think this is a huge issue since people normally start the dashboard at the beginning and hope it works. There isn't a lot of runtime tweaking throughout the lifecycle.

If I want to set a new value for dashboard-heading-icons in a init file, does it require some kind of ordering like I must setting dashboard-icon-type before setting dashboard-heading-icons?

No, the defcustom operation won't overwrite variables that are already set.

@rainstormstudio
Copy link
Contributor Author

Thank you so much for the detailed explanation! I just fixed the compile error and replaced those cond with pcase. Hopefully this is better now :D

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))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And maybe all these places, use pcase for consistency. :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah I should do a search for all of the occurrences. Sorry about that!

BTW is there any advantage of using pcase over cond? or it doesn't matter and we just want consistency here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of taste. I prefer pcase since the code is cleaner. The downside of this, it will add up startup time due to loading the pcase.el module.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a matter of taste. I prefer pcase since the code is cleaner. The downside of this, it will add up startup time due to loading the pcase.el module.

@jcs090218
Copy link
Member

Thank you so much for the detailed explanation! I just fixed the compile error and replaced those cond with pcase.

No, I should say thank you to you! Thanks for creating nerd-icons! ❤️ It's amazing! I've added all of the nerd-icons related packages to my config! See here.

@rainstormstudio
Copy link
Contributor Author

I just replaced other cond with pcase. Please take a look.

Yeah I felt jealous when I saw Vim users had Nerd icons and we didn't. That's why I made nerd-icons lol

Copy link
Member

@jcs090218 jcs090218 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some clean up! ;)

@@ -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))
Copy link
Member

@jcs090218 jcs090218 May 2, 2023

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:

(and dashboard-set-heading-icons
    (or (require 'nerd-icons nil t)
        (require 'all-the-icons nil t)))

Make sure to place dashboard-set-heading-icons to the front to avoid compile error.

: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))
Copy link
Member

@jcs090218 jcs090218 May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use pcase here too?

(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))))

Copy link
Member

@jcs090218 jcs090218 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some work needs to be done on our side. Anyways, the PR is good to be merged! :D

Thank you for your contribution! ❤️ 🚀

@jcs090218 jcs090218 merged commit 7991d92 into emacs-dashboard:master May 2, 2023
@rainstormstudio
Copy link
Contributor Author

Sorry I was a bit busy just now.

The clean up looks good, and I think we also need to modify the README regarding using nerd-icons.

Thank you for your guidance!

@jcs090218
Copy link
Member

jcs090218 commented May 2, 2023

Sorry I was a bit busy just now.

No worries! The code quality is there, therefore it's good to merge! :D

The clean up looks good, and I think we also need to modify the README regarding using nerd-icons.

Can you open another PR for this. Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants