From XEmacs to Emacs

13 February 2014
Although I use Gvim professionally and have worked out how to get it to use my preferred C/C++ bracing style, one thing that has lingered on my to-do list has been giving Emacs (as opposed to XEmacs) a proper try-out. In the past Emacs has struck me as more focused on NCurses-style text-based interfaces rather than graphical ones, and for a long time it has left me with the impression it only grudgingly supported X-Windows rather than embracing it, but regardless of how much these views reflected reality it has also been years since I last really tried Emacs. In any case I thought that switching from XEmacs to Emacs would not be anywhere near as a turnaround as switching to GVim.

Bye bye XEmacs

The overriding problem with XEmacs is that it has trouble running a lot of the more interesting packages out there, such as CEDIT, which as far as I can tell is due to bit-rot in its Lisp interpretor. The last stable release was in 2003, and beta versions simply will not cut it for professional code development. There is also the SXEmacs fork out there, but since there are no pre-packed Windows binaries I initially rejected it. In the end I did give it a try, but I was somewhat disappointed with how it performed, so in the end it went out the window as well.

Requirements

The only major reason I really used XEmacs at all for so long was its unrivalled indentation engine, which Emacs has anyway. Aside from this, I was also looking for code folding and code completion, both of these are available in CEDIT, which is detailed below. Support for tabs was also a requirement. Beyond these things, it was a case of minor adjustments to how things like scrolling behaved in XEmacs and GVim.

Tabs in Emacs

The Emacs community is something that seems somewhat against the idea of tabbed browsing, but for me it is a tick-list item. My programming editor(s) of choice is something I reasonably expect to spend a sizeable portion of my life in front of, so it is not something I will compromise my personal tastes on. Of all the implementations I gave come across, the only two I've taken to are an experimental Gtk-Tabs Emacs branch, and a lisp-based tab-bar module.

Gtk-Tabs

There is a GTK-Tabs branch of Emacs that includes native tab support, but it needs a bit of digging to find, and getting it working can be rather hit-n-miss. Once built the only problem I've noticed with it is an inability to use CEDIT, most likely because it is based on an early-ish beta of Emacs 24.0. I tend not to use many Lisp packages, so there may be other issues with it I have not noticed.

Once it has been built, use M-x tab-new to show tabs. To build it on Ubuntu 12.04 you will need to install the following packages:

Once that is done, download & build using the following commands (amend as needed):

bzr clone http://bzr.savannah.gnu.org/r/emacs/gtk-tabs/ cd gtk-tabs ./configure -prefix=/usr/local/gtk-tabs make bootstrap make make install

The Bazaar clone will pull down 331MB, so it will take quite some time. Due to oddities with Ubuntu 12.04 64-bit, you may encounter these problems:

gcc: error: unrecognized option '-2.0/'
This is caused by a historical artefact causing library paths containing unix to screw up. Fix is to change line 3135 of configure.in to the following:
[cpp_undefs="`echo $srcdir $configuration $canonical unix |
and then running autoconf to rebuild your configure script.
make[2]: *** No rule to make target `/usr/lib/crt1.o', needed by `temacs'. Stop.
This is caused by the file being somewhere odd on 64-but Debian-based systems. Fix by changing lines 126-127 in src/m/amdx86-64.h to the following:
#define START_FILES pre-crt0.o /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o #define LIB_STANDARD -lgcc -lc -lgcc /usr/lib/x86_64-linux-gnu/crtn.o
Hopefully the above is noted down correctly, as they were worked out by the combination of Googling and hacking away at the code until it worked.

Tabbar mode

Through much searching, I came across TabBarMode, of which the most up-to-date version I could find is elsewhere on GitHub. By itself it is too ugly for my tastes, so I combined it with a modified version of Tabbar ruler. The modification was a hack to get around a missing color-name-to-rgb call, which causes the loss of the nicer looking icons, but improves the look of the tabs:

It is not nearly as good as tabs in XEmacs (or any other editor I've used), and it has a few edge cases, but it gets the job done. I've not tried building it for Windows, which I expect might be an ordeal.

CEDIT

Recently I came across CEDIT (Collection of Emacs Development Environment Tools) which is aimed at turning Emacs into something more like an IDE, but so far I have only used two of its features: Code folding, and code completion. Installation is a bit tricky, but enabling the stuff I want just needs the following in ~/.emacs.d/init.el:

(load-file "~/.emacs.d/lib/cedet-1.1/common/cedet.el") (semantic-load-enable-code-helpers) (require 'semantic-tag-folding) (defun c-folding-hook () (global-semantic-tag-folding-mode 1) (local-set-key (kbd "C-c ") 'semantic-tag-folding-fold-block) (local-set-key (kbd "C-c ") 'semantic-tag-folding-show-block) (local-set-key (kbd "C-N") 'semantic-ia-complete-symbol-menu) )

Binding semantic-ia-complete-symbol-menu to Ctrl-N is because I have become used to GVim using that key combination for its code completion. My one complaint, apart from CEDIT being a little heavyweight, is that it does not seem to work well for completing C++ this-> if you are writing functions in-line the class definition (i.e. like Java/C#) rather than separately.

Code folding alternative

Historically I have used Folding Mode, which uses token-based folding (i.e. putting /* {{{ */ & /* }}} */ everywhere), and so far still seems one of the better solutions out there. It is clunky and occasionally screws up (especially with line numbering), but I have been using it for at least the last five years. One thing I miss from using FoldingMode with Emacs (as opposed to XEmacs) is highlighting of folds when you move the mouse over them, but it seems that folding-mode-motion-highlight-fold is an Xemacs-only feature.

Another alternative folding plugin is HideShow, which seems to be included with Emacs as standard these days. It seems to do a better job of handling line numbers than Folding Mode above, although the key bindings it uses by default I think are very awkward. XEmacs 2.15 beta also includes HideShow but toggling is somewhat less intuitive with nested folds than that included with Emacs.

Code-completion alternative

Aside from CEDIT, the only other decent Emacs code completion add-on I have come across is AutoComplete. As far as I can tell this is based around keywords rather than semantic analysis of the rest of the source code, and the way it operates by default seems to be a lot nearer Visual Studio (and similar) than CEDIT. I did try AutoComplete with both XEmacs and SXEmacs, but both had problems with it, but it did work with the Gtk-Tabs Emacs branch.

Overall impression

Overall my choice seems to be the stock Emacs with CEDIT, or using the Gtk-Tabs Emacs branch with AutoComplete and FoldingMode, as both combinations seems to provide development environments I feel comfortable with. I am tending towards Emacs/CEDIT mainly because it is actively maintained, and unlike the Gtk-Tabs branch should not be too difficult to get a Windows binary should I start developing C/C++ under Windows again.