Directory and Project Browsers
A rather common feature of many IDEs and text editors is a file system or project 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.
My choices:
- Dired, which I mainly use for file system exploration
- SrSpeedbar, of which I appreciate the integration with Org Mode
- Treemacs, for software development
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
orM-x dired
- Select “Hide details” from the menu bar (“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:
- 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. The problem is less relevant, if you use a tiling window manager.
- 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 file tree to the clicked directory
- 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. Written by Sebastian Rose.
This makes Speedbar a lot more usable, in my opinion, but some of the oddities of Speedbar 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 sub projects: 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 differentiates from the other packages in a rather interesting way. Rather than replicating the file system, Treemacs focuses on projects, that is portions of the the file system, and workspaces, that is collections of projects.
It has modern look and various integrations, among which projectile, and git, to mention two.
Really worth a try.
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.
Revisions
- Updated description of Treemacs, which is not at version 2, and fixed wording.
- First release