Alexander-Miller / treemacs

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

Invalid image type 'svg' #1017

Closed Randy1Burrell closed 1 year ago

Randy1Burrell commented 1 year ago

What's the problem? Recently after Emacs elpa upgraded the packages I am getting the error "Invalid image type 'svg'" from Treemacs.

Version Emacs 28.2

OS MacOS

What do you expect to happen? I expect Treemacs to work.

Debug Log

Debugger entered--Lisp error: (error "Invalid image type ‘svg’")
  signal(error ("Invalid image type ‘svg’"))
  error("Invalid image type `%s'" svg)
  image-type("/Users/randyburrell/.emacs.d/elpa-28.2/treemacs-20..." svg nil)
  create-image("/Users/randyburrell/.emacs.d/elpa-28.2/treemacs-20..." svg nil :ascent center :width 22 :height 22)
  byte-code("\305\306\307\310\311$\305\306\307\310\311$\312\313\314\315\10\316\"\5\5%\317\320\2\"\210\211\31\321\322\323\"\324\11!\n>\2040\0\325\326\313\11D\"\210\11\327..." [treemacs-dir treemacs--current-theme cl-struct-treemacs-theme-tags treemacs--icon-size treemacs-file-extension-regex make-hash-table :size 300 :test equal record treemacs-theme "Default" treemacs-join-path "icons/default" add-to-list treemacs--themes mapcar #f(compiled-function (it) #<bytecode -0x1deb3897afdd3b8d>) (root-closed) type-of signal wrong-type-argument 2 "vsc/root-closed.png" image-type-available-p png "" s-starts-with\? "root-" round 0.909 1.1818 imagemagick create-image nil :ascent center :width :height intern string-match 0 copy-sequence (:background "darkseagreen2") (:background "White") propertize " " display img-selected ...] 19)
  #<subr require>(treemacs-icons)
  apply(#<subr require> treemacs-icons nil)
  (prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis (current-time) require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t)))))
  (let* ((already-loaded (memq feature features)) (require-start-time (and (not already-loaded) (current-time)))) (prog1 (apply orig feature args) (if (and (not already-loaded) (memq feature features)) (progn (let ((time (sanityinc/time-subtract-millis ... require-start-time))) (add-to-list 'sanityinc/require-times (list feature require-start-time time) t))))))
  sanityinc/require-times-wrapper(#<subr require> treemacs-icons)
  apply(sanityinc/require-times-wrapper #<subr require> treemacs-icons)
  #f(advice-wrapper :around #<subr require> sanityinc/require-times-wrapper)(treemacs-icons)
  apply(#f(advice-wrapper :around #<subr require> sanityinc/require-times-wrapper) treemacs-icons)
  require(treemacs-icons)
  eval-buffer(#<buffer  *load*> nil "/Users/randyburrell/.emacs.d/elpa-28.2/treemacs-20..." nil t)  ; Reading at buffer position 1294
  load-with-code-conversion("/Users/randyburrell/.emacs.d/elpa-28.2/treemacs-20..." "/Users/randyburrell/.emacs.d/elpa-28.2/treemacs-20..." nil t)
  autoload-do-load((autoload "treemacs" "Select the treemacs window if it is visible.\nBring..." t nil) treemacs-select-window)
  command-execute(treemacs-select-window)
chrishowejones commented 1 year ago

I get the same issue.

Alexander-Miller commented 1 year ago

I have recently added a few icons in the svg format because it has a few advantages over the pngs currently in use - svgs can be upscaled without pixelation which is very useful for people with large 4k displays, they also have no trouble with overlays changing their background color, which is something I need to fix manually with png files.

For all intents and purposes svg files are the future of treemacs icons, it just will take a long time to migrate the 300 or so icons that already exist. I just hope lack for svg support is not a common issue, or at least it's easy to rectify.

Do you also see the error when you try this?

(insert (propertize " " 'display '(image :type svg :file "treemacs install dir/icons/default/vsc/dir-git-open.svg")))

What does (image-type-available-p 'svg) return?

I get the same issue.

Are you also on a mac?

My google-fu says Emacs has supported svgs since 2007, there's 7 year old threads asking how to compile Emacs with svg support like this. Maybe you just need to install the right version?

chrishowejones commented 1 year ago

@Alexander-Miller I am on Ubuntu 22.10 and Emacs 29 Emacs 29.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.34, cairo version 1.16.0) built from Savannah source some months ago.

(insert (propertize " " 'display '(image :type svg :file "treemacs install dir/icons/default/vsc/dir-git-open.svg"))) returns nil

(image-type-available-p 'svg) also returns nil

Alexander-Miller commented 1 year ago

built from Savannah source some months ago.

I guess you missed the --with-rsvg or you don't have librsvg installed.

I evidently need to include guards against Emacs being unable to handle svg images, but that will just mean that you will not see any of the new svg icons, and eventually the old icons that will be replaced, though that will take a while.

Randy1Burrell commented 1 year ago

I'm using the native packages built for Mac. What do your think the solution is here?

Alexander-Miller commented 1 year ago

I'm using the native packages built for Mac. What do your think the solution is here?

You might be affected by this issue. That means you should:

Whatever plans I had to replace more icons with svgs will be shelved until Emacs 29 is out (it would not have been a priority anyway).

chrishowejones commented 1 year ago

@Alexander-Miller It turns out I needed to build Emacs with --with-rsvg and install librsvg2-dev. also worth noting I tried to build the latest master branch for Emacs (version 30.50) and had a load of issues (not related to treemacs) so I built off the 29.0.90 tag.

xautjzd commented 1 year ago

I got the same issue, add (add-to-list 'image-types 'svg) to emacs configuration(eg: init.el) to fix it. @Randy1Burrell @chrishowejones

Randy1Burrell commented 1 year ago

@xautjzd Thank you, this worked!! @ Alexander-Miller you don't need to roll back converting over to SVG since this solution works. @chrishowejones Thanks for the help, but since this work, I don't have to go through the trouble of compiling and moving away from the stable builds.

Alexander-Miller commented 1 year ago

I got the same issue, add (add-to-list 'image-types 'svg) to emacs configuration(eg: init.el) to fix it.

I would have thought if an image type isn't in that list then Emacs is unable to support, but ok, whatever works :man_shrugging:.

Anyway I've prevented the creation if svg images if Emacs thinks they are not supported. I'll keep that code until Emacs 29 has been released for a while and then consider removing it and adding more svg icons.

nacl commented 1 year ago

I inadvertently built an instance of emacs 29 (tag emacs-29.0.92) without SVG support, and I'm still seeing a similar error. The stack trace I get contains messages like:

Debugger entered--Lisp error: (error "Invalid image type ‘svg’")
  error("Invalid image type `%s'" svg)
  image-type(".../treemacs/icons/default/vsc/dir-src-closed.svg" svg nil)
  create-image(".../treemacs/icons/default/vsc/dir-src-closed.svg" svg nil :ascent center :width 22 :height 22)

I have an easy enough way to deal with this locally (just build linking against librsvg-2), but from what I observed, it looks like create-image is being called from:

https://github.com/Alexander-Miller/treemacs/blob/cb56fb908e612e008608a910a0606ec84d9f63ac/src/elisp/treemacs-icons.el#L189-L201

which is in turn called by:

https://github.com/Alexander-Miller/treemacs/blob/cb56fb908e612e008608a910a0606ec84d9f63ac/src/elisp/treemacs-icons.el#L203-L220

when a GUI is available and some sort of image creation is possible. This is called in the treemacs-create-icon macro, unconditionally best I can tell.

Perhaps some image support detection logic needs to be added earlier in the macro too? I can make a new issue for this if you like.

Randy1Burrell commented 1 year ago

@Alexander-Miller this is an issue again it seems you were right here https://github.com/Alexander-Miller/treemacs/issues/1017#issuecomment-1520718287

Emacs now throws an error about

Debugger entered--Lisp error: (void-variable image-types)
  (member 'svg image-types)
  (if (member 'svg image-types) image-types (setq image-types (cons 'svg image-types)))
  eval-buffer(#<buffer  *load*> nil "/Users/randyburrell/.emacs.d/init.el" nil t)  ; Reading at buffer position 1620
  load-with-code-conversion("/Users/randyburrell/.emacs.d/init.el" "/Users/randyburrell/.emacs.d/init.el" nil nil)
  load("/Users/randyburrell/.emacs.d/init.el" nil nil t)
  load-file("/Users/randyburrell/.emacs.d/init.el")
  (let ((debug-on-error t) (url-show-status nil) (user-emacs-directory default-directory) (user-init-file (expand-file-name "init.el")) (load-path (delq default-directory load-path))) (load-file user-init-file) (run-hooks 'after-init-hook))
  eval((let ((debug-on-error t) (url-show-status nil) (user-emacs-directory default-directory) (user-init-file (expand-file-name "init.el")) (load-path (delq default-directory load-path))) (load-file user-init-file) (run-hooks 'after-init-hook)) t)
  command-line-1(("--eval" "(let ((debug-on-error t)\n                         ..."))
  command-line()