Emacs Notes

This page is a journal of my experiments with emacs. In November of 2008, I decided to use emacs for all my text editing purposes, after long been convinced of Emacs’s power and utility in editing programs and texts. At this time, I consider myself to be an adequate user of vim, emacs and TextMate. My goal is to teach myself emacs in an auto-didactic manner and make a note of the questions I had and the solutions I found for them. I hope this serves as a reminder for myself on a later date.

Note: All the instructions on this page, unless otherwise noted, are tested on Mac OS X systems and Aquamacs.

Python + Emacs

Install rope, ropemode, pep8 and pyflakes.

$ pip install ropemode pep8 pyflakes

Install yasnippet-bundle and pymacs in emacs:

M-x package-install yasnippet-bundle

References:

Emacs Client on Mac OS X

Here is a nice AppleScript created by Brian McCallister that provides proper emacsclient behaviour. Update: this script launches a “terminal” window, which is an annoyance.

Go to Shortcut


Goto line M-gg. End of the buffer M-x > End of the line C-e Beginning of the line C-a

Editing

Do what Shortcut


zap-to-char (say e) M-z e

Customising emacs

Customizing emacs is done through editing ~/.emacs file. Though, if you are using emacs-starter-kit you will be putting files under emacs.d.

Adding a new key binding.

You can bind any operation that you can do in emacs to a set of key strokes. For example: the emacs-git integration – magit can be invoked by typing M-x magit-status. But, this gets tiring after a while, so you may want to assign a short cut. Short cuts in Emacs start with ‘C-c’. You have to decide what comes after C-c. In this case, I chose magit-status.

Add the following lines to your .emacs file:

;; C-c ms Magit-status
(global-set-key (kbd "C-c ms") 'magit-status)

The first line is the comment (a good practice) and the second line tells emacs to call magit-status when you press C-c ms.

After editing a custom function in .emacs file how do I reload it?

Select the block of code that you want to reload and hit C-x C-e (evaluate). This can also be achieved by positioning the cursor (point in emacs lingo) after the last closing parentheses of the function and typing C-x C-e.

Editing ConTEXt files with Emacs

Install ConTEXt. Install AUCTEX using port (on mac).

$ sudo port install auctex

Active AucTEX by putting this (load "auctex.el" nil t t) in .emacs.

Auto completion.

Install YASnippet to get auto-completion on emacs. To use YASnippet, type in the trigger word and press TAB. For example, typing def and pressing TAB will give you

    def name():
        """
        """

The next tab press allows you replace the default function name with your own, with subsequent tabs taking you to the parameter list, docstring and finally the body of the function

What programming font?

This page has a nice collection of free programming fonts optimized for editing code over long durations of code. The rule of thumb to remember while selecting a programming font is: it should be a fixed width font. This is especially true in languages like “Python”:Python where indentation is essential in understanding the code flow.

I currently use Monaco, a font that is available on Mac OS X set to size 10.

Emacs Muse Notes

Muse tutorial.

Instead of editing the muse-latex.el and muse-book.el files, just use customize on the muse-latex-header and muse-book-latex-header variables. Upgrades to new versions of muse will be much smoother.

Emacs + Git integration

Main entry point M-x magit-status (bound to C-c ms). Go to the magit buffer *magit: PRJNAME* and press tab on the line containing the filenames. The modified text will expand underneath. Press TAB again collapse.

Press g in the magit buffer to refresh git status. or execute M-x magit-status from one of the repository files.

Removing trailing white spaces

The emacs manual defines tells us that setting buffer variable show-trailing-whitespace to t will show trailing white spaces.

(setq show-trailing-whitespace 't)

Paste the above line into the current emacs buffer and evaluate the statement by pressing C-x C-e. Delete the white spaces with M-x delete-trailing-whitespace

Check to see if your emacs configuration is correct.

Source

emacs -q --eval '(condition-case err (progn (load "~/.emacs") (kill-emacs 0)) (error (kill-emacs 1)))'

Shut down emacs gracefully from the command line

emacsclient -n -e '(kill-emacs)'

How to ? Command


Create a Directory from within emacs M-x make-direct ory

Spell M-x ispell check

Undo C-x u or C-_

Describe key C-h k

Describe bindings C-h b

Describe functions C-h f


Emacs Server/Client

See Running emacs as daemon.

Setting up SLIME

Movie showing how to setup slime, swank, sbcl and emacs

Some notes:

check out slime and put it somewhere convenient, ie., $HOME/elisp/slime.

Put the following lines in .sbclrc

(require :asdf)
(push "/Users/pradeep/elisp/slime/" asdf:*central-registry*)

Load swank in sbcl:

$ sbcl
(asdf:oos 'asdf:load-op :swank)
(setf swank:*use-dedicated-output-stream* nil)
(setf swank:*communication-style* :fd-handler)
(swank:create-server :dont-close t)

Installing emacs24

What’s new in emacs 24?

git clone git://git.savannah.gnu.org/emacs.git
cd emacs
sudo apt-get install libxpm-dev
sudo apt-get install libgif-dev
sudo apt-get install libtiff-dev
./configure
make
sudo make install

My initial impression of emacs24 is that it feels much faster compared to the stock emacs-snapshot available on ubuntu maverick.

Interesting modes

Help

Interesting reads

Dotemacs

Distributions

Packages

Information well / emacs people

TODO

Is it possible to show the keybindings in the modeline?

Use case: I have configured ‘Fn’ keys for mode specific actions, but do not remember them, or I want emacs to prompt me to use them.

Starting point: http://www.emacswiki.org/emacs/ModeLineConfiguration

Random tips

CIDER

Journal