reddit / emacs
How can I maximize another window momentarily?
robopiglet · 2022-11-19 19:15
I often have two side by side windows and, in my case, the right one shows the output of something in the left one (an error, or the result of a function). I'll want to see that error or output and then get back t my side by side arrangement and continue right where I am in the first. Currently, I switch to the other window with ace-window o (C-x o in my case) then mazimize that one with zoom-window-zoom (bound to z in my case). The nice thing with zoom-window-zoom is that it toggles... so z again unmazimizes the window. Then I C-x o again to get back to the first window. So, to fill my screen with the other window: C-x o, z, z, C-x o. Muscle memory at this point. But I want to be able to hit one key and maximize the other window, and hit it again to unmaximize the other window, and have my pointer where it was in the first window at the end. I'm not attached to ace-window or zoom-window-zoom... they were just what I happened across. I realize this may be more complicated if I have more than two windows open, but I very seldom do. Thoughts? And Thanks!
PS - I have a lot of rebindings so knowing the command a suggested binding invokes is helpful.
ieure · 2022-11-19 19:36
You can use the built-in [winner-mode](https://www.emacswiki.org/emacs/WinnerMode), which tracks window configuration changes and lets you undo them. So `C-x 1` to focus on a single window, then `winner-undo` to go back.
I have winner's undo/redo bound to `C-c <left>` / `C-c <right>`, but I don't think it has any default bindings.
mickeyp · 2022-11-19 21:56
Yep. Winner's awesome.
If you use tab bar, you can also use `M-x tab-bar-history-mode` and `M-x tab-bar-history-forward/backward` as they're "local" to your tab. A third option's a register with a window configuration; a fourth is a keyboard macro that sets up your window layout the way you want it.
robopiglet · 2022-11-20 00:31
This is super helpful (and I'll have to look at Mastering Emacs now too!). I still am on a mission to get a single key press to maximize/fullscreen the opposite window, and the same key to reverse it. I don't mind if the pointer jumps to the other screen, so long as it is where it started once the windows are side by side again. I'll play with the window layout option both of you are mentioning and try to assign it to a single keystroke. I do use Emacs in a terminal, so not sure the tab bar applies.
robopiglet · 2022-11-20 01:51
I do still want a single-keypress able solution to maximize/restore the window opposite the one the pointer is in while momentarily moving the pointer to that window as it is maximized.
I'll play with winner mode but I think it looks like it would still be around the same number of keystrokes/actions as my current approach (C-x o, z, z, C-x o). Those invoke ace-window with an arg (C-x o) and zoom-window-zoom (z) in my case.
vifon · 2022-11-20 02:05
A quick and dirty proposal:
(defun zoom-window ()
"Maximize the window or bring back the previous layout."
(interactive)
(if (one-window-p)
(winner-undo)
(delete-other-windows)))
…or alternatively:
(defun zoom-other-window ()
"Maximize the other window or bring back the previous layout."
(interactive)
(if (one-window-p)
(winner-undo)
(other-window 1)
(delete-other-windows)))
Depending on your preferred behavior. It should be a good starting point.
robopiglet · 2022-11-20 02:18
Thanks! I'll give it a go. And I'll also learn about creating defun's in the process. :-)
robopiglet · 2022-11-20 02:22
Oh wow! That's all I need. And I've learned a lot... with your example building off the direction of the previous replies.
[deleted] · 2022-11-20 02:23
[deleted]
[deleted] · 2022-11-20 02:24
[deleted]
robopiglet · 2022-11-20 02:24
I'll still need to work a little on where the cursor is left, but now I see how I can do that by modifying the defun.
redguardtoo · 2022-11-20 02:52
One command is enough,
```
(defun my-toggle-full-window()
"Toggle full view of selected window."
(interactive)
;; @see http://www.gnu.org/software/emacs/manual/html_node/elisp/Splitting-Windows.html
(if (window-parent)
(delete-other-windows)
(winner-undo)))
```
3-days-ago · 2022-11-20 02:55
Here's an alternative that doesn't require winner-mode enabled.
(defvar my-min-max-window nil)
(defun my-min-max-window()
(interactive)
(if (and (one-window-p) my-min-max-window)
(window-state-put my-min-max-window)
(setq my-min-max-window (window-state-get))
(delete-other-windows)))
timmymayes · 2022-11-20 07:27
Let me ask some questions to see if I understand this fully:
1. 2 windows side by side to start
2. output hits window 2 and you want to pop that window into full screen
3. when you're done you want to go back to 2 panel with cursors where they started?
4. you are typically active in buffer A and Buffer B is interfaced with when maxmiized?
Caveat I'm wanting to understand. Buffer A and Buffer B are side by side. B goes to maximized then resplit to A/B side by side.
Another thing I'd like to call out for getting this type of thing to work is macros. You can should spend some time playing with recording, naming and writing to your config macros.
The toggle on one key might be tough but you could easily record 2 macros, name them then bind them and have it on 2 keys or even on C-<key> M-<key>
This was how I got started figuring out how to make emacs do what I want without losing too much productivity and while learning elisp (which I'm still doing)
robopiglet · 2022-11-20 07:34
Thank you! You definitely have the solution with the most brevity.
Aminumbra · 2022-11-20 08:51
One other thing that might be worth mentioning: [registers](https://www.gnu.org/software/emacs/manual/html_node/emacs/Configuration-Registers.html) !
They would probably be a good solution for "more complex" situations, typically, you have a "complex" layout (with 3 windows or more, for example), and need to temporarily override it to do something else (which would typically be more than 'open a buffer to check something').
If that is the case, you can save the first layout in a register, do the changes you need, and reload the first layout whenever you want.
Bonus: you can save various such registers, if you want to save several complex layouts and jump between them.
For your situation, though, `winner-mode` would be my solution.
github-alphapapa · 2022-11-20 15:35
For transient (not `transient`) layouts, winner-mode and other mentioned solutions are probably most appropriate.
But FYI, you may also find this useful: https://github.com/alphapapa/burly.el
github-alphapapa · 2022-11-20 15:35
Even better than registers is to use `burly` to bookmark window and frame configs: https://github.com/alphapapa/burly.el
arthurno1 · 2022-11-20 19:53
He said he wants the 'other-window' to get maximized. This one is maximizing current-window. But combined with something from [this thread](https://www.reddit.com/r/emacs/comments/x0r0pe/share_your_otherwindow_commands/) it will work fine :).
Particularly check the comment by dbqpdb (and my answer).
arthurno1 · 2022-11-20 20:12
Didn't you want the "other-window" to get maximized? This one maximizes the current window. You can check the link I posted in the other comment about doing stuff in the other window. You can combine the 'my-toggle-full-window' with the "do-in-other-window" [from this thread](https://www.reddit.com/r/emacs/comments/x0r0pe/share_your_otherwindow_commands/) (comment by dbqpdb), or you can get the code to copy-paste from [here too](https://github.com/amno1/.emacs.d/blob/main/lisp/extras.el), lines 320 - 371.
Also, you mention something like full-screen sometimes; all those functions are just making a window the only one in the frame, but none is toggling Emacs to full-screen. If you would like to do that too, you will have to look at [frame parameters](https://www.gnu.org/software/emacs/manual/html_node/elisp/Frame-Parameters.html) and some functions from frame.el (toggle-frame-fullscreen or toggle-frame-maximized for example).
robopiglet · 2022-11-27 07:11
You understood the situation correctly. However, I only have one cursor active, so 'cursors where they started?' would be 'cursor where it started?'. When window 2 pops into full screen it should have an active cursor.
I'll look at macros, for sure... seems like a good thing to know.