Git Product home page Git Product logo

golden-ratio.el's Introduction

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

For more info about the golden ratio check out

http://en.wikipedia.org/wiki/Golden_ratio

Install

Use el-get to install.

Usage

To enable automatic resizing, put on your .emacs.d/init.el

(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.

(setq golden-ratio-adjust-factor .8
      golden-ratio-wide-adjust-factor .8)

Fixed width

When working with files that are required to have a maximum line width or when writing text it's sometimes good to have a fixed width on the window you are typing in. For example when editing this files it's nice to set:

(setq golden-ratio-max-width 100)

When I write I like to have two empty buffers on the side and set

(setq golden-ratio-max-width 72)

to get a distraction free experience.

Credits

Code inspired by ideas from Tatsuhiro Ujihisa

golden-ratio.el's People

Contributors

abo-abo avatar arbelt avatar arcanis avatar bad-ptr avatar deftsp avatar dsevilla avatar ericgebhart avatar fuco1 avatar hickinbottoms avatar pataquets avatar roman avatar shouya avatar skangas avatar thierryvolpiatto avatar vkazanov avatar vmfhrmfoaj avatar zane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golden-ratio.el's Issues

Add `handle-select-window` to `golden-ratio-extra-commands`

Currently golden-ratio doesn't kick in if you have mouse-autoselect-window on and you move your mouse over another window. After some digging it looks like simply adding handle-select-window to golden-ratio-extra-commands does the trick. Very simple fix but I can open a pull-request if you'd prefer.

Cheers,
Zane

Add autoload cookies

Please add ;;;###autoload declarations to the interactive defuns so
the package manager will be able to provide them automatically without
need to require the package.

execute golden-ratio at startup of a REPL

Sorry, not really an issue, just I don't know how to do it: I prefer to manually execute golden-ratio by a macro rather than using the golden-ratio-mode, but I would like to automatically execute golden-ratio once when the REPL starts. I have very limited knowledge of elisp, and cannot get it to work by simply add golden-ratio to the inferior-python-mode-hook.

Preserve windows width when quiting compilation buffer

Hello,

When I run compile and it opens a new buffer with the compile result my cursor change to the compilation buffer, however when quiting compilation buffer with q my cursor goes back to the previous buffer. But it keeps the witdth as if it was still on compilation buffer.

Thanks for the wonderful project. 😃

Erratic horizontal resizing behavior

If the intention is for horizontal siblings of the focused window to all have the same width that behavior appears to be broken for certain frame width / window combinations. Here we have three windows in a frame with a width of 239 (focused window on the right):

Note that the focused window is the right size, but the middle window is abnormally small.

This function and advice appears to fix the behavior by balancing the widths of all the focused window's siblings from the outside in (order matters, otherwise you wind up resizing the focused window as well). I imagine there's a more elegant solution, but this is what worked for me:

(defun zane/window-siblings-at-side-list (side &optional window)
  (let ((window (or window (selected-window))))
    (let ((next (cond ((eq side 'left)
                       (window-left window))
                      ((eq side 'right)
                       (window-right window)))))
      (if (eq next nil)
          nil
        (cons next
              (zane/window-siblings-at-side-list side next))))))

(defun zane/balance-sibling-widths (&optional window)
  "Even widths of all provided windows other than the selected window."
  (let* ((window (or window (selected-window)))
         (siblings (append (reverse (zane/window-siblings-at-side-list 'left window))
                           (reverse (zane/window-siblings-at-side-list 'right window))))
         (total-width (apply '+ (mapcar 'window-width siblings))))
    (dolist (sibling siblings)
      (condition-case nil
          (window-resize sibling
                         (- (/ total-width (length siblings))
                            (window-width sibling))
                         t)
        (error nil)))))

(defadvice golden-ratio
  (after horizontally-balance-after-golden)
  (zane/balance-sibling-widths))

(ad-activate 'golden-ratio)

Here is the desired effect of the above advice on a frame with the same width/number of windows:

golden-ratio won't work with ace-window package

Hello,

Read about golden-ratio on the Internet which I found could be usefull stuff. Tried it but it did not work at first.

I had to manually do a one-call to golden-ratio RET to make it works and then, I had to C-x o to make it really working with my setup. When trying to navigate from buffer to buffer using the excellent ace-window package did nothing.

What can I do ?

"GNU Emacs 25.0.50.1 (x86_64-apple-darwin14.0.0, NS appkit-1343.16 Version 10.10.1 (Build 14B25))
of 2014-12-17 on kcals.intra.maillard.im"

'(golden-ratio-exclude-modes
(quote
("eshell-mode" "diff-mode" "dired-mode" "ediff-mode")))
'(golden-ratio-mode t)

Nothing more.

Thank you

Other windows are unnecessarily resized after switching perspective

I have (setq-default golden-ratio-adjust-factor .53) so that I can have 3 windows of the same width. That way eyes travel less and only the height will change:

screen shot 2016-12-21 at 12 32 53

After switching perspective with persp-mode, it looks like this:

screen shot 2016-12-21 at 12 34 47

In this case, I moved to the middle window. The ratio for that window is respected but others are not. Disabling and re-enabling golden-ratio-mode doesn't fix the issue, but closing a "column" window (ie. not one of the 2 on the left) and re-opening it does fix the issue.

Let me know what I can provide to help debug this issue, if any. Thanks

Inhibit functions don't seem sufficient to prevent resizing windows

There's a conflict between which-key and golden-ratio (Ref justbur/emacs-which-key#67) where golden-ratio seems to nudge the which-key buffer down. See the pictures in the referenced issue.

I tried this, but it doesn't seem to help

(defun which-key-showing? ()
  (and which-key--buffer (window-live-p (get-buffer-window which-key--buffer))))
(setq golden-ratio-inhibit-functions '(which-key-showing?))

I confirmed that this function works and therefore should prevent golden-ratio from doing anything. There's just something that golden-ratio is doing that I can't prevent. Any ideas would be appreciated.

Mouse works, Ctrl-xo doesn't

When changing window with the mouse, the window is properly resized, when doing it with keyboard C-xo does't

System: Mac OS X Lion
Emacs type: Aquamacs
Emacs version: 23.3.50.1

Expected behaviour: To change the window size properly when changing buffer with keyboard

golden ratio with ecb problem

I love Golden ratio and been using it for a while now, but recently I started using Emacs Code browser for my rails projects and the golden-ratio mode is working a bit odd with ecb. It resizes the ecb windows to a larger size.
This behaviour might be natural for the golden ratio, but it takes up unnecessary space on the screen. I want golden-ratio to resize everything except ecb buffers.
Is there any way to do so?

Vertical spilt gives reverse golden ratio

When I use a horizontal split, everything is peachy (dark modeline is the active window):

screenshot from 2015-07-20 07-34-16
screenshot from 2015-07-20 07-34-20

But when I split vertically, I get "opposite" golden ratio, where the active window is the smaller one:

screenshot from 2015-07-20 07-34-36
screenshot from 2015-07-20 07-34-38

does not expand windows with restclient major mod

If I split the window and open a .http file for rest-client mode initially it will be expanded but when I focus off and back on, it will remain minimized. and can only switch if you change the buffer to another non restclient major mode file.

Statusline

What do you use for styling your statusline? It looks like powerline, but I don't see any traces of that in your .emacsd.

golden-ratio does not work nicely with eshell

For other buffers, it was fine. But when I switched to eshell, the eshell's window resized back and forth as well as blinked a few times. This is annoying. This plugin would be perfect if this issue is fixed.

This issue happens when golden-ratio-mode is enabled. For manually resizing, there's no problem.

Moving to a complex workspace using eyebrowse while using golden-ratio-mode results in error

Description :octocat:

Creating or moving to a eyebrowse workspace with a complex window arrangement while in golden-ratio-mode results in error.

Turning off golden-ratio-mode removes the error.

Observed on Spacemacs' master and develop. Observed on base Emacs install with no Spacemacs or other libraries pre-loaded.

Reproduction guide 🪲

  1. Clear out your emacs configuration by deleting or moving your .emacs.d/
  2. Start Emacs
  3. Enable Marmalade repo (https://marmalade-repo.org/#download)
  4. Install eyebrowse using install-package
  5. Install el-get (https://github.com/dimitri/el-get)
  6. Install golden-ratio-mode using el-get-install golden-ratio-mode
  7. M-x eyebrowse-mode Turn on eyebrowse mode
  8. M-x golden-ratio-mode Turn on golden-ratio mode
  • Step 8B: Close all windows but one, using C-x 0. Load your *scratch* buffer the one remaining window
  1. C-x 3 Split window on the right
  2. C-x 2 Split window on the bottom
  3. C-x 3 Split window on the right
  4. ✅ There should be four windows
  5. M-x eyebrowse-create-window-config Create a new workspace using eyebrowse

Observed behaviour: 👀 💔
The new workspace is created!

However, we stay in our original workspace. One of the windows has disappeared from our original workspace; we now have three windows.

This error appears in the status bar:

window--state-put-1: Cannot resize window #<window 56 on  *temp*>

Expected behaviour: ❤️ 😄
The new workspace is created. We move to the new workspace. Our original workspace is unmodified.


I originally reported this to the Spacemacs repo here: syl20bnr/spacemacs#7779

They said to file a bug upstream, so I filed one with eyebrowse-mode here: wasamasa/eyebrowse#56

The eyebrowse-mode developer took a look at the issue. He reproduced the issue and made some fixes to eyebrowse-mode (releasing version 0.7.2). However, he and I both agree that his fixes do not solve the issue - it's still able to be reproduced. He thinks underlying issue should be solved inside of golden-ratio-mode and has closed the issue in eyebrowse; see his comment here: wasamasa/eyebrowse#56 (comment)

golden-ratio call requires golden-ratio-mode

Since commit e2cbe68 the function golden-ratio requires to enable golden-ratio-mode. Is this by accident or on purpose? If the latter, the readme is a little misleading, as it states "To call golden ratio manually just M-x golden-ratio".

Odd behavior with quit-window

  1. Create at least 2 windows
  2. C-h v
  3. Type in golden-ratio-extra-commands. Help buffer will open in other window.
  4. Move to window with Help buffer.
  5. Hit q for quit-window
  6. Another window will be selected but the window that previously had the Help buffer will be resized as the primary window.

Golden ratio not working with Evil?

For example I have bounded the keys nn to (evil-window-vsplit)

But there is no golden ratio. It will only be activated, when I turn on Helm in one of the windows.

Propably this is a bug, or Golden Ratio conflicts with Evil?

Golden-ratio keeps resizing sr-speedbar, and don't listening to ignore.

Hi there. Thanks for sharing the plugin. I use sr-speedbar, to get a view of the structure of files/directories.

When I open the speedbar with sr-speedbar-toggle. Instead getting as a small file browser, it's resizing to more than half of my window. Golden-ratio triggers this behaviour.

After looking around, I found this command
(setq golden-ratio-exclude-buffer-names '("*helm M-x*" "*helm for files*"))

When I do C-x C-b in speedbar window, I see the name of the buffer is *SPEEDBAR*.

So I modified it in:
(setq golden-ratio-exclude-buffer-names '("\\*SPEEDBAR*"))

But golden-ratio still resizing the speedbar window, instead just ignoring it. I found no another solution or answers here.

Any suggestion?

Enable an option to toggle golden ratio at a per frame basis

I often have multiple frames, each with a different configuration of the windows, and sometimes only one or two where I want golden-ratio enabled.
The problem is that when I toggle golden-ratio on, it toggles to all of them, several times destroying their window organization.
Is there a way to implement it only in one frame and not in the others?

Thank you!

Asymmetry on defining-minor-mode

I noticed a strange asymmetry on defining the mode

(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)))

The first branch of the if statement has progn but the other does not but they look similar. Shouldn't they be wrapped around by a symmetrical progn too?

(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))
      (progn ;; Progn here
        (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))))

Not really as issue, just spotted it.

Add advice on `select-window'

What's the rationale behind not adding an advice for select-window? Instead of adding advice to other-window, one should have advised select-window as the lowest-level function for window selection (which is used by all the other Emacs code that requires this action). Otherwise, this plugin is merely useless.

I'll leave the code here...

  (advice-add #'select-window
              :after
              #'(lambda
                    (select-window-function &rest ...)
                  (unless (minibuffer-window-active-p (selected-window))
                    (golden-ratio)))))

... feel free to adapt it to the old defadvice system.

By the way, in general, the ultimate recipe to ensure some action happening when frames/windows/buffers are switched is

(add-hook 'focus-in-hook              ...)
(add-hook 'focus-out-hook             ...)
(add-hook 'window-configuration-hook  ...)

(advice-add #'select-window
            :after
            #'(lambda
                  (select-window-function &rest ...)
                (unless (minibuffer-window-active-p (selected-window)) ;; Optional
                  ...))))

Make golden-ratio modeline string a variable

Hi,

Now the modeline string of golden-ratio is hardcoded to " Golden". I hope this could be made as a variable. I have golden-ratio-mode enabled globally, so there is no need to see a "Golden" string on the status bar which is already quite short of space. Thanks.

Strange windows' sizes at wide frames

There isn't a better way to describe it than by a screenshots:
zrzut ekranu z 2014-12-21 17 20 48
zrzut ekranu z 2014-12-21 17 18 56
zrzut ekranu z 2014-12-21 17 20 21

Versions:
GNU Emacs 24.4.1 (x86_64-suse-linux-gnu, GTK+ Version 3.14.5) of 2014-11-26 on cloud127
golden-ratio.el: 6173b7c

Please tell me if you need some more info!

Enhancement: don’t resize when dimension changes are small

Sometimes, screen dimensions and window configuration are such that the resizing done by golden-ratio results in a negligible change. It might be convenient to have a customizable variable containing a threshold value which allows avoiding the «jumpyness» of resizing the window dimensions when there is little to be gained in terms of window balance.

Resizing when creating a new buffer

I'm not fluent enough with elisp to do it, but it would be nice to resize the windows after creating a buffer, so it does not take 50% of the size

Add minor modes to exclusion list?

Currently, golden-ratio excludes based on major modes. However, excluding based on minor-modes may also be useful. For example minimap-mode shouldn't allow golden-ratio to modify. Of course this can be accomplished with golden-ratio-inhibit-functions, or even golden-ratio-exclude-buffer-names. However, I think that it may also be useful to add a customizable variable for minor-modes.

PR #48 is breaking gnus-summary-scroll* functions

To reproduce:

Launch gnus, fetch some mail or news, hit RET repetitively in gnus summary buffer, the message
doesn't scroll.
Disable golden-ratio-mode or switch to version 1.0 gnus scroll normally.

Need to have a filter list

some windows (like those created by anything) shouldn't trigger golden-ratio re-arrange. would be nice to filter them out, eg. by buffer name.

golden ratio doesn't work with helm

When a helm buffer pops up, it is invisible. Simply enable golden-ratio mode and then call e.g. helm-find-file.

No idea how to fix this :/

el-get not recognized by emacs

I need to know - do you have a solution to my problem.

I have installed el-get.

The emacs app does not recognize any el-get command after using M-x.

I'm looking to use el-get to install yasnippet.

Is it one of the supported packages?

No more 'golden-ratio-enable'?

Hello,

README says that golden-ratio should be initialized with:

(golden-ratio-enable)

However, this function seems to be missing in HEAD version. Can you please update README accordingly?

Thanks!

Temporarily inhibit golden-ratio when using undo-tree-mode

When using undo-tree-mode, the setup width of window for it has been broken by golden-ratio. So can you temporarily turn off golden-ratio when calling undo-tree, and turn on it again after undo-tree window closed?

Thanks ahead of time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.