[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/olivetti 8556abb 078/134: Rearranging code for clarity
From: |
Stefan Monnier |
Subject: |
[elpa] externals/olivetti 8556abb 078/134: Rearranging code for clarity |
Date: |
Thu, 25 Apr 2019 09:57:32 -0400 (EDT) |
branch: externals/olivetti
commit 8556abbfdb185c7915868a88e56ca71ea4857d6d
Author: Paul Rankin <address@hidden>
Commit: Paul Rankin <address@hidden>
Rearranging code for clarity
---
olivetti.el | 127 ++++++++++++++++++++++++++++++++----------------------------
1 file changed, 68 insertions(+), 59 deletions(-)
diff --git a/olivetti.el b/olivetti.el
index 1a00d39..dc70db6 100644
--- a/olivetti.el
+++ b/olivetti.el
@@ -147,7 +147,60 @@ exiting. The reverse is not true."
:group 'olivetti)
-;;; Functions
+;;; Set Environment
+
+(defun olivetti-set-environment ()
+ "Set text body width to `olivetti-body-width' with relative margins.
+
+Cycle through all windows displaying current buffer and, first,
+find the `olivetti-safe-width' to which to set
+`olivetti-body-width', then find the appropriate margin size
+relative to each window. Finally set the window margins, taking
+care that the maximum size is 0."
+ (dolist (window (get-buffer-window-list nil nil t))
+ (let* ((n (olivetti-safe-width (if (integerp olivetti-body-width)
+ (olivetti-scale-width
olivetti-body-width)
+ olivetti-body-width)
+ window))
+ (width (cond ((integerp n) n)
+ ((floatp n) (* (window-total-width window)
+ n))))
+ (margin (max (round (/ (- (window-total-width window)
+ width)
+ 2))
+ 0)))
+ (set-window-parameter window 'split-window 'olivetti-split-window)
+ (set-window-margins window margin margin))))
+
+(defun olivetti-reset-environment ()
+ "Remove Olivetti's parameters and margins.
+
+Cycle through all windows displaying current buffer and reset
+window parameter `split-window' to nil. Then reset the window
+margins to nil."
+ (dolist (window (get-buffer-window-list nil nil t))
+ (set-window-parameter window 'split-window nil)
+ (set-window-margins window nil nil)))
+
+(defun olivetti-split-window (&optional window size side pixelwise)
+ "Safely split the window by first resetting the environment.
+
+First call `olivetti-reset-environment' then try
+`split-window'.
+
+If `olivetti-mode' is non-nil, call `olivetti-set-environment'."
+ (olivetti-reset-environment)
+ (split-window window size side pixelwise)
+ (if olivetti-mode (olivetti-set-environment)))
+
+(defun olivetti-split-window-sensibly (&optional window)
+ "Like `olivetti-split-window' but calls `split-window-sensibly'."
+ (olivetti-reset-environment)
+ (split-window-sensibly window)
+ (if olivetti-mode (olivetti-set-environment)))
+
+
+;;; Set Mode-Line
(defun olivetti-set-mode-line (&optional arg)
"Set the mode line formating appropriately.
@@ -169,6 +222,17 @@ mode line."
(olivetti-hide-mode-line
(setq-local mode-line-format nil))))
+(defun olivetti-toggle-hide-mode-line ()
+ "Toggle the visibility of the mode-line.
+
+Toggles the value of `olivetti-hide-mode-line' and runs
+`olivetti-set-mode-line'."
+ (interactive)
+ (olivetti-set-mode-line 'toggle))
+
+
+;;; Calculate Width
+
(defun olivetti-scale-width (n)
"Scale N in accordance with the face height.
@@ -202,6 +266,9 @@ face, scale N by that factor, otherwise scale by 1."
(setq olivetti-body-width
(eval (car (get 'olivetti-body-width 'standard-value))))))))
+
+;;; Width Interaction
+
(defun olivetti-set-width (n)
"Set text body width to N with relative margins.
@@ -215,64 +282,6 @@ fraction of the window width."
(olivetti-set-environment)
(message "Text body width set to %s" olivetti-body-width))
-(defun olivetti-set-environment ()
- "Set text body width to `olivetti-body-width' with relative margins.
-
-Cycle through all windows displaying current buffer and, first,
-find the `olivetti-safe-width' to which to set
-`olivetti-body-width', then find the appropriate margin size
-relative to each window. Finally set the window margins, taking
-care that the maximum size is 0."
- (dolist (window (get-buffer-window-list nil nil t))
- (let* ((n (olivetti-safe-width (if (integerp olivetti-body-width)
- (olivetti-scale-width
olivetti-body-width)
- olivetti-body-width)
- window))
- (width (cond ((integerp n) n)
- ((floatp n) (* (window-total-width window)
- n))))
- (margin (max (round (/ (- (window-total-width window)
- width)
- 2))
- 0)))
- (set-window-parameter window 'split-window 'olivetti-split-window)
- (set-window-margins window margin margin))))
-
-(defun olivetti-reset-environment ()
- "Remove Olivetti's parameters and margins.
-
-Cycle through all windows displaying current buffer and reset
-window parameter `split-window' to nil. Then reset the window
-margins to nil."
- (dolist (window (get-buffer-window-list nil nil t))
- (set-window-parameter window 'split-window nil)
- (set-window-margins window nil nil)))
-
-(defun olivetti-split-window (&optional window size side pixelwise)
- "Safely split the window by first resetting the environment.
-
-First call `olivetti-reset-environment' then try
-`split-window'.
-
-If `olivetti-mode' is non-nil, call `olivetti-set-environment'."
- (olivetti-reset-environment)
- (split-window window size side pixelwise)
- (if olivetti-mode (olivetti-set-environment)))
-
-(defun olivetti-split-window-sensibly (&optional window)
- "Like `olivetti-split-window' but calls `split-window-sensibly'."
- (olivetti-reset-environment)
- (split-window-sensibly window)
- (if olivetti-mode (olivetti-set-environment)))
-
-(defun olivetti-toggle-hide-mode-line ()
- "Toggle the visibility of the mode-line.
-
-Toggles the value of `olivetti-hide-mode-line' and runs
-`olivetti-set-mode-line'."
- (interactive)
- (olivetti-set-mode-line 'toggle))
-
(defun olivetti-expand (&optional arg)
"Incrementally increase the value of `olivetti-body-width'.
- [elpa] externals/olivetti 48874ef 045/134: Hiding mode-line seems to work without frame redrawing, (continued)
- [elpa] externals/olivetti 48874ef 045/134: Hiding mode-line seems to work without frame redrawing, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 6818914 047/134: Neatening docs, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 78ef7ae 046/134: Reset margins in all buffer windows, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 6933bf9 049/134: More neatening up, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 35654fe 054/134: Added note about temporary-overlay-map, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti d4fdf91 059/134: Fix for Emacs lexical binding standard-value bug, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti cdc9fc3 058/134: Merge pull request #11 from rnkn/lexical-binding, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti e095ee34 060/134: Function quoting, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti b4094d3 066/134: Added badges, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 3d057a5 073/134: Removed useless (let ...), Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 8556abb 078/134: Rearranging code for clarity,
Stefan Monnier <=
- [elpa] externals/olivetti ff058b9 084/134: new file: screenshots/01.png, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 9bd4108 091/134: Compatibility fixes for Emacs 26, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti cba0d25 076/134: user-error for bad olivetti-body-width, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 696c195 080/134: Fixed window splitting, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti e9feab0 087/134: Remove H1 from README/Commentary, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 21f8356 086/134: Updated README/Commentary, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti df2477e 093/134: Fix README typo, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 2b202b4 098/134: Fix spelling error in description, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti 1629f89 102/134: Always find window on all frames, Stefan Monnier, 2019/04/25
- [elpa] externals/olivetti c87a7ec 100/134: Merge pull request #17 from sten0/master, Stefan Monnier, 2019/04/25