My Emacs configuration file is getting close to loading one-hundred packages. I download most of them from MELPA, which in my opinion is the best source for libraries or packages you want to mold Emacs for your needs. Once per week I read through MELPA’s Twitter feed and download anything that seems remotely useful—I have so many sub-directories in /home/eric/.emacs/lisp
….
Today I want to tell you about my favorite packages from the large number that I am currently using or have used in the past. I hope you find something useful as a result. Now, let the mini-endorsements begin!
use-package
Last year I rewrote my .emacs
file and replaced almost all of my require
expressions with use-package. I actually blogged about it at the time so I am not going to repeat myself here. Except to say that use-package has proven to be a fantastic way to keep my configuration feeling clean and organized. If your .emacs
feels cluttered then you need to check out use-package, or req-package if you have a lot of dependencies between packages.
Expand Region
In the course of all the programming I do, I often want to select regions such as everything in a string, the index of an array, the body of an Emacs Lisp expression, et cetera. Expand Region makes these selections easy. Take a look at the command in action.
The author Magnar Sveen—creator of many great packages—also offers Change Inner, an implementation of the ci
(change inner) and co
(change outer) commands from Vim, built on top of Expand Region. I often use these in programming. For example, with change-inner
bound to M-i
, I can kill the contents of a string at point by simply pressing M-i "
. If I used M-o
instead, which I bind to change-outer
, then it would kill the quotes as well. These commands are convenient for any kind of document where you are editing content between delimiters.
Anchored Transpose
Have you ever wanted to swap two regions? One way to do it would be to kill the first region, yank it at the position of the second, then kill the second and jump back to the first position to yank it. Or use the easier Anchored Transpose command. This command is great for swapping the order of parameters in code or exchanging two sentences around a comma or semicolon—things like that. It allows you to select the anchor first, e.g. the comma, and then phrase to transpose; or you can select the two regions independently and then transpose them. The command is aware of any overlap between the two regions and will Do the Right Thing.
Flycheck
GNU Emacs comes with Flymake to perform on-the-fly syntax checking. Flycheck is a replacement with support for more languages, at this time of writing:
- AsciiDoc
- C/C++
- CFEngine
- Chef
- Coffeescript
- CSS
- D
- Elixir
- Emacs Lisp
- Erlang
- ERuby
- Go
- Haml
- Handlebars
- Haskell
- HTML
- Javascript
- JSON
- LESS
- Lua
- Make
- Perl
- PHP
- Puppet
- Python
- Racket
- ReStructuredText
- Ruby
- Rust
- Sass
- Scala
- Scss
- Shell script languages
- Slim
- TeX/LaTeX
- Texinfo
- Verilog
- XML
- YAML
Whew.
If you need support for a language not part of the above then you can use Flycheck’s API to extend it. Flycheck comes with a set of functions to parse the output of lint programs so that you can define a new syntax checker with code as simple as this:
(flycheck-define-checker php-phpcs
"A PHP syntax checker using PHP_CodeSniffer.
See URL `http://pear.php.net/package/PHP_CodeSniffer/'."
:command ("phpcs" "--report=checkstyle" source)
:error-parser flycheck-parse-checkstyle
:modes php-mode)
(add-to-list 'flycheck-checkers 'php-phpcs)
Flycheck has helped me find countless errors in my work sooner rather than later, and I daresay the package is mandatory for any computer programmer. Flycheck is that useful.
Org Mode
I know more than one person who uses Emacs solely for the purpose of using Org Mode. It’s a comprehensive suite of tools for planning todo lists, tracking your time on tasks, organizing notes—no one demonstrates the usefulness of Org Mode like Sacha Chua. In my opinion her blog is the best place to see every way you can use Org Mode to organize everything you do.
God Mode
Tired of holding Control and/or Alt when executing a series of commands? Then turn God Mode on to get rid of the need for those modifiers. Consider this example of key presses from the project’s GitHub page:
Before: C-p C-k C-n M-^ ) C-j C-y M-r C-x z z M-2 C-g C-g C-x C-s
After: p k n g ^ ) j y g r . . 2 g g x s
I know this will sound like heresy to some, but God Mode gives you a level of convenience similar to the command mode of Vim. I realize that is the editor of “The Enemy,” but if we’re being honest then we have to admit that Vim has useful features, like the aforementioned Change Inner/Outer. Personally, I found it easy to adopt the mind-set of no longer holding modifier keys when I need to execute a of key-presses. We all know about “Emacs Pinky.” God Mode is a convenient way to reduce that strain.
Conclusion
Once again, I hope you improve your Emacs workflow by using one or more of the packages described above. If you have any questions about packages for specific purposes, like programming languages, feel free to leave a comment for suggestions. And also please suggest packages that you consider crucial benefits to the way you use Emacs.
I tried out god-mode, but immediately ran into a problem: I can’t set mark then move to mark a region. For example, I would expect a [space] e to mark the current line, but it doesn’t. I also tried a @ e, thinking that the special treatment of the space key was the problem, but still no joy. How do you deal with marking a region in god-mode? It’s obviously a major defect with it in my humble, etc.
You may want to report that as a bug. I add no configurations of my own to God Mode, and Space works for me for marking regions, e.g. your example of
a [Space] e
marks a line. The same is true for@
.