Can't add `file-type` collection
Townk opened this issue · comments
Thiago Alves commented
I tried to add the file-type collection by installing svg-icon
using the following:
(use-package! svg-icon
:commands svg-icon
:config
(setq
svg-icon-collections
'(("bootstrap" . "https://icons.getbootstrap.com/icons/%s.svg")
("material" . "https://raw.githubusercontent.com/Templarian/MaterialDesign/master/svg/%s.svg")
("file" . "https://raw.githubusercontent.com/file-icons/icons/master/svg/%s.svg")
("octicons" . "https://raw.githubusercontent.com/primer/octicons/master/icons/%s-24.svg")
("boxicons" . "https://boxicons.com/static/img/svg/regular/bx-%s.svg"))))
If I try to access a file on the file
collection directly on the browser, all works like expected:
But if I try to use svg-icon
to insert the same icon with:
(insert (format "[%s]" (propertize "--" 'display (svg-icon "file" "Emacs"))))
I get the following error:
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
string-match("[ \f\11\n\15\13]+" nil 0)
split-string(nil)
svg-icon("file" "Emacs" "#ff0000" "#000000")
(propertize "--" 'display (svg-icon "file" "Emacs" "#ff0000" "#000000"))
(format "[%s]" (propertize "--" 'display (svg-icon "file" "Emacs" "#ff0000" "#000000")))
(insert (format "[%s]" (propertize "--" 'display (svg-icon "file" "Emacs" "#ff0000" "#000000"))))
eval((insert (format "[%s]" (propertize "--" 'display (svg-icon "file" "Emacs" "#ff0000" "#000000")))) nil)
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
call-interactively(eval-last-sexp record nil)
command-execute(eval-last-sexp record)
execute-extended-command(nil "eval-last-sexp" nil)
funcall-interactively(execute-extended-command nil "eval-last-sexp" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
I'm using Emacs 27.1 with Doom-emacs, on a Mac with macOS Catalina.
Nicolas P. Rougier commented
I think the problem is related to the absence of a viewbox in the svg file. I need to create a default view box when this is the case:
;; Read original viewbox
(viewbox (cdr (assq 'viewBox (xml-node-attributes (car root)))))
(viewbox (mapcar 'string-to-number (split-string viewbox)))
(view-x (nth 0 viewbox))
(view-y (nth 1 viewbox))
(view-width (nth 2 viewbox))
(view-height (nth 3 viewbox))
If viewbox is nil, we should get the width and height of the SVG and set view-width and view-height with them while view-x and view-y should be 0. Could you try and make a PR?