Skip to content

Commit

Permalink
[RFC] Add support for functions as face sizes
Browse files Browse the repository at this point in the history
:height can be a function instead of an explicit number, which I rely on in my theme (eg. https://github.com/kunalb/poet/blob/master/poet-theme.el#L207). 

With this change the function is applied on the previous size ("A function value is called with one argument, the height of the underlying face, and returns the height of the new face" -- https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html). I'm not sure if "merged" is the best argument to pass here but I can't think of any alternatives.

Without this change htmlize on a buffer fails with an error around next not being a valid value type.
`htmlize-merge-two-faces: Wrong type argument: number-or-marker-p, (lambda (base) (truncate (* (face-attribute (quote fixed-pitch) :height nil (quote default)) 1.23)))`

Tested by running htmlize-buffer with poet enabled, output seems sane and it doesn't fail.

Bug report: kunalb/poet#15
  • Loading branch information
kunalb authored May 31, 2020
1 parent 86f22f2 commit 6b808b2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions htmlize.el
Original file line number Diff line number Diff line change
Expand Up @@ -1122,11 +1122,14 @@ If no rgb.txt file is found, return nil."

(defun htmlize-merge-size (merged next)
;; Calculate the size of the merge of MERGED and NEXT.
(cond ((null merged) next)
((integerp next) next)
((null next) merged)
((floatp merged) (* merged next))
((integerp merged) (round (* merged next)))))
(let ((next (if (functionp next)
(apply next '(merged)) next)))
(cond ((null merged) next)
((integerp next) next)
((null next) merged)
((floatp merged) (* merged next))
((integerp merged) (round (* merged next))))))


(defun htmlize-merge-two-faces (merged next)
(htmlize-copy-attr-if-set
Expand Down

0 comments on commit 6b808b2

Please sign in to comment.