[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/golden-ratio 73e9bd7f94 57/95: Merge remote-tracking branc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/golden-ratio 73e9bd7f94 57/95: Merge remote-tracking branch 'upstream/master' |
Date: |
Thu, 7 Sep 2023 22:02:13 -0400 (EDT) |
branch: elpa/golden-ratio
commit 73e9bd7f944aec4dcdcc20d5ec6c08a7cb392beb
Merge: feddcbe68b 33aa083b66
Author: Stuart Hickinbottom <stuart@hickinbottom.com>
Commit: Stuart Hickinbottom <stuart@hickinbottom.com>
Merge remote-tracking branch 'upstream/master'
---
README.md | 4 +-
golden-ratio.el | 157 ++++++++++++++++++++++++++++++++------------------------
2 files changed, 92 insertions(+), 69 deletions(-)
diff --git a/README.md b/README.md
index 30f47b6db2..65eb80020f 100644
--- a/README.md
+++ b/README.md
@@ -26,13 +26,13 @@ To enable automatic resizing, put on your .emacs.d/init.el
```elisp
(require 'golden-ratio)
-(golden-ratio-enable)
+(golden-ratio-mode 1)
```
***
If you want to disable automatic resizing done by golden-ratio, just invoke
-`(golden-ratio-disable)`
+`M-x golden-ratio-mode`
To call golden ratio manually just `M-x golden-ratio`
diff --git a/golden-ratio.el b/golden-ratio.el
index afcffaab8d..c28b3d4f28 100644
--- a/golden-ratio.el
+++ b/golden-ratio.el
@@ -17,16 +17,20 @@
;;; Code:
(eval-when-compile (require 'cl))
-(defconst -golden-ratio-value 1.618
+(defconst golden-ratio--value 1.618
"The golden ratio value itself.")
+(defgroup golden-ratio nil
+ "Resize windows to golden ratio."
+ :group 'windows)
+
;; 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,79 +38,98 @@ 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)
-(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)))))
-
+(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."
+ :group 'golden-ratio
+ :type '(repeat symbol))
+
+(defcustom golden-ratio-extra-commands
+ '(windmove-left windmove-right windmove-down windmove-up)
+ "List of extra commands used to jump to other window."
+ :group 'golden-ratio
+ :type '(repeat symbol))
+
+;;; Compatibility
+;;
+(unless (fboundp 'window-resizable-p)
+ (defalias 'window-resizable-p 'window--resizable-p))
+
+(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))))
+ (ncol (floor (- (second dimensions) (window-width)))))
+ (when (window-resizable-p (selected-window) nrow)
+ (enlarge-window nrow))
+ (when (window-resizable-p (selected-window) ncol t)
+ (enlarge-window ncol t)))))
;;;###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)))
- (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
+ thereis (funcall fun))))
+ (let ((dims (golden-ratio--dimensions))
+ (golden-p (if golden-ratio-mode 1 -1)))
+ ;; Always disable `golden-ratio-mode' to avoid
+ ;; infinite loop in `balance-windows'.
+ (golden-ratio-mode -1)
+ (balance-windows)
+ (golden-ratio--resize-window dims)
+ (golden-ratio-mode golden-p))))
+
+;; Should return nil
(defadvice other-window
- (after golden-ratio-resize-window)
- (golden-ratio))
-
-(defadvice split-window
- (after golden-ratio-resize-window)
- (golden-ratio))
-
-
-;;;###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))
-
+ (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)))))
+ (golden-ratio)))
;;;###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))
+(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)
+ (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)
+ (ad-deactivate 'other-window)
+ (ad-deactivate 'pop-to-buffer)))
(provide 'golden-ratio)
- [nongnu] elpa/golden-ratio 19bacbeaee 40/95: * golden-ratio.el (golden-ratio--resize-window): Remove unuseful nil arg., (continued)
- [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
- [nongnu] elpa/golden-ratio 25e95f7833 49/95: Merge pull request #27 from thierryvolpiatto/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 1df894012e 51/95: Merge pull request #28 from thierryvolpiatto/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 12b57a3904 53/95: * golden-ratio.el: Fix Issue #29, a typo., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 86ffa26952 54/95: Merge pull request #31 from thierryvolpiatto/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 0b90ffbf02 59/95: Delay window reconfig to fix autofollow, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 73e9bd7f94 57/95: Merge remote-tracking branch 'upstream/master',
ELPA Syncer <=
- [nongnu] elpa/golden-ratio 7da7dd7d53 60/95: * golden-ratio.el (golden-ratio-recenter): New user var, allow recentering, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 892e668685 55/95: * golden-ratio.el (golden-ratio): Fix Issue #32 don't recenter and scroll-right., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio cb9ccd04bb 58/95: Also resize windows when using mouse, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 79ead1cba6 61/95: Merge pull request #35 from thierryvolpiatto/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio d4a2dd0aeb 63/95: * golden-ratio.el (golden-ratio-mode): Issue #34 remove mouse-leave-buffer-hook when mode is off., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 6851a5f720 67/95: Added golden-ratio-toggle-widescreen function, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 26f616f658 70/95: set auto-scale to nil by default., ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio e2cbe68277 71/95: Use a common way to avoid recursion, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio 79b1743fc1 73/95: Merge pull request #45 from vkazanov/master, ELPA Syncer, 2023/09/07
- [nongnu] elpa/golden-ratio b78f921f56 74/95: Allow using symbols in golden-ratio-exclude-modes., ELPA Syncer, 2023/09/07