Reputation: 642
I'm aware of C-x 1, which will maxamize the current window both horizontally and vertically.
However, my quesiton is, is it possible to expand the current window to the edge of the frame on one direction only?
So in the below I want to expand window A to the right border of the frame, taking up the space currently occupied by B and C. But I want D and E to remain untouched.... and I want to do it in a single command.
Excuse the terrible attempt at ASCII art!
_______________________
| AAAAAA |BBBBBB |CCCC |
|________|_______|______|
| DDDDD | EEEEEEEEEE |
|________|______________|
I know you can move horizontally 1 char at a time, and that you can use the repeat n times command to do this many times, but both are clunky, when what I really want to say is expand until the right hand border, I don't care how far that is.
The nearest I've come up with this to go to each frame occupying the space you want and calling C-X 0, but this is still a bit clunky.
I need this to work in terminal mode (emacs -nw) rather than graphical/X-Windows mode.
Any ideas?
Upvotes: 3
Views: 949
Reputation: 571
I have the same problem: I would like to maximize a window horizontally but not vertically. After searching on the internet with no avail, I decided to write my own function. And I would like to share it here in case it might help someone in the future.
(require 'cl-lib)
(defun durand-maximize-window-horizontally (&optional window)
"Make WINDOW have the same width as the frame.
WINDOW defaults to the selected window.
Other windows are retained, but moved to the top."
(let* ((window (or window (selected-window)))
;; the list of windows to the left
(left-windows-list (let ((temp-window window)
window-list)
(cl-loop while (window-in-direction
'left temp-window t)
do (let ((left-win
(window-in-direction
'left temp-window t)))
(push left-win window-list)
(setf temp-window left-win)))
window-list))
;; the list of windows to the right
(right-windows-list (let ((temp-window window)
window-list)
(cl-loop while (window-in-direction
'right temp-window t)
do (let ((right-win
(window-in-direction
'right temp-window t)))
(setf window-list
(append window-list
(list right-win)))
(setf temp-window right-win)))
window-list))
;; the list of windows to the left and to the right
;; the order is from left to the right.
(same-level-list (append left-windows-list right-windows-list))
;; save all parameters: the car is the buffer, and the cadr is a list
;; of parameters.
(window-parameters-list
(cl-loop for win in same-level-list
collect (list (window-buffer win)
;; (window-width win)
(window-parameters win)))))
(cl-loop for win in same-level-list
do (delete-window win))
;; now our window is the only window horizontally speaking.
;; now we shall create them once again, if they exist.
(when same-level-list
(let* ((split-base-window
(split-window window nil 'above))
(new-windows (list split-base-window))
newly-created-window)
(cl-loop
for ind from 1 to (1- (length same-level-list))
do
(setf newly-created-window
(split-window split-base-window
nil 'right)
;; NOTE: it is important this list also follows the order
;; of going from the left to the right
new-windows (append new-windows
(list newly-created-window))
split-base-window newly-created-window))
(cl-loop for index from 0 to (1- (length same-level-list))
do
(let ((buf (car (nth index window-parameters-list)))
(paras (cadr (nth index window-parameters-list))))
(set-window-buffer
(nth index new-windows) buf)
(cl-loop for para-pair in paras
do (set-window-parameter
(nth index new-windows)
(car para-pair)
(cdr para-pair)))))))))
Upvotes: 0
Reputation: 30701
You can do this with library frame-cmds.el
(description).
It provides these commands:
maximize-frame-horizontally
, maximize-frame-vertically
, and max-frame
restore-frame-horizontally
, restore-frame-vertically
, and restore-frame
The "restore" commands are actually toggles that alternate between maximizing and restoring. (They are aliased to commands toggle-max-frame*
.)
Commands maximize-frame
and restore-frame
are general, and can act like the horizontal and vertical commands by giving them a prefix arg: negative for horizontally, non-negative for vertically.
Upvotes: 2