Maximizing / restoring a window in emacs
Ok, so maybe this is more a question for the superuser site but I figured there'd be a hell of a lot more emacs users on stackoverflow.
Basically 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.)
Th开发者_运维问答anks! John.
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.
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).
(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.
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
.
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
.
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.
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
精彩评论