Problem using svg-lib / svg-tag-mode with daemon and emacsclient
storvik opened this issue · 24 comments
I'm struggling to make svg-tag-mode
to work with Emacs daemon and while debugging the issue it seems like the error comes from this library. I'm not that proficient in elisp but bear with me. My configuration while debugging looks like this (basically just straight.el and loading svg-tag-mode):
(setq package-enable-at-startup nil)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
(use-package svg-tag-mode
:config
(setq svg-tag-tags
'((":TODO:" . ((lambda (tag) (svg-tag-make "TODO")))))))
When turning on svg-tag-mode
the *Messages*
buffer reports the following error
Error during redisplay: (jit-lock-function 1) signaled (wrong-type-argument arrayp nil
After investigating it seemed like the error comes from the font-lock-flush
function (https://github.com/rougier/svg-tag-mode/blob/fee61c6a0b0570bd24fd335efef17c7385297aa0/svg-tag-mode.el#L290). And in turn it is the svg-lib-tag
that triggers it. I can verify that by running (svg-lib-tag "TEST")
, which returns:
let*: Wrong type argument: arrayp, nil
Digging further into the problem I noticed that svg-lib-style-default
were getting invalid background and foreground color. Background were set to unspecified-bg
and foreground to unspecified-fg
. I fixed it by running (setq svg-lib-style-default (svg-lib-style-compute-default))
after starting emacsclient to set sensible default value to svg-lib-style-default
.
The value of svg-lib-style-default
when starting emacsclient:
(:background "unspecified-bg" :foreground "unspecified-fg" :padding 1 :margin 0 :stroke 2 :radius 3 :alignment 0.5 :width 20 :height 0.9 :scale 0.75 :crop-left nil :crop-right nil :collection "material" :font-family "default" :font-size 0 :font-weight normal)
After updating it to svg-lib-style-compute-default
:
(:background "#2E3440" :foreground "#ECEFF4" :padding 1 :margin 0 :stroke 2 :radius 3 :alignment 0.5 :width 20 :height 0.9 :scale 0.75 :crop-left nil :crop-right nil :collection "material" :font-family "Iosevka" :font-size 8 :font-weight regular)
So my best guess is that svg-lib-style-default
is set before emacs frame is created and therefore gets an invalid value.
Maybe this is related to issues rougier/svg-tag-mode#21 and rougier/svg-tag-mode#22.
Thank you for your contributions to the Emacs community, much appreciated!
Waouuh, thanks for the report and thanks for the amazing debug (and sorry for the delay in my answer). I think you analysis is right and there plenty of bug report for this specific case. One potential solution could be to take advantage of the after-make-frame-functions
hook to initialize the default. Or else, to set a real default value based on default
face.
I'm trying to initialize an icon with after-make-frame-functions
but unfortunately the timing doesn't appear to work for me. I am not sure how to get SVGs ready to go after the init process without some function to render them at least once after the frame is made and fully ready for usage. I cannot find a suitable built-in hook.
Do you know if your emacs has svg support?
Sorry for the late reply. This is how I got around it
(defun first-graphical-frame-hook-function ()
(remove-hook 'focus-in-hook #'first-graphical-frame-hook-function)
(provide 'my-gui))
(add-hook 'focus-in-hook #'first-graphical-frame-hook-function)
(with-eval-after-load 'my-gui
(setq svg-lib-style-default (svg-lib-style-compute-default)))
Remember trying to use after-make-frame-functions
without any luck. I'm actually using with-eval-after-load 'my-gui
to get around similar issues in several other packages.
Not sure this can / should be solved within the package itself, but that's up to you @rougier. Feel free to close this issue.
Thanks again @rougier for your work.
Thansk for the update. But it is really wierd. How do you start your emacs daemon withut any frame (such I can debug on my side) ?
I'm starting Emacs as a systemd service, that's why no frame is created.
Maybe your solution is worth a mention in the README. Could you make a PR?