emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/olivetti f213afd 017/134: Added safe-width fun


From: Stefan Monnier
Subject: [elpa] externals/olivetti f213afd 017/134: Added safe-width fun
Date: Thu, 25 Apr 2019 09:57:19 -0400 (EDT)

branch: externals/olivetti
commit f213afdca78f63772b2909f61c4a9f162514d789
Author: Paul Rankin <address@hidden>
Commit: Paul Rankin <address@hidden>

    Added safe-width fun
---
 olivetti.el | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/olivetti.el b/olivetti.el
index b7b9967..508816a 100644
--- a/olivetti.el
+++ b/olivetti.el
@@ -121,6 +121,29 @@ mode line. Finally redraw the frame."
          (setq-local mode-line-format nil)))
   (redraw-frame (selected-frame)))
 
+(defun olivetti-safe-width (n)
+  "Parse N to a safe value for `olivetti-body-width'."
+  (let ((window-width (- (window-total-width)
+                         (% (window-total-width) 2)))
+        (min-width (+ olivetti-minimum-body-width
+                      (% olivetti-minimum-body-width 2))))
+    (cond ((integerp n)
+           (let ((width (min n window-width)))
+             (max width min-width)))
+          ((floatp n)
+           (let ((min-width
+                  (string-to-number (format "%0.2f"
+                                            (/ (float min-width)
+                                               window-width))))
+                 (width
+                  (string-to-number (format "%0.2f"
+                                            (min n 1.0)))))
+             (max width min-width)))
+          ((message "`olivetti-body-width' must be an integer or a float")
+           (setq olivetti-body-width
+                 (car (get 'olivetti-body-width 'standard-value)))))))
+
+
 (defun olivetti-set-environment ()
   "Set text body width to `olivetti-body-width' with relative margins."
   (let* ((n olivetti-body-width)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]