The Right Lang for the Job

Exploring the abbyss of non-mainstream programming languages

Make <TAB> select the other Dired window

Replicating the best feature of Sunrise Commander in plain Dired


Some time ago, Sunrise Commander - a two-pane file manager for Emacs, built on top of Dired by Drew Adams - stopped working for me. The loss of familiar bindings was a little painful, but I mostly solved it with Hydra - the functionality is mostly still there in Dired.

One thing I missed was swithcing to the other Dired window easily. With just two Dired windows occupying a whole frame just M-x other-window worked well, but with more windows, I had to fall back to M-x windmove-* and that was less convenient1.

I decided to fix it at some point, and here's the result:

 1: (defun my-select-other-dired-window ()
 2:   "Select the other dired window, if there is only one."
 3:   (interactive)
 4:   (let* ((selected-window (selected-window))
 5:          (other-windows (cdr (window-list))))
 6:     (cl-loop for w in other-windows
 7:              if (with-current-buffer (window-buffer w)
 8:                   (derived-mode-p 'dired-mode)) 
 9:              collect w into result
10:              finally
11:              (when (= 1 (length result))
12:                (select-window (car result))))))
14: (keymap-set dired-mode-map "<tab>" #'my-select-other-dired-window)

Now I can select the other Dired buffer by pressing <TAB> in one of them, no matter how many other windows are there.



Testing footnotes