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

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

[nongnu] elpa/golden-ratio 0287ac76fd 76/95: Simplify `golden-ratio-mode


From: ELPA Syncer
Subject: [nongnu] elpa/golden-ratio 0287ac76fd 76/95: Simplify `golden-ratio-mode'
Date: Thu, 7 Sep 2023 22:02:15 -0400 (EDT)

branch: elpa/golden-ratio
commit 0287ac76fdf87b50af1c9b3504a503847f97b745
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>

    Simplify `golden-ratio-mode'
    
    * golden-ratio.el (golden-ratio-in-progress): New defvar.
    (golden-ratio): Use `golden-ratio-in-progress' instead of turning off
    the mode.
    (select-window): New defadvice; remove all other stuff.
    (golden-ratio-mode): Remove all hooks, the only entry point is
    `select-window'.
    
    This change will greatly simplify the life of package writers that have
    to work around `golden-ratio-mode'.
    
    Re abo-abo/hydra#64.
---
 golden-ratio.el | 79 ++++++++++++++++++---------------------------------------
 1 file changed, 24 insertions(+), 55 deletions(-)

diff --git a/golden-ratio.el b/golden-ratio.el
index d32d73de92..f75184b185 100644
--- a/golden-ratio.el
+++ b/golden-ratio.el
@@ -126,70 +126,39 @@ will not cause the window to be resized to the golden 
ratio."
       (member (symbol-name major-mode)
               golden-ratio-exclude-modes)))
 
+(defvar golden-ratio-in-progress nil
+  "Avoid recursive adjustment.")
+
 ;;;###autoload
 (defun golden-ratio ()
   "Resizes current window to the golden-ratio's size specs."
   (interactive)
-  (unless (or (not golden-ratio-mode)
-              (window-minibuffer-p)
-              (one-window-p)
-              (golden-ratio-exclude-major-mode-p)
-              (member (buffer-name)
-                      golden-ratio-exclude-buffer-names)
-              (and golden-ratio-inhibit-functions
-                   (loop for fun in golden-ratio-inhibit-functions
-                         thereis (funcall fun))))
-    (let ((dims (golden-ratio--dimensions))
-          (golden-ratio-mode nil))
-      ;; Always disable `golden-ratio-mode' to avoid
-      ;; infinite loop in `balance-windows'.
-      (balance-windows)
-      (golden-ratio--resize-window dims)
-      (when golden-ratio-recenter
-        (scroll-right) (recenter)))))
-
-;; Should return nil
-(defadvice other-window
-    (after golden-ratio-resize-window)
-  (golden-ratio) nil)
-
-;; Should return the buffer
-(defadvice pop-to-buffer
-    (around golden-ratio-resize-window)
-  (prog1 ad-do-it (golden-ratio)))
-
-(defun golden-ratio--post-command-hook ()
-  (when (or (memq this-command golden-ratio-extra-commands)
-            (and (consp this-command) ; A lambda form.
-                 (loop for com in golden-ratio-extra-commands
-                       thereis (or (memq com this-command)
-                                   (memq (car-safe com) this-command)))))
-    ;; This is needed in emacs-25 to avoid this error from `recenter':
-    ;; `recenter'ing a window that does not display current-buffer.
-    ;; This doesn't happen in emacs-24.4 and previous versions.
-    (run-with-idle-timer 0.01 nil (lambda () (golden-ratio)))))
-
-(defun golden-ratio--mouse-leave-buffer-hook ()
-  (run-at-time 0.1 nil (lambda ()
-                        (golden-ratio))))
+  (when (and golden-ratio-mode
+             (not golden-ratio-in-progress))
+    (let ((golden-ratio-in-progress t))
+      (unless (or (window-minibuffer-p)
+                  (one-window-p)
+                  (member (symbol-name major-mode)
+                          golden-ratio-exclude-modes)
+                  (member (buffer-name)
+                          golden-ratio-exclude-buffer-names)
+                  (and golden-ratio-inhibit-functions
+                       (loop for fun in golden-ratio-inhibit-functions
+                          thereis (funcall fun))))
+        (balance-windows)
+        (golden-ratio--resize-window (golden-ratio--dimensions))
+        (when golden-ratio-recenter
+          (scroll-right) (recenter))))))
+
+(defadvice select-window (after golden-ratio-select-window activate)
+  (when golden-ratio-mode
+    (golden-ratio)))
 
 ;;;###autoload
 (define-minor-mode golden-ratio-mode
     "Enable automatic window resizing with golden ratio."
   :lighter " Golden"
-  :global t
-  (if golden-ratio-mode
-      (progn
-        (add-hook 'window-configuration-change-hook 'golden-ratio)
-        (add-hook 'post-command-hook 'golden-ratio--post-command-hook)
-        (add-hook 'mouse-leave-buffer-hook 
'golden-ratio--mouse-leave-buffer-hook)
-        (ad-activate 'other-window)
-        (ad-activate 'pop-to-buffer))
-      (remove-hook 'window-configuration-change-hook 'golden-ratio)
-      (remove-hook 'post-command-hook 'golden-ratio--post-command-hook)
-      (remove-hook 'mouse-leave-buffer-hook 
'golden-ratio--mouse-leave-buffer-hook)
-      (ad-deactivate 'other-window)
-      (ad-deactivate 'pop-to-buffer)))
+  :global t)
 
 
 (provide 'golden-ratio)



reply via email to

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