rougier / nano-modeline

GNU Emacs / N Λ N O Modeline
GNU General Public License v3.0
169 stars 29 forks source link

Error with modeline when using svg-lib #76

Open bornbanane opened 2 months ago

bornbanane commented 2 months ago

Hello,

Emacs : 29.3 svg-lib : 0.3 nano-modeline : 1.1.0 nano-theme : 0.3.4

I use "nano-theme" and "nano-modeline" and instead of seeing icons in modeline I see text [bootstrap:XXX], I see this for exmple when I am in "capture" in orgmode (org roam dailies capture today).

Looking at the sources I see that svg-lib is required, so I add it via a : (use-package svg-lib) in my conf and when I restart my emacs my modeline disappears and I get this kind of error :

Error during redisplay: (eval (let* ((nano-modeline-base-face (nano-modeline--base-face 'header)) (left (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buffer-status "󰕮") " " (nano-modeline-buffer-name "Dashboard")))) (right (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buttons (("[Journal]" org-roam-dailies-capture-today . "Journal") ("[TAB]" tab-new . "New Tab") ("[DIRED]" ziok-dired . "Dired") ("[Toolbar]" tool-bar-mode . "Toolbar") ("[Menu]" menu-bar-mode . "Menu")) t) " " (nano-modeline-window-dedicated)))) (width (window-width)) (outside fringes-outside-margins) (left-fringe (if outside -1.0 0.0)) (left-margin (if outside 0.0 1.0)) (right-fringe (if outside -1.0 0.0)) (right-margin (if outside -1.0 0.0)) (left-max-size (- width (length right) 2)) (left (if (> (length left) left-max-size) (concat (truncate-string-to-width left left-max-size) (propertize "…" 'face `(:inherit ,nano-modeline-base-face))) left))) (concat (propertize " " 'display `(space :align-to (+ left-margin (,left-fringe . left-fringe) (,left-margin . left-margin)))) (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-left-fringe-width))) left (propertize " " 'face `(:inherit ,nano-modeline-base-face) 'display `(space :align-to (- right-margin (,right-fringe . right-fringe) (,right-margin . right-margin) (nano-modeline-right-fringe-width) ,(length right)))) right (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-right-fringe-width)))))) signaled (wrong-type-argument listp nano-modeline-button-active-face) [25 times]

Here my conf for nano-modeline :

(use-package svg-lib)

(set-face-attribute 'default nil
                    :family "Roboto Mono"
                    :weight 'light
                    :height 140)

(set-face-attribute 'bold nil
                    :family "Roboto Mono"
                    :weight 'regular)

(set-face-attribute 'italic nil
                    :family "Victor Mono"
                    :weight 'semilight
                    :slant 'italic)

(set-fontset-font t 'unicode
                    (font-spec :name "Inconsolata Light"
                               :size 16) nil)

(set-fontset-font t '(#xe000 . #xffdd)
                     (font-spec :name "RobotoMono Nerd Font"
                                :size 16) nil)

(use-package nano-theme
  :config
  (load-theme 'nano t)
)

;;(use-package nano-agenda)

(use-package nano-modeline)
(nano-modeline-text-mode t)
(add-hook 'prog-mode-hook            #'nano-modeline-prog-mode)
(add-hook 'text-mode-hook            #'nano-modeline-text-mode)
(add-hook 'org-mode-hook             #'nano-modeline-org-mode)
(add-hook 'pdf-view-mode-hook        #'nano-modeline-pdf-mode)
;;(add-hook 'mu4e-headers-mode-hook    #'nano-modeline-mu4e-headers-mode)
;;(add-hook 'mu4e-view-mode-hook       #'nano-modeline-mu4e-message-mode)
;;(add-hook 'elfeed-show-mode-hook     #'nano-modeline-elfeed-entry-mode)
;;(add-hook 'elfeed-search-mode-hook   #'nano-modeline-elfeed-search-mode)
(add-hook 'term-mode-hook            #'nano-modeline-term-mode)
;;(add-hook 'xwidget-webkit-mode-hook  #'nano-modeline-xwidget-mode)
(add-hook 'messages-buffer-mode-hook #'nano-modeline-message-mode)
;;(add-hook 'org-capture-mode-hook     #'nano-modeline-org-capture-mode)
(add-hook 'org-agenda-mode-hook      #'nano-modeline-org-agenda-mode)

;; pour tester 
(defun ziok-nano-modeline-org-capture-filename ()
    (buffer-file-name (org-base-buffer (current-buffer))))

(defun ziok-nano-modeline-org-capture-mode ()
  "Nano line for org capture mode"  

  (let* ((filename (ziok-nano-modeline-org-capture-filename))
         (save (format "Save entry to %s" filename))
         (buttons `(("SAVE" . (org-capture-finalize . ,save))
                    ("CANCEL" . (org-capture-kill . "Delete entry"))
                    ("[bootstrap:arrows-expand]" . (delete-other-windows . "expand"))
                    )))
    (funcall nano-modeline-position
             `((nano-modeline-buffer-status "ORG") " "
               (nano-modeline-buffer-name "Capture") " "
               (nano-modeline-org-capture-description))
             `((nano-modeline-buttons ,buttons t) " "
               (nano-modeline-window-dedicated)))))

