From: Alex Schroeder Date: Tue, 21 Jul 2020 07:22:56 +0000 (+0200) Subject: Fill headers X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=a2966e515f0fb0c9b803ead48a00bab8fa42be4f;p=elpher.git Fill headers Filling headers is tricky because fill-column is measured in characters but the font-size for headers is much larger than for regular text. This change tries to accomodate this by taking the face for the heading, getting it's font – a string like "-BE5N-Iosevka-normal-normal-normal-*-29-*-*-*-d-0-iso10646-1" – turns it into a spec and gets the size from there: 29. We can't use something like (face-attribute face :height) directly because it might return a font size in 1/10 point (if an interger) or as a scaling factor (if a float). Thus, in order to avoid tracking down the face inheritance tree, we're looking at the font name (a string), in either XLFD, Fontconfig, or GTK+ format. --- diff --git a/elpher.el b/elpher.el index b2bc1c5..b57f2b8 100644 --- a/elpher.el +++ b/elpher.el @@ -1368,17 +1368,20 @@ treatment that a separate function is warranted." The gemini map file line describing the header is given by HEADER-LINE." (when (string-match "^\\(#+\\)[ \t]*" header-line) - (let ((level (length (match-string 1 header-line))) - (header (substring header-line (match-end 0)))) + (let* ((level (length (match-string 1 header-line))) + (header (substring header-line (match-end 0))) + (face (pcase level + (1 'elpher-gemini-heading1) + (2 'elpher-gemini-heading2) + (3 'elpher-gemini-heading3) + (_ 'default))) + (fill-column (/ (* fill-column + (font-get (font-spec :name (face-font 'default)) :size)) + (font-get (font-spec :name (face-font face)) :size)))) (unless (display-graphic-p) (insert (make-string level ?#) " ")) - (insert (propertize header 'face - (pcase level - (1 'elpher-gemini-heading1) - (2 'elpher-gemini-heading2) - (3 'elpher-gemini-heading3) - (_ 'default))) - "\n")))) + (insert (propertize header 'face face)) + (newline)))) (defun elpher-gemini-insert-text (text-line) "Insert a plain non-preformatted TEXT-LINE into a text/gemini document.