My Favourite Emacs Packages

After a few years doing my PhD I’ve settled on Emacs as my main editor. This is mainly because it is incredibly powerful and extendable, there are thousands of free packages available to use and everything can be tweaked exactly the way I want.

The price to pay for this freedom is a fairly steep learning curve and the need to get familiar with Emacs Lisp (for customizing packages). However Emacs has been around since 1976 and is still under active development so it must have something going for it!

In this post I’ve described some of what I consider the most useful packages to get started with Emacs. For a guide on how to install Emacs packages in the latest version see this page.

AucTeX and RefTeX mode

If you write LaTeX documents these two packages are absolutely essential! Together they simplify the creation of environments, referencing from a BibTeX database and compilation of your document into a few small keystrokes. For me the most useful feature is the reference list: type “C-c )” and Emacs brings up an outline of all the labelled equations, theorems and algorithms etc. in your document to choose from. There’s far too much for me to cover here but there is are some tutorials here and here to get started.

Note: to get AucTeX and RefTeX working together you will need to add the following to your .emacs file.


(add-hook 'LaTeX-mode-hook 'turn-on-reftex)

Org-mode

Org-mode useful making any kind of structured document whether that be a simple list or a blog (I write this blog using the org2blog plugin). You can even use it as a simple spreadsheet and calendar!

There are lots of links and tutorials describing org-mode on their website.

Python mode

Recently I’ve started some Python development and Emacs proved to be a great editor for that. Some of my previous blog posts here and here describe the setup I’m currently using.

Flymake mode

This mode provides real time syntax and spell checking, highlighting the offending lines in red for easy visualization. Below is my setup for using flymake with LaTeX and Python, just copy them into your .emacs file. The Python setup forces flymake to use the PEP8 coding standard.


;; FLYMAKE FOR LATEX
(add-hook 'LaTeX-mode-hook
        (lambda ()
                (setq flymake-allowed-file-name-masks
                    (delete '("[0-9]+\\.tex\\'"
                         flymake-master-tex-init
                         flymake-master-cleanup)
                         flymake-allowed-file-name-masks));NO multipart files
                (defun flymake-get-tex-args (file-name)
                        (list "pdflatex" (list "-file-line-error" "-draftmode"
                        "-interaction=nonstopmode" file-name)))
                (unless (eq buffer-file-name nil) (flymake-mode 1))
                (local-set-key [f2] 'flymake-goto-prev-error)
                (local-set-key [f3] 'flymake-goto-next-error)
        ))

;; FLYMAKE FOR PYTHON
(add-hook 'python-mode-hook
        (lambda ()
                (unless (eq buffer-file-name nil) (flymake-mode 1))
                (local-set-key [f2] 'flymake-goto-prev-error)
                (local-set-key [f3] 'flymake-goto-next-error)
        ))
(when (load "flymake" t)
        (defun flymake-pylint-init ()
                (let* ((temp-file (flymake-init-create-temp-buffer-copy
                        'flymake-create-temp-inplace))
                (local-file (file-relative-name
                        temp-file
                        (file-name-directory buffer-file-name))))
                (list "pep8" (list "--repeat" local-file))))
        (add-to-list 'flymake-allowed-file-name-masks
                '("\\.py\\'" flymake-pylint-init)))
(defun my-flymake-show-help ()
        (when (get-char-property (point) 'flymake-overlay)
                (let ((help (get-char-property (point) 'help-echo)))
                        (if help (message "%s" help)))))
(add-hook 'post-command-hook 'my-flymake-show-help)

This setup makes F2 and F3 go to the previous and next errors respectively.

VC-mode

If you’re using any kind of version control system then VC-mode is great. Whether the underlying system uses Git or SVN etc. VC-mode uses the same key bindings for all of them, making it easy to switch between systems.

There’s a list of all the key bindings here.

hl-p mode

The final mode on my list is hl-p mode which highlights parenthesis surrounding the current cursor position. I find this one especially useful when writing complicated LaTeX expressions which need lots of brackets.

Unfortunately the default colours didn’t stand out well on my black background but you can change them to any RGB colour! I found “firebrick1”, “yellow1”, “lawn green” and “MediumPurple1” stand out nicely for me.

Let me know in the comments if I missed out any other useful modes!

Advertisements

5 thoughts on “My Favourite Emacs Packages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s