Dirtree

Menu

A rather common feature of many IDEs and text editors is a file system browser, typically shown on the left of the editor.

Emacs provides various options to implement this feature. Here I recap the ones I am aware of.

Table of Contents

Dired

Dired ships with Emacs and allows one to navigate the file system in a buffer. By default, dired shows detailed information about each file in the chosen directory:

total used in directory 72 available 285255156
drwxr-xr-x 3 adolfo adolfo  4096 Mar 16 10:44 .
drwxr-xr-x 7 adolfo adolfo  4096 Mar 11 14:34 ..
-rw-r--r-- 1 adolfo adolfo  3788 Mar 16 10:44 dirtree.org
-rw-r--r-- 1 adolfo adolfo 10003 Mar  9 09:23 emacs-caldav.org
drwxr-xr-x 3 adolfo adolfo 4096 Mar 15 22:02 emacs

By default Dired opens each directory in its own buffer, unless one uses I, which appends the content of a directory in the current buffer.

Dired has an option to hide all the details, showing the file name only. This option allows to show dired on a sidebar, even on smaller screen. Proceed as follows:

  • Split the frame vertically (C-x 3) and resize it
  • Open dired on the window of your choice using C-x d or M-x dired
  • Select “Hide details” from the menubar (“Immediate” -> “Hide details”)

The advantage is that one gets all the feature of dired, at the cost of losing navigation in a tree view. Another disadvantage is that if the dired buffer opens in a regular window and the window layout might be easily lost, for instance with C-x 1.

Dired Sidebar

Dired sidebar is a minor mode that leverages ’dired’ to emulate a tree browser.

Install it from Melpa (M-x package-istall dired-sidebar) and then invoke it with M-x dired-sidebar-toggle-sidebar.

Used in conjunction with dired-subtree, it shows and allows to navigate the file system hierarchically, while getting all the benefits of dired. No triangular icon is shown on directories, however, which makes navigation visually more difficult.

Speed Bar

Another possibility is using Speed Bar, which also ships with Emacs. Invoke it with M-x speedbar and a new frame will open showing the file system.

Speedbar offers various context-aware navigation capabilities. It shows files, buffers, org-mode headers, info files, emails, according to the content displayed in the other frame. This makes the mode very flexible.

Three aspects I do not particularly like about this function:

  1. The Speed Bar runs in its own frame: this makes its use difficult when you start moving windows around. Tiling window managers, such as i3, mitigate the issue; another possibility is using SrSpeedbar, described below.
  2. Clicking on the icon of a directory has a different effect than clicking on the directory name. In the former, the Speed Bar shows the content of the directory in a subtree; in the latter, Speed Bar changes the root of the filetree to the clicked directory
  3. By default only the directories are shown (no files). This can be easily changed in the preferences, though.

SrSpeedbar

SrSpeedbar is a mode that makes SpeedBar show in the Current Frame, by SebastianRose.

This makes speedbar a lot more usable, in my opinion, but some of the oddities of Speed Bar still remain.

Neotree

Neotree is a Emacs tree plugin like NerdTree for Vim.

Simple and intuitive. The only critique is that the mode blocks the size of the sidebar and long filenames are only partially shown. This is, however, similar to what other modes do.

A Useful command is C-c C-c to change the root of the currently shown tree.

ZTree

ZTree is a project dedicated to implementation of several text-tree applications inside GNU Emacs. It consists of 2 subprojects: ztree-diff and ztree-dir (the basis of ztree-diff).

The latter can be used to navigate a file tree in a buffer.

Treemacs

Treemacs is a file and project explorer in the same vein as NeoTree or vim’s NerdTree. It shows the file system outline in a simple tree layout allowing quick navigation and exploration, while also possessing basic file management utilities.

Similar to SrSpeedbar, with a more modern look and more functions. For instance, it recognizes sections and symbols in formatted text (such as Markdown) and source code.

Dirtree

emacs-dirtree used to show a directory tree, but I have not been able to make it run on recent versions of Emacs.

Direx

direx.el is a simple directory explorer. It also works as a generic tree explore library.

I never used it, but it is another possibility to consider.

Date: 2014-11-16 Sun 00:00

Author: Adolfo Villafiorita

Created: 2020-04-03 Fri 18:43

Validate