[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/golden-ratio 0d7e18325d 33/95: Merge pull request #1 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/golden-ratio 0d7e18325d 33/95: Merge pull request #1 from thierryvolpiatto/exp |
Date: |
Thu, 7 Sep 2023 22:02:11 -0400 (EDT) |
branch: elpa/golden-ratio
commit 0d7e18325d0f2019adb81fad9132b47ce2870a06
Merge: 2d1553431c 550fb22580
Author: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Commit: Thierry Volpiatto <thierry.volpiatto@gmail.com>
Merge pull request #1 from thierryvolpiatto/exp
Fix crashes and make it working with helm
---
golden-ratio.el | 140 ++++++++++++++++++++++++++------------------------------
1 file changed, 64 insertions(+), 76 deletions(-)
diff --git a/golden-ratio.el b/golden-ratio.el
index 31334cd897..f75e630d51 100644
--- a/golden-ratio.el
+++ b/golden-ratio.el
@@ -17,16 +17,16 @@
;;; Code:
(eval-when-compile (require 'cl))
-(defconst -golden-ratio-value 1.618
+(defconst golden-ratio--value 1.618
"The golden ratio value itself.")
;; Major modes that are exempt from being resized. An example of this
;; for users of Org-mode might be:
;; ("calendar-mode")
(defcustom golden-ratio-exclude-modes nil
- "An array of strings naming major modes. Switching to a buffer
-whose major mode is a member of this list will not cause the
-window to be resized to the golden ratio."
+ "An array of strings naming major modes.
+Switching to a buffer whose major mode is a member of this list
+will not cause the window to be resized to the golden ratio."
:type '(repeat string)
:group 'golden-ratio)
@@ -34,93 +34,81 @@ window to be resized to the golden ratio."
;; for users of Org-mode might be (note the leading spaces):
;; (" *Org tags*" " *Org todo*")
(defcustom golden-ratio-exclude-buffer-names nil
- "An array of strings containing buffer names. Switching to a
-buffer whose name is a member of this list will not cause the
-window to be resized to the golden ratio."
+ "An array of strings containing buffer names.
+Switching to a buffer whose name is a member of this list
+will not cause the window to be resized to the golden ratio."
:type '(repeat string)
:group 'golden-ratio)
(defcustom golden-ratio-inhibit-functions nil
- "List of functions to call with no arguments. Switching to a
-buffer, if any of these functions returns non-nil will not cause
-the window to be resized to the golden ratio."
+ "List of functions to call with no arguments.
+Switching to a buffer, if any of these functions returns non-nil
+will not cause the window to be resized to the golden ratio."
:group 'golden-ratio
:type 'hook)
-(defun -golden-ratio-dimensions ()
- (let* ((main-rows (floor (/ (frame-height) -golden-ratio-value)))
- (main-columns (floor (/ (frame-width) -golden-ratio-value))))
- (list main-rows
- main-columns)))
-
-
-(defun -golden-ratio-resize-window (dimensions window)
- (let* ((edges (window-pixel-edges window))
- (nrow (floor
- (- (first dimensions)
- (window-height window))))
- (ncol (floor
- (- (second dimensions)
- (window-width window)))))
- (progn
- (if (not (window-full-height-p))
- (enlarge-window nrow nil))
- (if (not (window-full-width-p))
- (enlarge-window ncol t)))))
-
+(defun golden-ratio--dimensions ()
+ (list (floor (/ (frame-height) golden-ratio--value))
+ (floor (/ (frame-width) golden-ratio--value))))
+
+(defun golden-ratio--resize-window (dimensions &optional window)
+ (with-selected-window (or window (selected-window))
+ (let ((nrow (floor (- (first dimensions) (window-height-after-balance))))
+ (ncol (floor (- (second dimensions) (window-width-after-balance)))))
+ (when (window-resizable-p (selected-window) nrow)
+ (enlarge-window nrow nil))
+ (when (window-resizable-p (selected-window) ncol t)
+ (enlarge-window ncol t)))))
+
+(defun window-width-after-balance ()
+ (let* ((size-ls (loop for i in (window-list)
+ unless (window-full-width-p i)
+ collect (window-width i)))
+ (len (length size-ls))
+ (width (and size-ls (floor (/ (apply #'+ size-ls) len)))))
+ (if width (min (window-width) width) (window-width))))
+
+(defun window-height-after-balance ()
+ (let* ((size-ls (loop for i in (window-list)
+ unless (or (window-full-height-p i)
+ (not (window-full-width-p i)))
+ collect (window-height i)))
+ (len (length size-ls))
+ (height (and size-ls (floor (/ (apply #'+ size-ls) len)))))
+ (if height (min (window-height) height) (window-height))))
;;;###autoload
(defun golden-ratio ()
- "Resizes current window to the golden-ratio's size specs"
+ "Resizes current window to the golden-ratio's size specs."
(interactive)
- (if (and (not (window-minibuffer-p))
- (not (one-window-p))
- (not (member (symbol-name major-mode)
- golden-ratio-exclude-modes))
- (not (member (buffer-name)
- golden-ratio-exclude-buffer-names))
- (not (run-hook-with-args-until-success
- 'golden-ratio-inhibit-functions)))
- (progn
- (balance-windows)
- (-golden-ratio-resize-window (-golden-ratio-dimensions)
- (selected-window)))))
-
-
-(defadvice select-window
- (after golden-ratio-resize-window)
- (golden-ratio))
-
+ (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
+ always (funcall fun))))
+ (let ((dims (golden-ratio--dimensions)))
+ (golden-ratio--resize-window dims)
+ (scroll-left))))
+
+;; Should return nil
(defadvice other-window
(after golden-ratio-resize-window)
- (golden-ratio))
-
-(defadvice split-window
- (after golden-ratio-resize-window)
- (golden-ratio))
-
-(defadvice delete-window
- (after golden-ratio-resize-window)
- (golden-ratio))
+ (golden-ratio) nil)
;;;###autoload
-(defun golden-ratio-enable ()
- "Enables golden-ratio's automatic window resizing"
- (interactive)
- (ad-activate 'select-window)
- (ad-activate 'other-window)
- (ad-activate 'split-window)
- (ad-activate 'delete-window))
-
-
-;;;###autoload
-(defun golden-ratio-disable ()
- "Disables golden-ratio's automatic window resizing"
- (interactive)
- (ad-deactivate 'select-window)
- (ad-deactivate 'other-window)
- (ad-deactivate 'split-window)
- (ad-deactivate 'delete-window))
+(define-minor-mode golden-ratio-mode
+ "Enable automatic window resizing with golden ratio."
+ :lighter " Golden"
+ (if golden-ratio-mode
+ (progn
+ (add-hook 'window-configuration-change-hook 'golden-ratio)
+ (ad-activate 'other-window))
+ (remove-hook 'window-configuration-change-hook 'golden-ratio)
+ (ad-deactivate 'other-window)))
(provide 'golden-ratio)
- [nongnu] elpa/golden-ratio 6af760274b 16/95: Fixing several bugs at once, (continued)
- [nongnu] elpa/golden-ratio 6af760274b 16/95: Fixing several bugs at once, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio ff8ade7d35 19/95: Merge branch 'release/with-exemption-support', ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 7504957a7a 23/95: Merge pull request #19 from deftsp/inhabit-func, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 2d1553431c 25/95: Merge pull request #22 from Fuco1/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio c028a68645 26/95: Initial cleanup., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio d7c433c655 27/95: (golden-ratio--resize-window): Fix, it is not a cond but when twice., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio b2eb54a74c 28/95: Remove unuseful advices and create new minor mode., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 239eb4d9cb 29/95: (golden-ratio): scroll left., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio d877ceec2c 30/95: Remove commented line., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio f547dee6ad 31/95: (golden-ratio-mode): fix lighter., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 0d7e18325d 33/95: Merge pull request #1 from thierryvolpiatto/exp,
ELPA Syncer <=
- [nongnu] elpa/golden-ratio 7646627bbf 34/95: * golden-ratio.el: Add group., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 07fc7d7f7b 35/95: Merge branch 'master' of github.com:thierryvolpiatto/golden-ratio.el, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 4871294c94 36/95: * golden-ratio.el (pop-to-buffer): Advice also pop-to-buffer., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 6e58cc5871 37/95: Merge branch 'origin-exp', ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio a19b9b0a3b 39/95: * golden-ratio.el: Fix window-resizable-p compatibility with 24.2., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 19bacbeaee 40/95: * golden-ratio.el (golden-ratio--resize-window): Remove unuseful nil arg., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio e66acd10ae 41/95: * golden-ratio.el (window-height-after-balance, window-width-after-balance): Prefix with golden-ratio., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 134156bbff 42/95: * golden-ratio.el: Allow running golden-ratio when switching with other commands than other-window., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 5411fb2798 45/95: Merge pull request #23 from thierryvolpiatto/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 38948457fd 48/95: Merge remote-tracking branch 'refs/remotes/upstream/master', ELPA Syncer, 2023/09/07