In an Emacs dired buffer, if I navigate point over a filename and hit o for dired-find-file-other-window
, dired successfully produces desired behavior: opening the file in a secondary window.
But if I then navigate point over a SECOND filename and again hit o, dired splits the frame AGAIN and opens the file in a THIRD window.
How do I direct dired to reuse the second window, such that I always have a maximum of two windows in a frame?
You can use the C-x 0 key combination to delete the current window. Show activity on this post. (winner-mode 1) ;"C-c <left>" and "C-c <right>" undo and re-do window changes.
Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears. But the windows showing the same buffer can show different parts of it, because each window has its own value of point.
To open a new frame, select Make New Frame from the Files menu or press C-x 5 2 (for make-frame). Emacs makes a new frame containing the current buffer and puts it on top of the current frame.
Tried to solve the same problem using by modifying value of split-width-threshold
, but found that it often stops working when monitor configuration changes. Ended up writing an advice for window-splittable-p
.
(setq split-width-threshold (- (window-width) 10))
(setq split-height-threshold nil)
(defun count-visible-buffers (&optional frame)
"Count how many buffers are currently being shown. Defaults to selected frame."
(length (mapcar #'window-buffer (window-list frame))))
(defun do-not-split-more-than-two-windows (window &optional horizontal)
(if (and horizontal (> (count-visible-buffers) 1))
nil
t))
(advice-add 'window-splittable-p :before-while #'do-not-split-more-than-two-windows)
Raise value of split-height-threshold
to the extend it will not do another split.
You might have to raise split-width-threshold
also - in case Emacs thinks it's smart to split that way than.
WRT questions in comment:
The value to choose IMO depends from number of lines displayed at window. Let's assume 40 lines are displayed. If a window is split, 20 are left. Then a `split-height-threshold' of 15 should prevent further split. Preventing further side-by-side split should work respective, just consider the columns displayed.
BTW would expect a way to adapt that dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With