Skip to content
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

Make svg-lib optional #13

Closed
aclonegeek opened this issue Apr 22, 2022 · 24 comments
Closed

Make svg-lib optional #13

aclonegeek opened this issue Apr 22, 2022 · 24 comments

Comments

@aclonegeek
Copy link

Hi!

Would it be possible to make svg-lib optional? Could it be removed from Package-Requires without blowing everything up? I use only the text versions of the icons and I don't want to pull in the svg-lib dependency when installing (I also don't build emacs with SVG support).

BTW, the copyright year should probably be bumped.

@jdtsmith
Copy link
Owner

It should already be the case that it works without svg-lib. That is, if you don't have svg-lib installed and use text-only icons, it should work just fine. But most users will want icons so I'll leave the package-require. To avoid svg-lib, you can either install the old fashioned way by git cloning, package-install and M-x package-remove svg-lib, or fork + remove the Package-Requires and use straight to install right from your fork.

BTW, the copyright year should probably be bumped.

Thanks.

@aclonegeek
Copy link
Author

Indeed, it works perfectly as is. I was simply hoping to get rid of the svg-lib dependency (preferably without having to work around anything). I was planning to switch to straight at some point, so I guess now is a good time as any.

Is svg-lib just used for the icons? company-mode ships with dark and light SVG icons (from vscode) and uses the built in SVG functionality. Would there be any interest in doing something similar?

@jdtsmith
Copy link
Owner

Most users will want the icons (it's in the name!). Company mode uses icons from the Microsoft VSCode icon set, whereas kind-icon gives you access to hundreds of thousands, and the ability to tweak their style (see `kind-icon-default-style'), and colors which match the candidate type. While I appreciate the desire to keep your footprint small, svg-lib is in Elpa, and is quite a small package at <600LOC.

If I decided to ship a default set of icons, I'd basically need to reimplement (or copy) about 200LOC from svg-lib anyway. Doesn't sound worth the savings.

@grolongo
Copy link

grolongo commented Jan 4, 2023

Hello, instead of popping a new issue thread for my question, would it be possible for kind-icon to offer VSCode icon set as an alternative to the default?

@jdtsmith
Copy link
Owner

jdtsmith commented Jan 4, 2023

Kind-icon uses svg-lib, which actually supports a larger set of icon repos than just material. I'm considering a small update to allow kind-icon to use any collection svg-lib supports. But I don't think it (yet) supports vscode-icons in any of them.

If you open an issue at svg-lib it's possible this could be added. Post back here and we can revisit then if so.

@grolongo
Copy link

grolongo commented Jan 5, 2023

Understood. I made a request (ref: rougier/svg-lib#27) but I'm not sure it would be accepted as not all of the vscode icons are monochrome (it stipulated that it has to be for them to be included in svg-lib).

@grolongo
Copy link

Post back here and we can revisit then if so.

VScode icons set has been added to svg-lib: rougier/svg-lib@19db737

@jdtsmith
Copy link
Owner

Interesting. It looks like we could simply allow kind-icon-mapping to specify additional keywords like :collection (="vscode" for you). I've pushed a change which allows this. Can you have a look and see if it works for you?

@grolongo
Copy link

grolongo commented Mar 1, 2023

I tested your latest commit and it's working without any issue so far.
This is how I configured kind-icon-mapping:

(setq kind-icon-mapping
      '((method        "m"  :icon "symbol-method"      :collection "vscode" :face font-lock-function-name-face)
        (function      "f"  :icon "symbol-method"      :collection "vscode" :face font-lock-function-name-face)
        (constructor   "cn" :icon "symbol-method"      :collection "vscode" :face font-lock-function-name-face)
        (variable      "va" :icon "symbol-variable"    :collection "vscode" :face font-lock-variable-name-face)
        (field         "fd" :icon "symbol-field"       :collection "vscode" :face font-lock-variable-name-face)
        (typeparameter "tp" :icon "symbol-parameter"   :collection "vscode")
        (constant      "co" :icon "symbol-constant"    :collection "vscode")
        (class         "c"  :icon "symbol-class"       :collection "vscode" :face font-lock-type-face)
        (interface     "if" :icon "symbol-interface"   :collection "vscode" :face font-lock-type-face)
        (struct        "%"  :icon "symbol-structure"   :collection "vscode")
        (event         "ev" :icon "symbol-event"       :collection "vscode" :face font-lock-warning-face)
        (operator      "op" :icon "symbol-operator"    :collection "vscode")
        (module        "{"  :icon "symbol-namespace"   :collection "vscode")
        (property      "pr" :icon "symbol-property"    :collection "vscode")
        (value         "v"  :icon "symbol-enum"        :collection "vscode" :face font-lock-builtin-face)
        (enum          "e"  :icon "symbol-enum"        :collection "vscode" :face font-lock-builtin-face)
        (enummember    "em" :icon "symbol-enum-member" :collection "vscode" :face font-lock-builtin-face)
        (reference     "rf" :icon "references"         :collection "vscode")
        (keyword       "kw" :icon "symbol-keyword"     :collection "vscode")
        (file          "f"  :icon "symbol-file"        :collection "vscode")
        (folder        "d"  :icon "folder"             :collection "vscode")
        (color         "#"  :icon "symbol-color"       :collection "vscode")
        (unit          "u"  :icon "symbol-ruler"       :collection "vscode")
        (snippet       "S"  :icon "symbol-snippet"     :collection "vscode")
        (text          "tx" :icon "symbol-key"         :collection "vscode")
        (array         "a"  :icon "symbol-array"       :collection "vscode")
        (boolean       "b"  :icon "symbol-boolean"     :collection "vscode")
        (numeric       "nu" :icon "symbol-numeric"     :collection "vscode")
        (param         "pa" :icon "gear"               :collection "vscode")
        (string        "s"  :icon "symbol-string"      :collection "vscode")
        (command       "cm" :icon "chevron-right"      :collection "vscode")
        (magic         "ma" :icon "lightbulb-autofix"  :collection "vscode")
        (macro         "mc" :icon "lambda"             :face font-lock-keyword-face)
        (t             "."  :icon "question"           :collection "vscode")))

