Function: adjust-window-trailing-edge
adjust-window-trailing-edge is a byte-compiled function defined in
window.el.gz.
Signature
(adjust-window-trailing-edge WINDOW DELTA &optional HORIZONTAL PIXELWISE)
Documentation
Move WINDOW's bottom edge by DELTA lines.
Optional argument HORIZONTAL non-nil means move WINDOW's right edge by DELTA columns. WINDOW must be a valid window and defaults to the selected one.
Optional argument PIXELWISE non-nil means interpret DELTA as number of pixels.
If DELTA is greater than zero, move the edge downwards or to the right. If DELTA is less than zero, move the edge upwards or to the left. If the edge can't be moved by DELTA lines or columns, move it as far as possible in the desired direction.
Probably introduced at or before Emacs version 22.1.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun adjust-window-trailing-edge (window delta &optional horizontal pixelwise)
"Move WINDOW's bottom edge by DELTA lines.
Optional argument HORIZONTAL non-nil means move WINDOW's right
edge by DELTA columns. WINDOW must be a valid window and
defaults to the selected one.
Optional argument PIXELWISE non-nil means interpret DELTA as
number of pixels.
If DELTA is greater than zero, move the edge downwards or to the
right. If DELTA is less than zero, move the edge upwards or to
the left. If the edge can't be moved by DELTA lines or columns,
move it as far as possible in the desired direction."
(setq window (window-normalize-window window))
(let* ((frame (window-frame window))
(minibuffer-window (minibuffer-window frame))
(right window)
left first-left first-right this-delta min-delta max-delta ignore)
(unless pixelwise
(setq pixelwise t)
(setq delta (* delta (frame-char-size window horizontal))))
;; Find the edge we want to move.
(while (and (or (not (window-combined-p right horizontal))
(not (window-right right)))
(setq right (window-parent right))))
(cond
((and (not right) (not horizontal)
;; Resize the minibuffer window if it's on the same frame as
;; and immediately below WINDOW and it's either active or
;; `resize-mini-windows' is nil.
(eq (window-frame minibuffer-window) frame)
(= (nth 1 (window-pixel-edges minibuffer-window))
(nth 3 (window-pixel-edges window)))
(or (not resize-mini-windows)
(eq minibuffer-window (active-minibuffer-window))))
(window--resize-mini-window minibuffer-window (- delta)))
((or (not (setq left right)) (not (setq right (window-right right))))
(if horizontal
(user-error "No window on the right of this one")
(user-error "No window below this one")))
(t
;; Set LEFT to the first resizable window on the left. This step is
;; needed to handle fixed-size windows.
(setq first-left left)
(while (and left
(or (window-size-fixed-p left horizontal)
(and (< delta 0)
(<= (window-size left horizontal t)
(window-min-size left horizontal nil t)))))
(setq left
(or (window-left left)
(progn
(while (and (setq left (window-parent left))
(not (window-combined-p left horizontal))))
(window-left left)))))
(unless left
;; We have to resize a size-preserved window. Start again with
;; the window initially on the left.
(setq ignore 'preserved)
(setq left first-left)
(while (and left
(or (window-size-fixed-p left horizontal 'preserved)
(and (< delta 0)
(<= (window-size left horizontal t)
(window-min-size
left horizontal 'preserved t)))))
(setq left
(or (window-left left)
(progn
(while (and (setq left (window-parent left))
(not (window-combined-p left horizontal))))
(window-left left)))))
(unless left
(if horizontal
(user-error "No resizable window on the left of this one")
(user-error "No resizable window above this one"))))
;; Set RIGHT to the first resizable window on the right. This step
;; is needed to handle fixed-size windows.
(setq first-right right)
(while (and right
(or (window-size-fixed-p right horizontal)
(and (> delta 0)
(<= (window-size right horizontal t)
(window-min-size
right horizontal 'preserved t)))))
(setq right
(or (window-right right)
(progn
(while (and (setq right (window-parent right))
(not (window-combined-p right horizontal))))
(window-right right)))))
(unless right
;; We have to resize a size-preserved window. Start again with
;; the window initially on the right.
(setq ignore 'preserved)
(setq right first-right)
(while (and right
(or (window-size-fixed-p right horizontal 'preserved)
(and (> delta 0)
(<= (window-size right horizontal t)
(window-min-size
right horizontal 'preserved t)))))
(setq right
(or (window-right right)
(progn
(while (and (setq right (window-parent right))
(not (window-combined-p right horizontal))))
(window-right right)))))
(unless right
(if horizontal
(user-error "No resizable window on the right of this one")
(user-error "No resizable window below this one"))))
;; LEFT and RIGHT (which might be both internal windows) are now the
;; two windows we want to resize.
(cond
((> delta 0)
(setq max-delta
(window--max-delta-1
left 0 horizontal ignore 'after nil pixelwise))
(setq min-delta
(window--min-delta-1
right (- delta) horizontal ignore 'before nil pixelwise))
(when (or (< max-delta delta) (> min-delta (- delta)))
;; We can't get the whole DELTA - move as far as possible.
(setq delta (min max-delta (- min-delta))))
(unless (zerop delta)
;; Start resizing.
(window--resize-reset frame horizontal)
;; Try to enlarge LEFT first.
(setq this-delta
(window--resizable
left delta horizontal ignore 'after nil nil pixelwise))
(unless (zerop this-delta)
(window--resize-this-window
left this-delta horizontal ignore t 'before
(if horizontal
(+ (window-pixel-left left) (window-pixel-width left))
(+ (window-pixel-top left) (window-pixel-height left)))))
;; Shrink windows on right of LEFT.
(window--resize-siblings
left delta horizontal ignore 'after
(if horizontal
(window-pixel-left right)
(window-pixel-top right)))))
((< delta 0)
(setq max-delta
(window--max-delta-1
right 0 horizontal ignore 'before nil pixelwise))
(setq min-delta
(window--min-delta-1
left delta horizontal ignore 'after nil pixelwise))
(when (or (< max-delta (- delta)) (> min-delta delta))
;; We can't get the whole DELTA - move as far as possible.
(setq delta (max (- max-delta) min-delta)))
(unless (zerop delta)
;; Start resizing.
(window--resize-reset frame horizontal)
;; Try to enlarge RIGHT.
(setq this-delta
(window--resizable
right (- delta) horizontal ignore 'before nil nil pixelwise))
(unless (zerop this-delta)
(window--resize-this-window
right this-delta horizontal ignore t 'after
(if horizontal
(window-pixel-left right)
(window-pixel-top right))))
;; Shrink windows on left of RIGHT.
(window--resize-siblings
right (- delta) horizontal ignore 'before
(if horizontal
(+ (window-pixel-left left) (window-pixel-width left))
(+ (window-pixel-top left) (window-pixel-height left)))))))
(unless (zerop delta)
;; Don't report an error in the standard case.
(when (window--resize-apply-p frame horizontal)
(if (window-resize-apply frame horizontal)
(window--pixel-to-total frame horizontal)
;; But do report an error if applying the changes fails.
(error "Failed adjusting window %s" window))))))))