Emacs Redux

Return to the Essence of Text Editing

Quickly Open an Info Manual

| Comments

Every Emacs user knows that Emacs ships with plenty of built-in documentation in the GNU info format (they don’t call it a self-documenting editor for no reason). Most Emacs users know how to access that built-in documentation with C-h i (M-x info) and some Emacs users even know that the Emacs manual can be opened directly with C-h r (M-x info-emacs-manual).

If you know the name of the manual you’re looking for, however, there’s a nice little-known alternative to using C-h i - the info-display-manual command. When you run it you’ll be prompted in the minibuffer for the name of the manual you’d like to view (manual name completion is available).

To give you a more concrete example of the command’s advantage over info let’s try to open the Emacs Lisp manual with both commands. With info you’ll have to type the following:

1
M-x info RET m elisp RET

And the alternative would be:

1
M-x info-emacs-manual RET elisp RET

If you like the command I’d suggest binding it to some keybinding:

1
(define-key 'help-command (kbd "C-i") 'info-display-manual)

Emacs Lisp Style Guide

| Comments

I’ve started working on a community Emacs Lisp style guide. My goal is to create a comprehensive document similar to the Clojure and Ruby community style guides.

Such a document would be a great starting point for many newcomers to the Emacs community and should increase the overall quality of the code produced by it. There’s much to be documented about code layout, preferred syntactic conventions, major and minor mode definitions, etc. and I obviously can’t know the best practices about everything so I’ll need a lot of help.

Of course, we already have the official coding guidelines, but they are a bit light on examples, rationale, etc. Hopefully the community style guide will manage to fill any gaps in them and in good time portions of it will find their place in the official documentation.

I’m inviting all members of our community interested in promoting good Emacs Lisp practices to join the development of this document!

A Peek at Emacs 24.4: Superword-mode

| Comments

In a previous post I wrote about camel-case aware editing with subword-mode. Emacs 24.4 adds a complementary minor mode called superword-mode, which also alters the behavior of word-based commands when enabled.

Normally Emacs would consider underscores and dashes word separators (snake_case and lisp-case anyone?). This affects all word commands - forward-word, backward-word, kill-word, etc. Let’s see a couple of examples (| denotes the cursor position):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;; word with dash
|some-word

;; press M-f (forward-word) once
some|-word

;; press M-f again
some-word|

;; press M-b (backward-word) once
some-|word

;; word with underscore
|some_word

;; press M-f once
some|_word

;; press M-f again
some_word|

;; press M-b once
some_|word

;; word in camelCase (assuming subword-mode is not enabled)
|someWord

;; press M-f once
someWord|

;; word in camelCase (assuming subword-mode is enabled)
|someWord

;; press M-f once
some|Word

Personally I find the default behavior combined with subword-mode great. I do a lot of Ruby and Lisp programming and it also makes a lot of sense to me to be able to navigate the portions of a complex word, but I guess not everyone feels this way. Enter superword-mode - when it’s enabled all “complex/compound” words are treated as a single word:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
;; word with dash
|some-word

;; press M-f once
some-word|

;; word with underscore
|some_word

;; press M-f once
some_word|

;; word in camelCase
|someWord

;; press M-f once
someWord|

Note that you cannot have subword-mode and superword-mode enabled at the same time. Turning one of them on will disable the other.

Personally, I don’t see much value in superword-mode as a mode that’s enabled all the time, but I can imagine some useful scenarios in which I’d enable it briefly to do some focused editing.

A Peek at Emacs 24.4: Prettify-symbols-mode

| Comments

Emacs 24.4 ships with a new minor mode called prettify-symbols-mode. Its purpose is to replace the standard text representation of various identifiers/symbols with a (arguably) more aesthetically pleasing representation (often a single unicode character would replace several ascii characters).

A classic example would be lambda from various Lisp dialects that many people prefer to replace with the greek letter λ (small lambda). prettify-symbols-mode allows you to achieve this by relying on a simple mapping expressed in the form of an alist that each major mode must initialize (prettify-symbols-alist). Simply put - major modes have to provide the configuration for prettify-symbols-mode.

Lisp modes do this via lisp--prettify-symbols-alist:

