YYYY




This is in the process of being decommissioned.

For the new stuff, go to
http://blogish.nomistech.com/


Sunday 9 June 2013

Simple Directory Navigation for Emacs

When using Emacs I've always missed having a nice way to navigate around directory structures and display their contents. Dired comes close to what I want, but it's less than ideal.

I've added a few commands and key bindings that make it easy to do what I want. You can find them in my Emacs initialisation code, specifically at Nomis Dired Explorer.

My Requirements

First, a terminology note. I'm using Emacs terminology, so a "frame" is what you probably normally call a window and a "window" is what you probably normally call a pane in a window.

I want these things:

  1. A frame with a side-by-side view with a navigation window on the left and a content window on the right.
  2. Commands to navigate the directory hierarchy and to change the selection within a directory, without updating the content window.
  3. A command to make the content window display the item that is selected in the navigation window.
  4. Single commands that combine navigation with updating the content window to show the newly-selected item.
  5. Easy-to-remember key bindings for the commands, with the bindings for navigating-without-updating-content and navigating-with-updating-content differing by the addition of the same key for each type of navigation.

I've chosen to use Dired as a basis for things, so a further requirement is not to blat existing Dired key bindings.

Nomis Dired Explorer is perhaps the simplest possible way to satisfy these requirements.

Setting up Nomis Dired Explorer

To avoid clutter, I suggest having "A" in your dired-listing-switches so that . (the current directory) and .. (its parent) are not displayed by Dired.

Another reason not to display the current directory is that Dired's dired-display-file command, which is used by Nomis Dired Explorer, does not work on the current directory

Using Nomis Dired Explorer

Nomis Dired Explorer looks like this (click the image for a larger version):

There's a Dired window on the left and a content window on the right.

To make the best use of vertical space, set up a wide window containing a Dired buffer. Then when Dired opens the content window it will appear to the right of the navigation window rather than below it. (Maybe I'll add something later to make this step easier.)

Nomis Dired Explorer has these commands:

  • Navigation commands (most of these are existing Dired commands with new bindings that satisfy my easy-to-remember-bindings requirement):
    • M-<up>
      dired-previous-line

      The Dired command to go up a line.

    • M-<down>
      dired-next-line

      The Dired command to go down a line.

    • M-<left>
      dired-up-directory

      The Dired command to go up a directory.

    • M-<right>
      nomis-dired-find-file-if-dir

      If the selected item is a directory, go down a directory.

  • A display command:
    • M-<RET>
      dired-display-file

      The Dired command to display the selected item in the content window.

  • Combined navigation and display commands; these are like the navigation commands but they also display the newly-selected item in the content window:
    • M-S-<up>
      nomis-dired-previous-line
    • M-S-<down>
      nomis-dired-next-line
    • M-S-<left>
      nomis-dired-up-directory
    • M-S-<right>
      nomis-dired-down-directory

Coda

This is pretty simple stuff, but it makes a huge difference to my ability to navigate around in Emacs.

It's probably worth saying that after adding my new commands and key bindings I came across http://www.emacswiki.org/emacs/DiredMode. You may find something better than Nomis Dired Explorer there. I had a quick look but didn't find anything I wanted to use.

1 comment:

  1. Just thought I would mention something that I find really nice is dirtree, which gives you an expandable directory tree, simple navigation commands, the choice to expand a directory, or open up a dired buffer on that directory, and opening a file brings it up in a window beside the tree view.

    I installed it with el-get. Another cool thing is that you can have a bunch of different roots, so you can jump around different trees easily.

    I know it is not dired, but I have found it absolutely brilliant for browsing around a project, which can be difficult in dired because you can lose your overview. For most things, ido-mode and dired are great, but for those moments where browsing is what you really need to do, dirtree is brilliant.

    ReplyDelete