Directory and Project Browsers
Eight years passed from the first release of this post and things changed quite a bit, but I kept it over the years. The following is a list of changes made to the original content to reflect updates made to packages listed here:
A rather common feature of many IDEs and text editors is a file system and function/symbols browser, typically shown on the left of the editor.
Emacs provides several options to implement this feature. Here I recap the ones I have tried.
I prefer sticking with relatively standard options, avoiding configuration headaches and hiccups. I usually stick to:
- Dired, when I work with files and directories. Not a sidebar, but very useful.
- Treemacs which I appreciate for its approach to workspace management and for its configuration files written in Org Mode.
- SrSpeedbar (and its “father” Speedbar), for navigating the file system. (Treemacs seems to be another excellent choice.)
In action here:
In the rest you can find a description of these and various other packages I have tried.
Table of Contents
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
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
- 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
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
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 directories more difficult to distinguish.
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.
emacs-dirtree used to show a directory tree, but I have not been able to make it run on recent versions of Emacs.
Imenu and friends
This group of modes is useful for navigating source code:
imenunavigates on the symbols defined in a file and optionally builds a menu with the functions defined in a buffer.
imenu-listshows a sidebar with the list of symbols and functions (but I have not found a simple way to automatically update the list when you switch buffer).
imenubut for multiple buffers. It is a useful navigation tool, more intuitive than
xtags. The combination with
imenu-listis very interesting.
Neotree is a Emacs tree plugin like NerdTree for Vim.
Simple and intuitive. The only critique is that the mode blocks the width of the sidebar; long filenames are thus only partially shown. This is, however, similar to what other modes do.
A useful command is
C-c C-c, which changes the root of the currently
In the words of the author, this package presents helpful sidebars for Org buffers. Sidebars are customizable using org-ql queries and org-super-agenda grouping.
The command I use is
org-sidebar-tree which shows the structure of the
Org Mode file I am editing.
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
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.
Speedbar can also show a list of functions defined in a file. No support for Ruby, apparently, though.
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.
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.
A nice touch is that it opens up files, listing functions and todos (for Org Modes). It is a feature present in all the the IDEs I am aware of and provides a nice overview of the structure of each file.
It has modern look and various integrations, among which projectile, and git, to mention two.
Really worth a try.
(From the project GitHub page)
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:
- ztree-diff is a directory-diff tool for Emacs. It supports showing the difference between two directories; calling Ediff for not matching files, copying between directories, deleting file/directories, hiding/showing equal files/directories.
- ztree-dir is a simple text-mode directory tree for Emacs. Invoke it with ztree-dir. It is not a sidebar, but you can use it as such, if you “protect” your layout or avoid splitting your window.