1
2
(defconst lisp--prettify-symbols-alist
  '(("lambda"  . ?λ)))

This means that out of the box only lambda will get replaced. You can, of course, add more mappings for different major modes:

1
2
3
(add-hook 'emacs-lisp-mode-hook
            (lambda ()
              (push '(">=" . ?) prettify-symbols-alist)))

Let’s see the mode in action. Consider this bit of Emacs Lisp code:

1
2
3
4
(lambda (x y)
  (if (>= x y)
      (something)
      (something-else)))

After you do M-x prettify-symbols-mode you’ll end up with:

1
2
3
4
(λ (x y)
  (if ( x y)
      (something)
    (something-else)))

To enable this for a particular mode use (add-hook 'some-mode-hook 'prettify-symbols-mode). If you’d like to enable it globally just add the following to your config:

1
(global-prettify-symbols-mode +1)

By the way, sky is the limit for symbol prettification. One fairly extreme example would be vim’s plugin haskell-conceal+ that goes to great lengths to bring proper mathematical notation to Haskell code. We can achieve more or less the same effect with prettify-symbols-mode, but one have to ask themselves where should we draw the border between tasteful and distasteful prettifications.

Configure the Scratch Buffer’s Mode

| Comments

Pretty much every Emacs user knows of the *scratch* buffer - after all it’s always present when you start your Emacs. If you’ve set inhibit-startup-screen to t (which I recommend) it will even be the very first buffer see each time you fire up your beloved editor (unless you alter initial-buffer-choice, that is).

The scratch buffer was conceived a scratchpad for notes and Emacs Lisp experiments and a lot of Emacs users find it quite handy. On the other hand - even more users don’t really write Emacs Lisp and probably find little value in this buffer.

One little know fact about the *scratch* buffer is that its initial major mode (by default it’s lisp-interaction-mode) is not hardcoded and you can alter it. If you’re a Ruby developer you might opt to make it use ruby-mode by default:

1
(setq initial-major-mode 'ruby-mode)

If you do this I’d also advise you to change the buffer’s initial contents. By default they are:

1
2
3
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

For Ruby something like this might be better:

1
2
3
4
(setq initial-scratch-message "\
# This buffer is for notes you don't want to save, and for Ruby code.
# If you want to create a file, visit that file with C-x C-f,
# then enter the text in that file's own buffer.")

Or you can simply set initial-scratch-message to nil and be done with it.

Travel Back and Forward in Git History

| Comments

I recently discovered an extremely cool package called git-timemachine that allows you to step though the git history of the file you’re currently editing in Emacs.

Using it is pretty simple:

  • visit a git-controlled file and issue M-x git-timemachine (or bind it to a keybinding of your choice)
  • use the following keys to navigate historic version of the file:
    • p visit previous historic version
    • n visit next historic version
    • w copy the hash of the current historic version
    • q exit the time machine buffer

Here you can see git-timemachine in action:

P.S.

This package is bundled with Prelude.

Become an Emacs Redux Patron

| Comments

Securing funding for OS projects and blogs (outside of displaying annoying ads) is a hard endeavor. While I’d love to raise enough cash to work on CIDER, projectile and Emacs itself for an entire year through some wildly successful crowdfunding campaign, that’s unlikely to ever happen.

That said, I recently discovered an interesting alternative to one-off crowdfunding campaigns called gratipay. Self-described as sustainable crowdfunding (meaning people will get microdonations (say half a buck) from their patrons each week) it seems like a reasonable way to raise a modest sum of money so you could work on open-source projects more than your regular schedule might permit.

So, if you like Emacs Redux and the Emacs projects in which I’m involved like:

  • Prelude - An Emacs distribution built on top of GNU Emacs 24
  • Projectile - Project Interaction Library for Emacs, that stays out of your way
  • clojure-mode - A major mode for programming in Clojure
  • cider - A Clojure programming environment for Emacs
  • guru-mode - An annoying companion on your journey to Emacs mastery
  • rubocop-emacs - Emacs integration for RuboCop
  • zenburn-emacs - The Zenburn color theme, ported to Emacs
  • solarized-emacs - The Solarized color theme, ported to Emacs
  • puppet-mode - A mode for editing Puppet 3 manifests
  • swift-mode - A mode for editing Swift code

consider supporting my work via Gratipay.

Support via Gratipay

P.S.

Alternatively you can use PayPal.

Paypal

New Emacs Blogs

| Comments

The problem with Emacs blogs is one can never have enough of them (especially the good ones).

I’d like to draw my readers attention to two new blogs:

lunarsite

lunarsite is not exactly new (it was started in March 2014), but I don’t think enough people have come across it, so I’m mentioning it here anyway. It’s operated by one of the most prolific members of the Emacs community in recent years - the great Sebastian Wiesner (of flycheck and cask fame).

If you’re thinking of writing your first major mode - you’ll find some great advice there.

Endless Parentheses

Endless Parentheses is a brand new blog started by Arthur Malabarba. It’s dedicated to concise posts on improving your Emacs productivity.

The content so far is similar to the articles I write here, so if you like Emacs Redux you’ll likely enjoy Endless Parentheses as well.