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

Syntax to set Icons for Files and Folders #1059

Closed
Caliv0 opened this issue Sep 14, 2023 · 1 comment
Closed

Syntax to set Icons for Files and Folders #1059

Caliv0 opened this issue Sep 14, 2023 · 1 comment

Comments

@Caliv0
Copy link

Caliv0 commented Sep 14, 2023

I'm trying to set a custom icon for files like *.actions.ts
Is there some kind of wildcard, or a way to match against regex?

This is my latest attempt, but it doesn't match files like login.actions.ts or core.actions.ts.

      (treemacs-create-icon :file (concat doom-user-dir "icons/actions.svg") :extensions ("actions.ts"))

For context, the rest of my config. Everything besides reducers.ts, state.ts, selectors.ts and actions.ts works perfectly.

  (treemacs-modify-theme "Default"
    :config
    (progn
      ;; Folders
      (treemacs-create-icon :file (concat doom-user-dir "icons/folder.svg") :extensions (dir-closed "icons-open" "bin-open" "public-open" "private-open"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/folder-open.svg") :extensions (dir-open "icons-closed" "bin-closed" "private-closed" "private-closed"))

      ;; Concat to add space https://github.com/Alexander-Miller/treemacs/issues/735
      (treemacs-create-icon :icon (concat (all-the-icons-material "folder_special" :height 1.5 :v-adjust 0.05 :face 'treemacs-root-face) " ") :extensions (root-open))
      (treemacs-create-icon :icon (concat (all-the-icons-material "folder_special" :height 1.5 :v-adjust 0.05 :face 'treemacs-root-face) " ") :extensions (root-closed))

      ;; Files
      (treemacs-create-icon :icon (concat (all-the-icons-alltheicon "terminal" :v-adjust 0.05) " ") :extensions ("bash" "bashrc" "bash_profile" "fish" "zshrc" "zsh" "sh"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/settings.svg") :extensions ("json"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/csharp.svg") :extensions ("cs"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/css.svg") :extensions ("scss" "css" "less" "sass"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/html.svg") :extensions ("html"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/dotnet.svg") :extensions ("sln" "csproj"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/angular.svg") :extensions ("angular.json"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/store-open.svg") :extensions ("store-open" "state-open"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/store-closed.svg") :extensions ("store-closed" "state-closed"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/actions-open.svg") :extensions ("actions-open"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/actions-closed.svg") :extensions ("actions-closed"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/actions.svg") :extensions ("actions.ts"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/selectors-open.svg") :extensions ("selectors-open"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/selectors-closed.svg") :extensions ("selectors-closed"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/selectors.svg") :extensions ("selectors.ts"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/reducer-open.svg") :extensions ("reducer-open" "state-open"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/reducer-closed.svg") :extensions ("reducer-closed" "state-closed"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/reducer.svg") :extensions ("state.ts" "reducer.ts"))
      (treemacs-create-icon :file (concat doom-user-dir "icons/typescript.svg") :extensions ("ts"))

      (treemacs-create-icon :file (concat doom-user-dir "icons/file.svg") :extensions (unknown))
      (treemacs-create-icon :file (concat doom-user-dir "icons/file.svg") :extensions (fallback))
      )
    ;; Reduce Space https://github.com/Alexander-Miller/treemacs/issues/735
    (let ((icons (treemacs-theme->gui-icons theme)))
      (maphash
       (lambda (ext icon)
         (puthash ext (concat (substring icon 0 1)
                              (propertize " " 'display '(space . (:width 0.2))))
                  icons))
       icons))
    )

I'm new to lisp and Emacs in general, but I took me a while to figure out that foldername-open/close is something that would work.

@Alexander-Miller
Copy link
Owner

Matching icons is something that happens a lot, so treemacs keeps the algorithm as simple as possible. To get the icon for a file treemacs will first look at the entire filename. If it finds nothing it looks at the file's extension, which is defined as anything after the name's last period.

If you want to change that behavior you can look at treemacs-file-extension-regex.

The dir-open & -closed is a fairly new feature. I've added some documentation for it (in the admittedly very large readme).

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

No branches or pull requests

2 participants