branch: elpa/golden-ratio
commit c028a68645c01270796eddf7c785dbc6970ac6c4
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Initial cleanup.
---
golden-ratio.el | 94 +++++++++++++++++++++++++++------------------------------
1 file changed, 44 insertions(+), 50 deletions(-)
diff --git a/golden-ratio.el b/golden-ratio.el
index 31334cd897..e2eae88102 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,71 +34,66 @@ 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 ( ;(edges (window-pixel-edges window))
+ (nrow (floor (- (first dimensions) (window-height))))
+ (ncol (floor (- (second dimensions) (window-width)))))
+ (cond ((not (window-full-height-p))
+ (enlarge-window nrow nil))
+ ((not (window-full-width-p))
+ (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))
- (not (run-hook-with-args-until-success
- 'golden-ratio-inhibit-functions)))
- (progn
- (balance-windows)
- (-golden-ratio-resize-window (-golden-ratio-dimensions)
- (selected-window)))))
-
-
+ (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)))
+ (balance-windows)
+ (golden-ratio--resize-window dims))))
+
+;; Should return window
(defadvice select-window
- (after golden-ratio-resize-window)
- (golden-ratio))
+ (around golden-ratio-resize-window)
+ (prog1 ad-do-it (golden-ratio)))
+;; Should return nil
(defadvice other-window
(after golden-ratio-resize-window)
(golden-ratio))
+;; Should return window
(defadvice split-window
- (after golden-ratio-resize-window)
- (golden-ratio))
+ (around golden-ratio-resize-window)
+ (prog1 ad-do-it (golden-ratio)))
+;; Should return nil
(defadvice delete-window
(after golden-ratio-resize-window)
(golden-ratio))
@@ -112,7 +107,6 @@ the window to be resized to the golden ratio."
(ad-activate 'split-window)
(ad-activate 'delete-window))
-
;;;###autoload
(defun golden-ratio-disable ()
"Disables golden-ratio's automatic window resizing"