Maximizing / restoring a window in emacs
Asked Answered
S

7

29

I often have my emacs split into about 4 windows so I can look at a bunch of buffers at the same time, however I'd like to be able to C-x 1 (make the window the same size as emacs) and then somehow restore back to my nice 4 window layout I was just looking at.

Is there an easy way to do this or do I need some elisp / lisp (note: I don't know ANY elisp.)

Smile answered 3/10, 2011 at 23:18 Comment(1)
Note: When I say 'window' I mean 'pane' within emacs. Also note I'm using emacs on Ubuntu under X.Smile
D
29

Try winner-mode.

With winner-mode enabled, you can restore your previous window configuration with C-c<left>.

You can type it repeatedly to step back through the window configuration history, so you're safe even when there have been multiple intervening changes.

C-c<right> returns you (directly) to the most recent configuration.

Discussion answered 3/10, 2011 at 23:31 Comment(1)
Spot on, nice and easy too :)Smile
S
13

I'm sure there are a few different solutions for this, but I use:

C-x r w x to store the window configuration and C-x r j x to restore it, where x is the name of the register to store it in.

Then, I also like winner-mode which allows swiching back to previous window configurations with winner-undo and winner-redo (which I bound to C-^ and C-c ^ because I can't stand the bindings C-c <left> and C-c <right> that are set by default).

Simonides answered 3/10, 2011 at 23:37 Comment(0)
S
9

(winner-mode 1) is my preferred general solution (and I would urge anyone not already using it to add it to their init file immediately), but it's also worth pointing out that for this particular question (maximising a single window and then returning to the previous configuration), simply creating a new frame works very nicely.

  • C-x52 to create the new frame.
  • C-x50 to delete it and return to the original frame.

In a terminal, it's completely seamless. With GUI Emacs it's fine if your new frames are automatically full-screen (or however you prefer them to be), but not as good if you're manually sizing them.

Scut answered 11/6, 2013 at 1:6 Comment(0)
B
3

You should also try C-x 0 in the window you'd like to close, as it will close that specific window but not any other. I think that most people wants this most of the times they use C-x 1.

Beginning answered 5/10, 2011 at 12:2 Comment(0)
P
1

http://www.emacswiki.org/emacs/frame-cmds.el

See commands maximize-frame and restore-frame (aka toggle-frame). There are also commands maximize-frame-horizontally, maximize-frame-vertically, restore-frame-horizontally, and restore-frame-vertically.

Poorhouse answered 7/10, 2011 at 3:53 Comment(2)
While the terminology in the question is not very clear, I do believe from the C-x 1 example that this question is not at all about frames.Wolfsbane
Oops, sorry -- yes, you're no doubt right about that. In that case, the answer about saving and restoring the window configuration is appropriate.Poorhouse
S
0

I use escreen.el for multiple workspace management, but as a side effect, each workspace remembers the window configuration. So, you may find it a useful package.

Other people suggest elscreen instead of escreen, but I haven't used this package yet. So I can't say if it also preserves window configuration of workspaces.

Skirret answered 3/10, 2011 at 23:47 Comment(0)
S
0

Years ago I defined this function in my init.el file:

;; Toggle between split windows and a single window
(defun toggle-windows-split()
  "Switch back and forth between one window and whatever split of windows we might have in the frame. The idea is to maximize the current buffer, while being able to go back to the previous split of windows in the frame simply by calling this command again."
  (interactive)
  (if (not(window-minibuffer-p (selected-window)))
      (progn
        (if (< 1 (count-windows))
            (progn
              (window-configuration-to-register ?u)
              (delete-other-windows))
          (jump-to-register ?u))))
  (my-iswitchb-close))

and then I add a keybinding for it:

(define-key global-map (kbd "C-|") 'toggle-windows-split)

I don't remember if I wrote this myself or got it from someone else. There are similar implementations defined here but I haven't tried them: https://www.emacswiki.org/emacs/ToggleWindowSplit

Syringe answered 29/3, 2023 at 2:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.