1

NOTE: I added more info to this query. Initially, I didn't mention dired, but after experimenting, I see that it needs to be explicitly discussed here, because of how it manages buffers.

I'm using emacs-27.2. I am looking for what I consider to be an "exotic" (i.e., non-standard) way to split a buffer between two windows when using dired, as follows:

  1. Enter dired
  2. Split the dired buffer into two windows
  3. The two windows are next to each other, left and right, in the same frame.
  4. The same dired info appears in both windows.
  5. In the leftmost window, the topmost lines of the dired list appear, with the cursor initially automatically positioned to the first line of the dired list as soon as I enter this mode.
  6. In the rightmost window, the bottommost lines of the dired list appear, with the cursor initially automatically positioned to the last line of the dired list as soon as I enter this mode.
  7. As soon as select a subdirectory in the dired list of one of the windows, the directory gets displayed at the same time in the other window, with the top of the buffer showing in the leftmost window and the bottom of the buffer showing in the rightmost window, as described above.

I want all of these characteristics exactly as described, not just a subset of them nor any kind of variation.

I know how to split the window, and I'm sure that I can figure out how to write a function to accomplish what I want. However, before I "reinvent the wheel", I'm wondering if there already is some sort of command or mode which can give me this functionality.

2 Answers 2

0

M-x follow-mode is very close to what you're requesting. It lets you show a buffer in two windows, with one of the windows starting at the line where the other left off.

You may have to explicitly visit a subdir in both windows, and turn on follow-mode for that buffer as well, but out-of-the-box follow-mode gets you quite close. (You can write a command that visits a subdir and sets that up the same way etc.)

2
  • Thank you very much. I'm working on a follow-mode-based solution now, and assuming I get it to work, I'll post my findings.
    – HippoMan
    Dec 13, 2021 at 22:44
  • Great! With your answer we'll have a more a useful Q&A.
    – Drew
    Dec 14, 2021 at 0:29
0

Based on the very helpful answer by Drew, I figured out what to do.

First, I wrote this command ...

(defun my-dired-action ()
  (interactive)
  (let* ((files (dired-get-marked-files t current-prefix-arg))
         (file (expand-file-name (car files)))
    (dired-view-file)
    (when (file-directory-p file)
      (delete-other-windows)
      (follow-delete-other-windows-and-split))
    ))

And then, I start dired as follows:

(require 'dired)
;; set up `dired-mode-hook` to map the `my-dired-action` 
;; function to the desired keystrokes and mouse clicks
(dired)
(follow-delete-other-windows-and-split)

The follow-delete-other-windows-and-split function is a standard elisp function to split the current window and to then initiate follow-mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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