(add-hook 'org-capture-mode-hook     #'ziok-nano-modeline-org-capture-mode)            

;; pour le bouton DIRED
(defun ziok-dired () 
  (interactive)
  "Dired button function"
  (dired "/home/francois/orgmode/orgroam")
)
;; ajout de bouton sur le dashboard
(defun ziok-nano-modeline-dashboard-mode ()
  "Nano line for Dashboard"

  (let ((buttons '( 
    ("[Journal]" . (org-roam-dailies-capture-today . "Journal")) 
    ("[TAB]" . (tab-new . "New Tab")) 
    ("[DIRED]" . (ziok-dired . "Dired")) 
    ("[Toolbar]" . (tool-bar-mode . "Toolbar")) 
    ("[Menu]" . (menu-bar-mode . "Menu")) 
    ))) 
    (funcall nano-modeline-position
             '((nano-modeline-buffer-status "󰕮") " "
               (nano-modeline-buffer-name "Dashboard"))
             `((nano-modeline-buttons ,buttons t) " "
               (nano-modeline-window-dedicated)))))

(add-hook 'dashboard-mode-hook #'ziok-nano-modeline-dashboard-mode)
(add-hook 'post-command-hook #'force-mode-line-update)

On the other hand, "modelines" that don't use button like the default org one work very well. And without svg-lib everything is OK but button are juste text [bootstrap:XXX]

PS : C'est un plaisir d'utiliser vos créations 👍

rougier commented 2 months ago

Merci !

For the bootstrap:XXX, the problem seems that svg-lib is unable to create the button for some reason. Can you try to toggle debug on error and report the error (if any) ?

bornbanane commented 2 months ago

I have activated toggle debug on error (M-x toggle-debug-on-error) but it does not stop and report anything else than the previous error of the inial post.

I have done a capture with orgroam this time to have the error with your default button :

Error during redisplay: (eval (let* ((nano-modeline-base-face (nano-modeline--base-face 'header)) (left (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buffer-status "ORG") " " (nano-modeline-buffer-name "Capture") " " (nano-modeline-org-capture-description)))) (right (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buttons (("SAVE" org-capture-finalize . "Save entry to /home/xxxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t) " " (nano-modeline-window-dedicated)))) (width (window-width)) (outside fringes-outside-margins) (left-fringe (if outside -1.0 0.0)) (left-margin (if outside 0.0 1.0)) (right-fringe (if outside -1.0 0.0)) (right-margin (if outside -1.0 0.0)) (left-max-size (- width (length right) 2)) (left (if (> (length left) left-max-size) (concat (truncate-string-to-width left left-max-size) (propertize "…" 'face `(:inherit ,nano-modeline-base-face))) left))) (concat (propertize " " 'display `(space :align-to (+ left-margin (,left-fringe . left-fringe) (,left-margin . left-margin)))) (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-left-fringe-width))) left (propertize " " 'face `(:inherit ,nano-modeline-base-face) 'display `(space :align-to (- right-margin (,right-fringe . right-fringe) (,right-margin . right-margin) (nano-modeline-right-fringe-width) ,(length right)))) right (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-right-fringe-width)))))) signaled (wrong-type-argument listp nano-modeline-button-active-face) [207 times] 

I'm not good enough in elisp to understand fully what all that means.

Well I found that : https://www.gnu.org/software/emacs/manual/html_node/elisp/Debugging-Redisplay.html

