Emacs Redux

Return to the Essence of Text Editing


| Comments

For the longest time Prelude included the function prelude-goto-symbol (bound to C-c i). It basically allowed you to jump to any definition in the current source file using imenu behind the curtains.

Recently I’ve found an even better option - the package imenu-anywhere. It works in a pretty similar manner but gives you the ability to jump to any definition in any currently open buffer. That’s quite handy and it greatly reduces the need to use something like etags.

As an added bonus - imenu-anywhere features helm integration.

This is a very handy package and I encourage you to give it a go!

P.S. Prelude users should simply upgrade to the latest version of Prelude (it already uses it).

My Personal Emacs Configuration

| Comments

From time to time people ask me about my personal Emacs configuration. Other just assume that I use Prelude. For a very long time my personal configuration was pretty similar to Prelude - in a way it was a staging ground for things to go into Prelude eventually (although changes would travel both ways when Prelude users suggest some cool things).

Recently I’ve decided that in the future I want to do a few things with Prelude:

  • extract as much functionality from it as possible into reusable packages (e.g. super-save and crux)
  • adopt there use-package
  • improve the support for Windows (because now I have Windows computer)

As part of these efforts I reworked my personal config into something pretty simple (it’s a single init.el file) and I’ve started experimenting with ideas for the future. Stay tuned for the results!

The config is available here. Perhaps some of you will find something useful there.

Remap Return to Control in GNU/Linux

| Comments

A long time ago I wrote about remapping Return to Control in OS X. This was the best productivity boost for my Emacs experience ever!

Recently I’ve bought a Windows ultrabook (wanted something as light as MacBook Air, but more powerful and versatile) and I’m doing most of my work there in a Xubuntu VM. The first thing I did while setting up Xubuntu was to figure out how to do the aforementioned remapping.

In my original post some people suggested the tool xcape, so I took a look at it. The tool can certainly use some documentation improvements (and pre-built packages), but it gets the job done. After you’ve installed it you just need to add the following to your login shell’s init file (e.g. .bash_profile) and you’re in business:

xmodmap -e "remove Control = Control_R"
xmodmap -e "keycode 0x69 = Return"
xmodmap -e "keycode 0x24 = Control_R"
xmodmap -e "add Control = Control_R"

xcape -t 10000 -e "Control_R=Return"

Obviously the first time around you should source .bash_profile after updating it:

$ . .bash_profile

This is definitely a lot more work than just clicking in the GUI of the wonderful Karabiner, but it yields the desired results and that’s what’s important at the end of the day.

Now if only there was a way to achieve the same result in Windows…

P.S. vim users will love xcape. Its default behaviour is to generate the Escape key when Left Control is pressed and released on its own.


| Comments

I’d often blog about some useful utility functions here. Pretty much all of them get included in Emacs Prelude, but I’ve decided I can do one better and extract those of them which are most useful/universal into a separate package.

This package is crux - a Collection of Ridiculously Useful eXtensions for Emacs.

You can install it from MELPA and MELPA Stable. Once this is done you just have to pick keybindings for the commands shipped with crux. I’ve suggested some keybindings here. And here’s a small configuration snippet showing how to actually bind keys to some of crux’s commands:

