I want to optimize my gdb window setup. The idea is to automatically resize the gdb-breakpoints window to the current buffer length. In my setup this buffer is at the bottom and I want it to auto-resize vertically every time I add or remove a breakpoint.

Try function fit-window-to-buffer? Put it on an appropriate hook for use with gdb.

fit-window-to-buffer is an interactive compiled Lisp function in window.el.

(fit-window-to-buffer &optional WINDOW MAX-HEIGHT MIN-HEIGHT MAX-WIDTH MIN-WIDTH)

Adjust size of WINDOW to display its buffer's contents exactly. WINDOW must be a live window and defaults to the selected one.

If WINDOW is part of a vertical combination, adjust WINDOW's height. The new height is calculated from the actual height of the accessible portion of its buffer. The optional argument MAX-HEIGHT specifies a maximum height and defaults to the height of WINDOW's frame. The optional argument MIN-HEIGHT specifies a minimum height and defaults to window-min-height. Both MAX-HEIGHT and MIN-HEIGHT are specified in lines and include mode and header line and a bottom divider, if any.

If WINDOW is part of a horizontal combination and the value of the option fit-window-to-buffer-horizontally is non-nil, adjust WINDOW's width. The new width of WINDOW is calculated from the maximum length of its buffer's lines that follow the current start position of WINDOW. The optional argument MAX-WIDTH specifies a maximum width and defaults to the width of WINDOW's frame. The optional argument MIN-WIDTH specifies a minimum width and defaults to window-min-width'. BothMAX-WIDTHandMIN-WIDTH` are specified in columns and include fringes, margins, a scrollbar and a vertical divider, if any.

Fit pixelwise if the option window-resize-pixelwise is non-nil. If WINDOW is its frame's root window and the option fit-frame-to-buffer is non-nil, call fit-frame-to-buffer to adjust the frame's size.

Note that even if this function makes WINDOW large enough to show all parts of its buffer you might not see the first part when WINDOW was scrolled. If WINDOW is resized horizontally, you will not see the top of its buffer unless WINDOW starts at its minimum accessible position.

  • Yeah I already tried a hook, but it doesn't work with (add-hook 'gdb-breakpoints-mode-hook 'fit-window-to-buffer). Sorry for not mentioning. – bertfred Oct 12 '16 at 16:09
  • 1
    In order for that function to DTRT on a hook, the buffer you want to fit the window to has to be current, displayed in a window, and that window has to be selected. – Drew Oct 12 '16 at 17:52

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.