I could find an equivalent icon for all the default items, except for macro with the lambda icon, so this one is still using Material.

I only added a :face to items that are colorized in VSCode icons, following this documentation (there is no fundamental reasoning behind this and all could be colorized for that matter, just personal preference):
https://code.visualstudio.com/docs/editor/intellisense#_types-of-completions

So thank you for implementing the possibility to choose different sets!

By the way, I think it would cool to have a defcustom to choose which set we want to apply, since vscode is pretty much 100% supported except for the macro item. Something like (setq kind-icon-collection 'vscode) which would use the settings above, and using 'material as default.

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 1, 2023

Grrat. BTW, you could also just add :collection "vscode" to kind-icon-default-style, then mention "material" for the one icon with no analog. I'll consider a 'vscode switch. Do you mind posting a screenshot?

@grolongo
Copy link

grolongo commented Mar 1, 2023

I made two screenshots, let me know if you need more.

I noticed two issues on the way, the module and reference icons are not being displayed for some reasons. I checked the cache folder and they are present, and I can open the svgs in Emacs where they get displayed normally.

I tweaked the :height and :scale thinking they might be too big to be displayed compared to the others but they still don't want to show up. Do you have any idea?

vscode-kindicon
vscode-kindicon2

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 2, 2023

These missing icons have colors hard-coded into them. It's one of the reasons I didn't use VSCODE icons to begin with: some are "just strokes" like material icons, but some have colors baked in. I'm not sure why svg-lib does not display the colors of these icons (which will NOT respect different themes, light vs. dark, etc.), but it's not a kind-icon issue:

(insert-image (svg-lib-icon "references" nil :collection "vscode" :foreground "red" :height 3 :width 6))

Maybe mention the issue over at svg-lib? But I think I'd probably suggest "don't do that" is the right response to trying to use icons with hard-coded colors in kind-icon.

@grolongo
Copy link

grolongo commented Mar 3, 2023

Actually I think it should be even better to report it directly to the VSCode icons repository.

But anyway, there are only two icons which have this problem:

  • the module one has braces { } for its icon, but good thing is, the fallback text use a single { too, so no big difference :)
  • the reference one is not really that popular (imo) so it's not a big deal if only the fallback text gets shown for the few times someone is going to encounter it in the completion list I think

So basically you could just remove the reference line or leave it like this, and you would have almost all VSCode icons supported ootb.

I think it would be better to hard code the list into your package. If someone is interested in kind-icon because he wants to use vscode icons or any other library, and know it's possible by simply tweaking :collection, I don't think he expects that he's going to have to look up for each icons for each items and add 36 lines of kind-icon-mapping in his config like I did.

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 3, 2023

Would you be willing to work up a suitable set of almost-vscode settings, and put it on the wiki page? For module, you could consider this material code-braces icon. I didn't find one like reference. I switched to a library-like thing as a mnemonic; I also switched property to be a wrench like vscode.

I would strongly suggest leaving the connection between font-lock faces and equivalencies however, this will nicely change with theme and some people do day/night themes.

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 3, 2023

If that pans out, I could consider a "packs" directory and solicit icon packs from people who want to contribute. vscodish could be one.

And for reference, I personally don't really like the vscode icons, as many of them are various similary-shaped boxes that don't seem to have much meaning. But I guess if you are used to them from company or VSCODE itself, it would make sense to have a "transition". I mostly figure people who don't really care will quickly adapt to the defaults, and people who are picky will have >10k icons to chose from!

@grolongo
Copy link

grolongo commented Mar 3, 2023

Would you be willing to work up a suitable set of almost-vscode settings, and put it on the wiki page?

Do you mean just make a wiki with the list (adjusted) from here #13 (comment)?

For module, you could consider this material code-braces icon.

Looks good.

I would strongly suggest leaving the connection between font-lock faces and equivalencies however, this will nicely change with theme and some people do day/night themes.

Roger that.

If that pans to, I could consider a "packs" directory and solicit icon packs from people who want to contribute. vscodish could be one.

Understood. To be clear it was just a proposal so someone who wants to switch collections can do so by just modifying one small defcustom setting to either material/octicons/vscode/... Then the guy who wants to tweak even further and change a few icons from the default ones can do so through kind-icon-default-style. That's just how I saw things, but it's totally up to you.

And for reference, I personally don't really like the vscode icons, as many of them are various similary-shaped boxes that don't seem to have much meaning.

I don't really have a strong attraction to them neither to be honest, they are just trivial icons after all, it's just that I'm used to them from company and VS Code and therefore if I can keep consistent settings across programs it's easier to switch.

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 3, 2023

Exactly what you said, then I can point to the Wiki from the README. BTW, please note I had to double up on two categories: enum-member and type-parameter, because eglot and lsp-mode disagree on how the kind is spelled (a change to uniformly target snake-case is working its way through).

so someone who wants to switch collections can do so by just modifying one small defcustom setting to either material/octicons/vscode/..

It's just becomes a problem of "which packs to bless". That's why a contributed "packs" directory makes sense to me. I.e. packs/vscode-like, packs/minimal, etc. Maybe that's overkill though. If I get some feedback on your Wiki settings, I'll consider hard-coding them.

BTW, since yours are mostly from vscode, you could consider

(plist-put kind-icon-default-style :collection "vscode")

Then just mention :collection "material" or octicon or whatever in kind-icon-mapping for the few that need a difference.

BTW, I noticed vscode icons from GH are quite slow to download/update and sometimes get stuck loading; did you find the same?

@grolongo
Copy link

grolongo commented Mar 3, 2023

BTW, I noticed vscode icons from GH are quite slow to download/update and sometimes get stuck loading; did you find the same?

I deleted the .cache/ folder several times and I didn't have any slowness, they come in as fast as materials ones on my side.

So I edited the list following your hints:

  • list is ordered alphabetically
  • added enum-member and type-parameter
  • added a :face attribute for all icons
  • removed all :collection so we use (plist-put kind-icon-default-style :collection "vscode") once instead
  • the reference item now uses the "library" icon

I encountered an issue, for item macro and module, if I add :collection "material" and use "vscode" by default it doesn't work (the icons don't get fetched). On the other way around if I use "material" as default (so without the need to use plist-put) and add :collection "vscode" like in #13 (comment), it works.

