Skip to content

Commit

Permalink
[Core] Reduce inlining in icon creation.
Browse files Browse the repository at this point in the history
This should fix bytecode overflow errors during compilation.
  • Loading branch information
Alexander-Miller committed Sep 25, 2023
1 parent 967916c commit bf1f4c2
Showing 1 changed file with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions src/elisp/treemacs-icons.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,41 +186,37 @@ Necessary since root icons are not rectangular."
(h (round (* ,height 1.1818))))
(setq ,width w ,height h)))

(define-inline treemacs--create-image (file-path)
(defun treemacs--create-image (file-path)
"Load image from FILE-PATH and size it based on `treemacs--icon-size'."
(inline-letevals (file-path)
(inline-quote
(let ((height treemacs--icon-size)
(width treemacs--icon-size))
(when (and (integerp treemacs--icon-size)
(s-starts-with? "root-" ,file-path))
(treemacs--root-icon-size-adjust width height))
(if (and (integerp treemacs--icon-size) (image-type-available-p 'imagemagick))
(create-image ,file-path 'imagemagick nil :ascent 'center :width width :height height)
(create-image
,file-path
(intern (treemacs--file-extension (treemacs--filename ,file-path)))
nil
:ascent 'center :width width :height height))))))

(define-inline treemacs--create-icon-strings (file fallback)
(let ((height treemacs--icon-size)
(width treemacs--icon-size))
(when (and (integerp treemacs--icon-size)
(s-starts-with? "root-" file-path))
(treemacs--root-icon-size-adjust width height))
(if (and (integerp treemacs--icon-size) (image-type-available-p 'imagemagick))
(create-image file-path 'imagemagick nil :ascent 'center :width width :height height)
(create-image
file-path
(intern (treemacs--file-extension (treemacs--filename file-path)))
nil
:ascent 'center :width width :height height))))

(defun treemacs--create-icon-strings (file fallback)
"Create propertized icon strings for a given FILE image and TUI FALLBACK."
(inline-letevals (file fallback)
(inline-quote
(let ((tui-icon ,fallback)
(gui-icon
(if (treemacs--is-image-creation-impossible?)
,fallback
(let* ((img-selected (treemacs--create-image ,file))
(img-unselected (copy-sequence img-selected)))
(nconc img-selected `(:background ,treemacs--selected-icon-background))
(nconc img-unselected `(:background ,treemacs--not-selected-icon-background))
(concat (propertize " "
'display img-unselected
'img-selected img-selected
'img-unselected img-unselected)
" ")))))
(cons gui-icon tui-icon)))))
(let ((tui-icon fallback)
(gui-icon
(if (treemacs--is-image-creation-impossible?)
fallback
(let* ((img-selected (treemacs--create-image file))
(img-unselected (copy-sequence img-selected)))
(nconc img-selected `(:background treemacs--selected-icon-background))
(nconc img-unselected `(:background treemacs--not-selected-icon-background))
(concat (propertize " "
'display img-unselected
'img-selected img-selected
'img-unselected img-unselected)
" ")))))
(cons gui-icon tui-icon)))

(defmacro treemacs--splice-icon (icon)
"Splice the given ICON data depending on whether it is a value or an sexp."
Expand Down

0 comments on commit bf1f4c2

Please sign in to comment.