golden-ratio.el-1.0/0000755000175000017500000000000012520355503014167 5ustar dogslegdogsleggolden-ratio.el-1.0/golden-ratio.el0000644000175000017500000001510512520355503017077 0ustar dogslegdogsleg;;; golden-ratio.el --- Automatic resizing of Emacs windows to the golden ratio ;; Copyright (C) 2012 Roman Gonzalez ;; Author: Roman Gonzalez ;; Mantainer: Roman Gonzalez ;; Created: 13 Oct 2012 ;; Keywords: Window Resizing ;; Version: 0.0.4 ;; Code inspired by ideas from Tatsuhiro Ujihisa ;; This file is not part of GNU Emacs. ;; This file is free software (MIT License) ;;; Code: (eval-when-compile (require 'cl)) (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." :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) (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)) (defcustom golden-ratio-recenter nil "Recenter window vertically and scroll right when non--nil." :group 'golden-ratio :type 'boolean) (defcustom golden-ratio-adjust-factor 1.0 "Adjust the width sizing by some factor. 1 is no adjustment. For very wide screens/frames, ie. 3400px, .4 may work well." :group 'golden-ratio :type 'integer) (defcustom golden-ratio-wide-adjust-factor 0.8 "Width adjustment factor for widescreens. Used when toggling between widescreen and regular modes." :group 'golden-ratio :type 'float) (defcustom golden-ratio-auto-scale nil "Automatic width adjustment factoring. Scales the width of the screens to be smaller as the frame gets bigger." :group 'golden-ratio :type 'boolean) ;;; Compatibility ;; (unless (fboundp 'window-resizable-p) (defalias 'window-resizable-p 'window--resizable-p)) (defun golden-ratio-toggle-widescreen () (interactive) (if (= golden-ratio-adjust-factor 1) (setq golden-ratio-adjust-factor golden-ratio-wide-adjust-factor) (setq golden-ratio-adjust-factor 1)) (golden-ratio)) (defun golden-ratio-adjust (a) "set the adjustment of window widths." (interactive (list (read-number "Screeen width adjustment factor: " golden-ratio-adjust-factor))) (setq golden-ratio-adjust-factor a) (golden-ratio)) (defun golden-ratio--scale-factor () (if golden-ratio-auto-scale (- 1.0 (* (/ (- (frame-width) 100.0) 1000.0) 1.8)) golden-ratio-adjust-factor)) (defun golden-ratio--dimensions () (list (floor (/ (frame-height) golden-ratio--value)) (floor (* (/ (frame-width) golden-ratio--value) (golden-ratio--scale-factor))))) (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." (interactive) (unless (or (not golden-ratio-mode) (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-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)))) ;;;###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))) (provide 'golden-ratio) ;;; golden-ratio.el ends here golden-ratio.el-1.0/LICENSE0000644000175000017500000000204112520355503015171 0ustar dogslegdogslegCopyright (c) 2012 Roman Gonzalez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.golden-ratio.el-1.0/README.md0000644000175000017500000000500312520355503015444 0ustar dogslegdogsleg# golden-ratio.el When working with many windows at the same time, each window has a size that is not convenient for editing. golden-ratio helps on this issue by resizing automatically the windows you are working on to the size specified in the "Golden Ratio". The window that has the main focus will have the perfect size for editing, while the ones that are not being actively edited will be re-sized to a smaller size that doesn't get in the way, but at the same time will be readable enough to know it's content. ![Golden Ratio](https://raw.github.com/roman/golden-ratio.el/assets/golden_ratio_el.gif) For more info about the golden ratio check out http://en.wikipedia.org/wiki/Golden_ratio ## Install Use [el-get](https://github.com/dimitri/el-get) to install. ## Usage To enable automatic resizing, put on your .emacs.d/init.el ```elisp (require 'golden-ratio) (golden-ratio-mode 1) ``` *** If you want to disable automatic resizing done by golden-ratio, just invoke `M-x golden-ratio-mode` To call golden ratio manually just `M-x golden-ratio` ## Wide Screens If you use a large screen and have very wide frames golden-ratio makes very wide windows. This can be handled automatically by setting _golden-ratio-auto-scale_ to true. This does a good job of keeping windows at a reasonable width regardless of how wide or narrow your frame size is. This works well on my laptop regardless of which monitor or LCD I happen to be using. `(setq golden-ratio-auto-scale t)` For those who wish for manual control, If _golden-ratio-auto-scale_ is false, manual control can be exercised through the _golden-ratio-adjust-factor_ variable. setting it to something less than 1 will cause the windows to be less wide. The golden-ratio-adjust function allows for experimentation with this value. `M-x golden-ratio-adjust` It is also possible to toggle between widescreen and regular width window sizing with `M-x golden-ratio-toggle-widescreen` The variable _golden-ratio-wide-adjust-factor_ can be set to the adjustment value you desire the widescreen toggle to use. The following code will set up golden-ratio to adjust for a moderately wide screen and also allow toggling between normal, with an adjustment factor of 1, and wide with an adjustment factor of .8. For a very wide screen/frame of ~3400 px, .4 works well giving screens with a width ~100 columns wide. ```elisp (setq golden-ratio-adjust-factor .8 golden-ratio-wide-adjust-factor .8) ``` ## Credits Code inspired by ideas from [Tatsuhiro Ujihisa](http://twitter.com/ujm) golden-ratio.el-1.0/.gitignore0000644000175000017500000000000512520355503016152 0ustar dogslegdogsleg*.elc