This is my personal Emacs configuration. This is the second repository
I clone -- after my dotfiles --
when settling in on a new computer . I'm using
package.el and Emacs
24 themes, so this requires at least Emacs 24.3!
To use it, clone it into your home directory, or at least wherever
Emacs thinks your home directory is. Move your existing
out of the way, since it being there prevents Emacs from using the
init.el in this repository. I do still use a
.emacs file for
system-specific configuration, but I put this at the top,
If you did everything right Emacs should simply launch with no errors. You will be greeted with a featureless, empty gray box awaiting your instructions.
I try to keep my Emacs configuration tight and tidy. I generally spend somewhere between 30-60 hours a week in front of Emacs, so this configuration has been carefully pieced together and every line is important.
Here's a list of some small features added by
- M- -- Move the current line up.
- M- -- Move the current line down.
- C-x ! -- Insert a UUID.
- C-x ~ -- Set the current buffer to 80 columns.
- C-c r -- Insert random number.
- C-c e -- Eval and replace.
- M-g -- Go to line.
- C-x C-k -- Compile.
- [f1] -- Start a terminal.
- [f2] -- Revert the buffer, no questions asked.
- [pause] -- Dedicate the current window to the current buffer.
And some of the more interesting functions/macros, especially if you're an Elisp developer,
That last one is used to create bindings to run
make with the
compile target and C-x C
make with the
There's a customized hook for
before-save-hook. It will remove all trailing whitespace, and,
because I'm so picky, also convert all tabs to spaces just before
saving a buffer. To disable this on a per-buffer basis -- for example,
to precisely edit a sloppily-spaced file -- run
whitespace-cleanup.el for all the details.
Something experienced Emacs users may notice at first is that I make
heavy use of
ido-mode. It's turned on with flex matching, I've got
smex loaded to complete M-x commands, and I use it for
picking Java documentation. It's a wonderful feature and every Emacs
user should be using it.
To interact with Git repositories, I use Magit (pronounced like "magic"). You can run it at any time with C-x g. As the manual points out, Magit is not a complete interface for Git, nor should it be. It covers 95% of my Git use, with the other 5% directly with Git on the command line. Magit is one of the main reasons I use Git.
This configuration includes a built-in web server, written by me. You
can launch it with
httpd-start and stop it with
will serve files from the directory at
httpd-root and log messages
in s-expression form to the
The most important use of the web server is for
skewer-mode. I run its
associated userscript in my browser allowing me to, at any time on
any page, attach Emacs to a webpage. Once attached to Emacs I can
skewer-repl) and live expression evaluation in
modes. It can also do live "evaluation" of CSS (
Paredit is a very significant behavioral change for Lisp modes. It enforces parenthesis balance and provides all sorts of shortcuts for manipulating entire s-expressions at once. It may feel annoying at first, but it quickly becomes indispensable. Keep looking at the cheatsheet until you've got the hang of it.
I also have parenface configured, which darkens the parenthesis in
Lisp modes. It makes Lisp code all the more pleasing to look at --
reading Lisp is all about indentation, not parenthesis. It won't be
enabled in the
*scratch* buffer automatically because that buffer
gets set up before parenface does.
You may wonder why I don't have
Slime here. That's because I
let Quicklisp install and manage it for
me. Remember my note about using
.emacs for system-specific
configuration? That's where I put the hook to load Slime.
This was one of the big ones when I used spend a lot of time writing
Java, and Emacs was lacking solid Java support. I built up my own
extensions to support Java development:
javadoc-lookup. The full documentation is listed in the
but here's a quick rundown of my configuration.
First, I use javadoc-lookup for class completion and lookup, which works by examining the file structure of Javadoc documentation. While it comes with the core API Javadoc built-in, to make more effective use of it I need to tell it about what other things I'll want to look up. Its configuration looks like this,
(javadoc-add-artifacts [org.lwjgl.lwjgl lwjgl "2.8.2"] [com.nullprogram native-guide "0.2"] [joda-time joda-time "2.1"])
I can jump to any class's documentation with C-h j. I use Firefox, so this will try to open the documentation in Firefox if possible.
ant-project-modeis not currently part of this configuration, so the following will not work at the moment.
Next, when in a
java-mode buffer, I can add an import to the imports
section at any time with C-x I (the
ant-project-short-keybindings binding). Like
C-h j, Ido will do a completing read asking you which class
I'd like to import. It's inserted in the proper position inside the
When using Ant like I do, there are a number of bindings that trigger specific Ant targets. The three I use most often are,
- C-x c -- Compile the program.
- C-x r -- Run the program.
- C-x t -- Run the unit tests.
The compilation buffer name is derived from the prefix argument. Using prefixes (C-u number), you can run any number of compilation processes at once. I find this especially useful for hot code replacement.
The YASnippets in
emacs-java/snippets/ take advantage of my
java-mode extensions. My favorite snippet is
cls ("class"): start
a fresh Java source file inside a package, type
cls, and hit tab. It
will attempt to guess the package name from your path and fill out the
basics with it, allowing you to quickly get on with your business.