(global-set-key [remap move-beginning-of-line] #'crux-move-beginning-of-line)
(global-set-key (kbd "C-c o") #'crux-open-with)
(global-set-key [(shift return)] #'crux-smart-open-line)
(global-set-key (kbd "s-r") #'crux-recentf-ido-find-file)
(global-set-key (kbd "C-<backspace>" #'crux-kill-line-backwards))
(global-set-key [remap kill-whole-line] #'crux-kill-whole-line)

crux also ships with some handy advises that can enhance the operation of existing commands.

For instance - you can use crux-with-region-or-buffer to make a command acting normally on a region to operate on the entire buffer in the absense of a region. Here are a few examples you can stuff in your config:

(crux-with-region-or-buffer indent-region)
(crux-with-region-or-buffer untabify)

So, this is crux for you - simple and neat! I’d love it if you contributed more useful commands to it, so we can make it even more versatile!


| Comments

A while back I wrote an article on saving buffers when they lose focus.

Recently I’ve packaged (an improved version of) this functionality into a tiny global minor mode called super-save.

The package is available on MELPA and MELPA Stable and enabling it is trivial:

(super-save-mode +1)

If you want to enable the additional feature of auto-saving buffers when Emacs is idle, add the following as well:

(setq super-save-auto-save-when-idle t)

If you’re like me and don’t care about the backups created by the built-in auto-save-mode, you can disable it aftewards:

(setq auto-save-default nil)

I’ve been using Emacs for over 10 years now and I’ve never needed the auto-created backups - I’m either very lucky or this is less useful than it’s supposed to be.

Ace-jump-mode Is Dead, Long Live Avy

| Comments

People often ask how am I navigating efficiently Emacs windows and buffers. I have the feeling they expect me to share with them some secrets that would turbo-charge common commands like C-s, M-f, C-x o, etc. I don’t, however, use those commands that much. Ever since I saw that vim’s EasyMotion has been ported to Emacs, I’ve been using that port - namely ace-jump-mode.

Basically, it allows you to navigate to every visible portion of your Emacs (buffers & windows) with only a handful of keystrokes (usually one two activate it and one or two to get where you want to go). You can see it in action in this excellent video. ace-jump served me well for years, but I’ve had a few gripes with it that were never addressed (multi-char targets, CamelCase support, etc). I would have implemented those myself, if the project was maintained at all, but alas - that’s not the case. Seems I wasn’t the only one who was frustrated with ace-jump, as the prolific Oleh Krehel reimplemented it pretty much from scratch for the purposes of his excellent ace-window library. Once I got wind of this, I managed to persuade Oleh to start distributing his rewrite as a standalone project, which he dubbed avy.

Avy features everything ace-jump does and more. Apart from the many extra features, its codebase is way cleaner and readable and Oleh is a fantastic and very responsive maintainer. So, as far as I’m concerned ace-jump is now a dead project and pretty much everyone who’s using it should try out avy instead. Their usage and interface are pretty similar, so the learning curve is non-existing. By the way, here’s avy in action:

And what about my usage of avy? Nothing fancy here - I just bind the commands I consider most important to handy keystrokes.

(global-set-key (kbd "C-c j") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "s-.") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "s-w") 'ace-window)

avy-goto-word-or-subword-1 is aware of CamelCase words and I do a lot of programming in languages that use those extensively.

avy has one more thing going for it - it’s part of the default Emacs package repo GNU ELPA, which means that you can install it right away without having to setup any third-party repositories (which you’ll probably need sooner or later).

avy and ace-window are naturally part of Prelude.

P.S. Oleh, one of those days you should rename ace-window to avy-window. :-)

JDEE Reborn

| Comments

JDEE (Java Development Environment for Emacs) used to be best way to develop Java apps in Emacs a while back. It offered a ton of cool features, like smart auto-completion and a debugger. Unfortunately at some point the development slowed down significantly and the project went in a catatonic state. There was pretty much no activity for years in the official SourceForge repo and there was also no support for features introduced in Java 5+.

Recently, however, the project migrated to GitHub and it’s now way easier to get involved. Seems that some people have already started work on updating JDEE to support modern JDKs and modern Emacs functionality.

That’s a really exciting project, as Java support has traditionally been a weakness of Emacs and I’m writing this post with the hope that more people will help make JDEE great again.

So what are you waiting for? If you’re into Java and friends (Scala, Clojure, Groovy, etc), check out the new official repo and let’s get this party started!

Mastering Emacs (the First Emacs Book in Over a Decade) Is Out

| Comments

Mickey Petersen just released Mastering Emacs, the first new book about our beloved editor, since Learning GNU Emacs(released way back in 2004).

I haven’t had the time to read the book yet, but being familiar with Mickey’s work I have no doubt it’s outstanding. That’s all from me for now - go buy the book and start mastering Emacs.


I hope we won’t have to wait another decade for the next great Emacs book.

Learning Emacs Lisp

| Comments

People who have been using Emacs for a while often develop the desire to learn Emacs Lisp, so they can customize Emacs more extensively, develop extra packages and create the ultimate editing experience, uniquely tailored to their needs & preferences.

There are a ton of Emacs Lisp resources our there, but most people generally need only one - the official Emacs Lisp manual. It’s bundled with Emacs and you can start reading right away by pressing C-h i m Elisp RET. If you’re relatively new to programming in general you might also check out the Introduction to Emacs Lisp (C-h i m Emacs Lisp Intro RET), before diving into the manual.

There are also plenty of Emacs Lisp tutorials online, but I’d advise against using them, as most of them have never been updated after originally published and Emacs Lisp keeps evolving all the time (albeit not as fast as I would have liked it to). That being said, Learn Emacs Lisp in 15 minutes is a short and sweet intro to the language. You can find more online educational resources on the EmacsWiki.

Trust me on this - any time invested in learning Emacs Lisp will be time well spent!

Pragmatic Emacs

| Comments

I recently noticed a new blog targeting beginner and intermediate Emacs users - Pragmatic Emacs by Ben Maughan.

If you’re relatively new to Emacs you should definitely check it out. Knowing how vast the Emacs ecosystem is, I’m pretty sure that more experienced Emacs users will also learn a thing or two there.