So I cheated a bit:
I removed the :icon attribute for both of them, and used the unicode lambda λ and brackets {} as fallbacks. Let me know if you are fine with that or need some changes before I add it to the wiki.

Here is the list:

(plist-put kind-icon-default-style :collection "vscode")

(setq kind-icon-mapping
      '((array          "a"   :icon "symbol-array"       :face font-lock-type-face)
        (boolean        "b"   :icon "symbol-boolean"     :face font-lock-builtin-face)
        (color          "#"   :icon "symbol-color"       :face success)
        (command        "cm"  :icon "chevron-right"      :face default)
        (constant       "co"  :icon "symbol-constant"    :face font-lock-constant-face)
        (class          "c"   :icon "symbol-class"       :face font-lock-type-face)
        (constructor    "cn"  :icon "symbol-method"      :face font-lock-function-name-face)
        (enum           "e"   :icon "symbol-enum"        :face font-lock-builtin-face)
        (enummember     "em"  :icon "symbol-enum-member" :face font-lock-builtin-face)
        (enum-member    "em"  :icon "symbol-enum-member" :face font-lock-builtin-face)
        (event          "ev"  :icon "symbol-event"       :face font-lock-warning-face)
        (field          "fd"  :icon "symbol-field"       :face font-lock-variable-name-face)
        (file           "f"   :icon "symbol-file"        :face font-lock-string-face)
        (folder         "d"   :icon "folder"             :face font-lock-doc-face)
        (function       "f"   :icon "symbol-method"      :face font-lock-function-name-face)
        (interface      "if"  :icon "symbol-interface"   :face font-lock-type-face)
        (keyword        "kw"  :icon "symbol-keyword"     :face font-lock-keyword-face)
        (macro          "λ"                              :face font-lock-keyword-face)
        (magic          "ma"  :icon "lightbulb-autofix"  :face font-lock-builtin-face)
        (method         "m"   :icon "symbol-method"      :face font-lock-function-name-face)
        (module         "{}"                             :face font-lock-preprocessor-face)
        (numeric        "nu"  :icon "symbol-numeric"     :face font-lock-builtin-face)
        (operator       "op"  :icon "symbol-operator"    :face font-lock-comment-delimiter-face)
        (param          "pa"  :icon "gear"               :face default)
        (property       "pr"  :icon "symbol-property"    :face font-lock-variable-name-face)
        (reference      "rf"  :icon "library"            :face font-lock-variable-name-face)
        (snippet        "S"   :icon "symbol-snippet"     :face font-lock-string-face)
        (string         "s"   :icon "symbol-string"      :face font-lock-string-face)
        (struct         "%"   :icon "symbol-structure"   :face font-lock-variable-name-face)
        (text           "tx"  :icon "symbol-key"         :face font-lock-doc-face)
        (typeparameter  "tp"  :icon "symbol-parameter"   :face font-lock-type-face)
        (type-parameter "tp"  :icon "symbol-parameter"   :face font-lock-type-face)
        (unit           "u"   :icon "symbol-ruler"       :face font-lock-constant-face)
        (value          "v"   :icon "symbol-enum"        :face font-lock-builtin-face)
        (variable       "va"  :icon "symbol-variable"    :face font-lock-variable-name-face)
        (t              "."   :icon "question"           :face font-lock-warning-face)))

