branch: externals/olivetti
commit d40a054420eb0a656732f6b92f52c3ad50860da6
Author: Niels uit de Bos <[email protected]>
Commit: Niels uit de Bos <[email protected]>
Fixed olivetti-scale-width for integer heights
The function `olivetti-scale-width` incorrectly assumes that the height is
always a fraction. However, it can in very normal circumstances be an
integer
such as 120 (see section 39.12.1 from the manual
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Face-Attributes.html)).
In such a case, the old function scales the width by a number that is far
too
large, which results in margins of width 0.
To see how this fails, set the height to something like 120 by using, for
example, buffer-face-mode.
I fixed this by scaling by height/100 if the height is an integer. If it is
a
float or something else entirely, the new function behaves as the old.
---
olivetti.el | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/olivetti.el b/olivetti.el
index 0998e80..16c177f 100644
--- a/olivetti.el
+++ b/olivetti.el
@@ -275,11 +275,15 @@ instead `olivetti-set-mode-line'."
For compatibility with `text-scale-mode', if
`face-remapping-alist' includes a :height property on the default
-face, scale N by that factor, otherwise scale by 1."
- (* n (or (plist-get (cadr (assq 'default
- face-remapping-alist))
- :height)
- 1)))
+face, scale N by that factor if it is a fraction, by (height/100)
+if it is an integer, and otherwise scale by 1."
+ (let
+ ((height (plist-get (cadr (assq 'default face-remapping-alist))
:height)))
+ (cond
+ ((integerp height) (* n (/ height 100.0)))
+ ((floatp height) (* n height))
+ (t n))))
+
(defun olivetti-safe-width (width window)
"Parse WIDTH to a safe value for `olivetti-body-width' for WINDOW.