So here the content of the buffer *Redisplay_trace* after evaluating (setq backtrace-on-redisplay-error t)

Error: wrong-type-argument (listp nano-modeline-button-inactive-face)
  mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode 0x107021b139ae86a6>))
  debug-early-backtrace()
  debug-early(error (wrong-type-argument listp nano-modeline-button-inactive-face))
  svg-lib-tag("SAVE" nano-modeline-button-inactive-face)
  nano-modeline--make-svg-button("SAVE" nano-modeline-button-inactive-face active)
  nano-modeline--make-button((:label "SAVE" :state active :help "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org" :hook org-capture-finalize) t)
  #<subr F616e6f6e796d6f75732d6c616d626461_anonymous_lambda_5>((:label "SAVE" :state active :help "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org" :hook org-capture-finalize))
  nano-modeline-buttons((("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t nil)
  apply(nano-modeline-buttons ((("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t))
  (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))
  (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element))))((nano-modeline-buttons (("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t))
  mapconcat((lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) ((nano-modeline-buttons (("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t) " " (nano-modeline-window-dedicated)))
  (let* ((nano-modeline-base-face (nano-modeline--base-face 'header)) (left (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buffer-status "ORG") " " (nano-modeline-buffer-name "Capture") " " (nano-modeline-org-capture-description)))) (right (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buttons (("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t) " " (nano-modeline-window-dedicated)))) (width (window-width)) (outside fringes-outside-margins) (left-fringe (if outside -1.0 0.0)) (left-margin (if outside 0.0 1.0)) (right-fringe (if outside -1.0 0.0)) (right-margin (if outside -1.0 0.0)) (left-max-size (- width (length right) 2)) (left (if (> (length left) left-max-size) (concat (truncate-string-to-width left left-max-size) (propertize "…" 'face `(:inherit ,nano-modeline-base-face))) left))) (concat (propertize " " 'display `(space :align-to (+ left-margin (,left-fringe . left-fringe) (,left-margin . left-margin)))) (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-left-fringe-width))) left (propertize " " 'face `(:inherit ,nano-modeline-base-face) 'display `(space :align-to (- right-margin (,right-fringe . right-fringe) (,right-margin . right-margin) (nano-modeline-right-fringe-width) ,(length right)))) right (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-right-fringe-width)))))
  eval((let* ((nano-modeline-base-face (nano-modeline--base-face 'header)) (left (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buffer-status "ORG") " " (nano-modeline-buffer-name "Capture") " " (nano-modeline-org-capture-description)))) (right (mapconcat (lambda (element) (if (stringp element) (propertize element 'face nano-modeline-base-face) (apply (car element) (cdr element)))) '((nano-modeline-buttons (("SAVE" org-capture-finalize . "Save entry to /home/xxxxx/orgmode/orgroam/daily/2024-05-27.org") ("CANCEL" org-capture-kill . "Delete entry") ("[bootstrap:arrows-expand]" delete-other-windows . "expand")) t) " " (nano-modeline-window-dedicated)))) (width (window-width)) (outside fringes-outside-margins) (left-fringe (if outside -1.0 0.0)) (left-margin (if outside 0.0 1.0)) (right-fringe (if outside -1.0 0.0)) (right-margin (if outside -1.0 0.0)) (left-max-size (- width (length right) 2)) (left (if (> (length left) left-max-size) (concat (truncate-string-to-width left left-max-size) (propertize "…" 'face `(:inherit ,nano-modeline-base-face))) left))) (concat (propertize " " 'display `(space :align-to (+ left-margin (,left-fringe . left-fringe) (,left-margin . left-margin)))) (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-left-fringe-width))) left (propertize " " 'face `(:inherit ,nano-modeline-base-face) 'display `(space :align-to (- right-margin (,right-fringe . right-fringe) (,right-margin . right-margin) (nano-modeline-right-fringe-width) ,(length right)))) right (propertize " " 'face 'fringe 'display '(space :width (nano-modeline-right-fringe-width))))))
  redisplay_internal\ \(C\ function\)()

I hope that can help.

rougier commented 1 month ago

Can you try in a scratch buffer:

(require 'svg-lib)
(insert (propertize "HOME" 'display (svg-lib-tag "[material:home] HOME")))
bornbanane commented 2 weeks ago

Hi, sorry for late answer.

emacs-svglibs