Screenshots:

dark
light

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 6, 2023

On the other way around if I use "material" as default (so without the need to use plist-put) and add :collection "vscode" like in #13 (comment), it works.

Oh right, sorry. Settings in style uniformly override anything in the mapping element's plist.

This looks great, thanks for working on it. I worry about others falling into this same trap, though. Perhaps for that reason we should leave kind-icon-default-style alone and just be explicit about the :collection. Then you can feel free to substitute a material or octicon icon for your problem cases. The unicode actually looks great, but its availability may be font-dependent. But now I wonder if a pure unicode "pack" would be a good addition. Lots of interesting shapes. Though some may take up more than one standard char width so some care would be required.

Please go ahead and include your vscode-alike in the wiki with your screenshots and I'll link from README.

@grolongo
Copy link

grolongo commented Mar 9, 2023

Perhaps for that reason we should leave kind-icon-default-style alone and just be explicit about the :collection. Then you can feel free to substitute a material or octicon icon for your problem cases.

Agree, I'll add :collection "vscode" on each lines then and leave kind-icon-default-style as default.

The unicode actually looks great, but its availability may be font-dependent. But now I wonder if a pure unicode "pack" would be a good addition. Lots of interesting shapes.

Luckily the lambda and brackets look good, but I don't think you'll find relevant unicode symbols for all the items.

@grolongo
Copy link

grolongo commented Mar 9, 2023

Please go ahead and include your vscode-alike in the wiki with your screenshots and I'll link from README.

I think you need to enable it first on your repository as I don't see the option to add/edit one on the main page.

@jdtsmith
Copy link
Owner

jdtsmith commented Mar 9, 2023

Ok it should be enabled. Thanks.

@grolongo
Copy link

grolongo commented Mar 9, 2023

I added the entry in the wiki, feel free to modify it as you please if needed.
Thank you for your help!

@Eason0210
Copy link

Eason0210 commented May 12, 2023

@grolongo

Thanks for your great work on it.
It works pretty good on my macBook with Emacs 30.0.50

I hope this config can be integrated to master branch, So the users don't need to add 36 lines to my init.el

image

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

No branches or pull requests

4 participants