Double dired with sunrise commander

I’ve written several times about managing files in emacs with dired. However, if I am copying or moving files between two directories, I have found that I like a two-paned file browser showing the two directories side by side. The package sunrise commander provides this very nicely, giving a great interface for managing files and even copying files between remote and local directories.

It is a tiny bit fiddly to install as it is not in one of the standard package archives. I would suggest evaluating the following code snippet to add the required repository:

(add-to-list 'package-archives '("SC" . "") t)

You can then install sunrise-commander using M-x package-list-packages as normal. The repository will be forgotten next time you restart emacs, which is fine as sunrise-commander is stable and rarely updated, and the repository can be slow to respond sometimes, which can affect the package listing.

While you are at it, also install sunrise-x-buttons and sunrise-x-modeline from the same place.

Once you have done this, use M-x sunrise to start sunrise-commander. This will open a two-paned dired style file browser as illustrated in this screen shot:


The top left and right panes are two different directory listings, each of which behave very much like dired. You can switch between them with TAB, and if you try to copy or move files, it will default to copying them to the opposite pane, which is just what you want.

This works particularly well when using emacs to manage remote files, indeed in the screenshot above, the left pane is a directory on a remote machine, so it is easy to copy files back and forth between the local and remote machines.

The bottom panel is a set of buttons to perform common tasks (provided by the sunrise-x-buttons extension); I don’t use the buttons but I find them a useful reminder of the keys for those tasks.

The sunrise-x-modeline extension updates the modeline of each directory pane to show a clickable path to the current directory.

There are several other extensions available, as described on the wiki page, and there is a second useful wiki page of tips for sunrise commander.

I have a couple of tweaks that I make:

;; sunrise commander                                                      ;;
(require 'sunrise-commander)
;; disable mouse
(setq sr-cursor-follows-mouse nil)
(define-key sr-mode-map [mouse-1] nil)
(define-key sr-mode-map [mouse-movement] nil)

;;tweak faces for paths
(set-face-attribute 'sr-active-path-face nil
                    :background "black")
(set-face-attribute 'sr-passive-path-face nil
                    :background "black")

;;advise sunrise to save frame arrangement
;;requires frame-cmds package
(defun bjm-sc-save-frame ()
  "Save frame configuration and then maximise frame for sunrise commander."
(advice-add 'sunrise :before #'bjm-sc-save-frame)

(defun bjm-sc-restore-frame ()
  "Restore frame configuration saved prior to launching sunrise commander."
(advice-add 'sr-quit :after #'bjm-sc-restore-frame)

This code disables mouse interaction, and changes the background colour of the directory paths.

More interestingly, I want sunrise commander to run full screen, but then I want my original frame size back when I finish with it. To do this I wrote two simple functions above, that use the frame-cmds library mentioned recently. The first saves the current frame configuration and then maximises the current frame – sunrise commander is advised to call this function when it starts. The second restores the saved frame configuration, and sunrise commander is advised to call this when it quits.