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

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

[elpa] externals/olivetti 8332154: Change post-command-hook back to wind


From: Paul Rankin
Subject: [elpa] externals/olivetti 8332154: Change post-command-hook back to window-configuration-change-hook
Date: Tue, 14 May 2019 03:08:15 -0400 (EDT)

branch: externals/olivetti
commit 8332154c1b28ed86d802843a019b5cfcf43b702e
Author: Paul W. Rankin <address@hidden>
Commit: Paul W. Rankin <address@hidden>

    Change post-command-hook back to window-configuration-change-hook
    
    This seems to cover the most bases on Emacs 26
    
    Also:
    
    - rename functions from internal style (they're not strictly internal)
    - update function documentation
    - make sure olivetti-set-margins passes a window when called recurisvely
---
 olivetti.el | 63 ++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 33 insertions(+), 30 deletions(-)

diff --git a/olivetti.el b/olivetti.el
index 94a5bdb..a64607e 100644
--- a/olivetti.el
+++ b/olivetti.el
@@ -142,32 +142,34 @@ exiting. The reverse is not true."
 
 ;;; Set Environment
 
-(defun olivetti--set-margins ()
-  "Set text body width to `olivetti-body-width' with relative margins.
+(defun olivetti-set-all-margins ()
+  "Balance window margins in all windows displaying current buffer.
 
-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."
+Cycle through all windows in all frames displaying the current
+buffer, and call `olivetti-set-margins'."
   (dolist (window (get-buffer-window-list nil nil t))
-    (olivetti--set-window-margins window)))
+    (olivetti-set-margins window)))
+
+(defun olivetti-set-margins (&optional frame-or-window)
+  "Balance window margins displaying current buffer.
+
+If FRAME-OR-WINDOW is a frame, cycle through windows displaying
+current buffer in that frame, otherwise only work on the selected
+window.
 
-(defun olivetti--set-window-margins (window-or-frame)
-  "Set text body width to `olivetti-body-width' with relative margins.
 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."
-  (if (framep window-or-frame)
-      ;; Emacs<27 calling style.
-      (mapc #'olivetti--set-window-margins
-            (get-buffer-window-list nil nil frame))
-    (olivetti-reset-window window-or-frame)
-    (let ((width (olivetti-safe-width olivetti-body-width window-or-frame))
-          (frame (window-frame window-or-frame))
-          (window-width (window-total-width window-or-frame))
-          (fringes (window-fringes window-or-frame))
+  (if (framep frame-or-window)
+      (dolist (window (get-buffer-window-list nil nil frame-or-window))
+        (olivetti-set-margins window))
+    ;; FRAME-OR-WINDOW passed below *must* be a window
+    (olivetti-reset-window frame-or-window)
+    (let ((width (olivetti-safe-width olivetti-body-width frame-or-window))
+          (frame (window-frame frame-or-window))
+          (window-width (window-total-width frame-or-window))
+          (fringes (window-fringes frame-or-window))
           left-fringe right-fringe margin-total left-margin right-margin)
       (cond ((integerp width)
              (setq width (olivetti-scale-width width)))
@@ -178,8 +180,8 @@ care that the maximum size is 0."
       (setq margin-total (max (/ (- window-width width) 2) 0)
             left-margin (max (round (- margin-total left-fringe)) 0)
             right-margin (max (round (- margin-total right-fringe)) 0))
-      (set-window-parameter window-or-frame 'split-window 
'olivetti-split-window)
-      (set-window-margins window-or-frame left-margin right-margin))))
+      (set-window-parameter frame-or-window 'split-window 
'olivetti-split-window)
+      (set-window-margins frame-or-window left-margin right-margin))))
 
 (defun olivetti-reset-all-windows ()
   "Remove Olivetti's parameters and margins from all windows.
@@ -257,7 +259,7 @@ fraction of the window width."
              (read-number "Set text body width (integer or float): "
                           olivetti-body-width))))
   (setq olivetti-body-width n)
-  (olivetti--set-margins)
+  (olivetti-set-margins)
   (message "Text body width set to %s" olivetti-body-width))
 
 (defun olivetti-expand (&optional arg)
@@ -271,7 +273,7 @@ If prefixed with ARG, incrementally decrease."
                   ((floatp olivetti-body-width)
                    (+ olivetti-body-width (* 0.01 p))))))
     (setq olivetti-body-width (olivetti-safe-width n (selected-window))))
-  (olivetti--set-margins)
+  (olivetti-set-margins)
   (message "Text body width set to %s" olivetti-body-width)
   (set-transient-map
    (let ((map (make-sparse-keymap)))
@@ -311,19 +313,20 @@ body width set with `olivetti-body-width'."
   (if olivetti-mode
       (progn
         (add-hook 'window-size-change-functions
-                  #'olivetti--set-window-margins t t)
-        ;; FIXME: Do we really still need this post-command-hook in
-        ;; Emacs-27?
-        (add-hook 'post-command-hook 'olivetti--set-margins t t)
+                  #'olivetti-set-margins t t)
+        (add-hook 'window-configuration-change-hook
+                  'olivetti-set-all-margins t t)
         (add-hook 'change-major-mode-hook
                   #'olivetti-reset-all-windows nil t)
         (setq-local split-window-preferred-function
                     #'olivetti-split-window-sensibly)
         (setq olivetti--visual-line-mode visual-line-mode)
         (unless olivetti--visual-line-mode (visual-line-mode 1))
-        (olivetti--set-margins))
-    (remove-hook 'post-command-hook #'olivetti--set-margins t)
-    (remove-hook 'window-size-change-functions #'olivetti--set-window-margins 
t)
+        (olivetti-set-all-margins))
+    (remove-hook 'window-configuration-change-hook
+                 #'olivetti-set-all-margins t)
+    (remove-hook 'window-size-change-functions
+                 #'olivetti-set-margins t)
     (olivetti-reset-all-windows)
     (when (and olivetti-recall-visual-line-mode-entry-state
                (not olivetti--visual-line-mode))



reply via email to

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