Reputation: 6368
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?
Upvotes: 10
Views: 2021
Reputation: 2234
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)
Upvotes: 7
Reputation: 4804
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.
Upvotes: 5