Permalink
Browse files

Merge pull request #15 from hickinbottoms/feature/add-exemptions

Support exclusions based on buffer name or major mode
  • Loading branch information...
2 parents f5b3602 + 650121b commit 9843ca2239d2c1b0a3c7a1e3b9106e8d13fbcdc6 @roman committed Nov 12, 2012
Showing with 25 additions and 1 deletion.
  1. +25 −1 golden-ratio.el
View
@@ -20,6 +20,26 @@
(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."
+ :type '(repeat string)
+ :group 'golden-ratio)
+
+;; Buffer names that are exempt from being resized. An example of this
+;; 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."
+ :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))))
@@ -47,7 +67,11 @@
"Resizes current window to the golden-ratio's size specs"
(interactive)
(if (and (not (window-minibuffer-p))
- (not (one-window-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)

3 comments on commit 9843ca2

but, how to filter out ediff mode?

Owner

roman replied Nov 19, 2012

(setq golden-ratio-exclude-buffer-names '("ediff-mode")) won't resize your ediff window when accessing it

Contributor

deftsp replied Nov 20, 2012

(setq golden-ratio-exclude-buffer-names '("ediff-mode")) can not work perfectly. After you execute `ediff-buffer', ediff-buffer-A / ediff-buffer-B will be resize. It cause "Ediff Control Panel" will be larger than normal.

I have give a pull request #19
then you can use following code to solve this problem.

(defun pl/inhibit-golden-ratio-for-ediff-func ()
  (let ((ediff-buffer (get-buffer "*Ediff Control Panel*"))
        (cur-buffer (current-buffer))
        (m major-mode))
    (if ediff-buffer
        (with-current-buffer ediff-buffer
          (if (or (eq ediff-buffer-A cur-buffer)
                  (eq ediff-buffer-B cur-buffer)
                  (eq ediff-buffer-C cur-buffer)
                  (eq m 'ediff-mode))
              t)))))

(add-to-list 'golden-ratio-inhibit-functions 'pl/inhibit-golden-ratio-for-ediff-func)
Please sign in to comment.