Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent Emacs dired from splitting frame into more than two windows?

Tags:

emacs

dired

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?

like image 821
incandescentman Avatar asked Apr 21 '14 23:04

incandescentman


People also ask

How do I get rid of split screen in Emacs?

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.

Can you only have one buffer open in Emacs at a time?

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.

How do I open a second window in Emacs?

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.


2 Answers

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)
like image 65
xelibrion Avatar answered Sep 29 '22 19:09

xelibrion


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.

like image 27
Andreas Röhler Avatar answered Sep 29 '22 18:09

Andreas Röhler