Alexander-Miller / treemacs

GNU General Public License v3.0
2.12k stars 155 forks source link

treemacs-create-icon - use regexp for :extensions #1051

Closed sebastiaanspeck closed 1 year ago

sebastiaanspeck commented 1 year ago
(treemacs-create-icon :icon (format "  %s%s" (nerd-icons-sucicon "nf-seti-docker" :face 'nerd-icons-cyan) treemacs-nerd-icons-tab)
              :extensions ("^Dockerfile.*$")
              :fallback 'same-as-icon)

Would be great if the above would work. I do have some Dockerfiles that are called:

I could add (add-to-list 'nerd-icons-regexp-icon-alist '("^Dockerfile.*$" nerd-icons-sucicon "nf-seti-docker" :face nerd-icons-cyan)) to the regexp for nerd-icons, but the regexp-icon-alist can't be used for treemacs-create-icon.

Besides this issue, is the function treemacs-get-icon-value case-sensitive? (treemacs-get-icon-value "dockerfile" nil "nerd-icons") --> results in a icon (treemacs-get-icon-value "Dockerfile" nil "nerd-icons") --> nil

It does display the icon for dockerfile when having a Dockerfile in treemacs, so thats no issue.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity (this bot only works as a reminder, it will not close issues).

Alexander-Miller commented 1 year ago

For performance reasons treemacs uses hash tables for its icon matching, so regexes are are no-go. You can at most change what treemacs considers a file's extension, that part is handled via regex. Look at treemacs-file-extension-regex. The default choices are about matching things after the first or last period, but maybe you can change it to something that suits you.

Besides this issue, is the function treemacs-get-icon-value case-sensitive?

Yes. Internally treemacs will downcase everything, so you should do the same.

sebastiaanspeck commented 1 year ago

Okay, but given the file Dockerfile-backend and Dockerfile-frontend, how can I add the Dockerfile-icon to those?

Alexander-Miller commented 1 year ago

Get the latest version of treemacs and you'll be able to create an override to check for the dockerfile prefix like this:

(advice-add
 #'treemacs--file-extension
 :around
 (defun treemacs-override (original-fn filename)
   (if (string-prefix-p "dockerfile" (downcase filename))
       "dockerfile"
     (funcall original-fn filename))))

Then make sure to create an icon for a lowercase "dockerfile" extension and you should be good to go.