Starting Off With Emacs - package.el, Org-mode, Aspell and Markdown-mode

Sun 04 December 2011

The background

The past couple of days I’ve been reading up about Org-mode, an Emacs “Mode” or environment that uses plain-text for efficient note creation, time management and authoring. There’s an extensive listing of tutorials/screencasts on their website as well as other resources that gives an indication of how extensible and powerful this environment can be.

The main reason I was attracted to Org-mode was that it seemed to fit in quite well with the requirements of a productivity approach that I’ve been meaning to try out for quite sometime. The idea was to use one program as far as possible to do my daily tasks:

  • Create and track to-dos
  • Create and track my calendar
  • Read, respond and track emails and email-based tasks
  • Write content and export it to my main document types
    • Markdown
    • Word
    • PDF

The reason I want to try this approach is that I feel a lot of time and cognitive up-shifting and down-shifting was taking place by using a multitude of programs for work1. I’m currently using NVAlt for notes, Mac Mail and Gmail, iCal for appointments and calendaring, TextWrangler and Microsoft Word for writing and document exporting.

I was also quite attracted to the fact that working in a text-based environment could help in reducing my propensity to chase cars on the Internet and end up in this very common situation for me. The final reason was a little bit of nostalgia. I thought it’d be cool to revive the 16-year old geek in me, who used to install Slackware Linux off of PC Quest CDs and tinker around and crash the computer on a weekly basis.

Well, nuff said.

Installing Emacs

The first step was to get down to it and get Emacs. At this point, I had two choices in front of me - go for the prettyified Mac-friendly version known as Aquamacs or a pre-packaged “clean” version of Emacs for Mac OS X. I chose to go with the latter option purely as I wanted a pure text-based interface. I also wanted to ensure that the Emacs I would use would be as close as possible to the original distribution, to avoid errors and configuration issues with add-ons and the like.

Installing package.el

The next step was to get Org-mode. Now, there is an older version that comes integrated with the Emacs download. To upgrade, I had the option of either downloading a tar package from their website or using an Emacs package manager known as package.el, to take care of the installation for me. I chose to go with the latter option, as it would make trivial, updates and installation of new packages in the future2.

Installation is simple - download the package.el file and put it into your local Emacs load path. You can set this by adding the following to your .emacs initialization file:

1 setq load-path (cons "~/xyz" load-path))

where xyz is the directory in which you want to store your emacs libraries and files.

Then add the following to your .emacs file. The practice is to append these to the end of your .emacs file to ensure that they override any other automated configuration changes that could have been made by other packages:

1 (require 'package)
2 (add-to-list 'package-archives
3     '("marmalade" .
4     "http://marmalade-repo.org/packages/") t)
5 (package-initialize)

Installing Org-mode

Once your package.el is installed, fire up Emacs and run M-x package-refresh-contents which will update the package list. Then hit M-x package-install RET and org RET and then package.el will be off and running, downloading the tarball from the website and doing an automatic compile and install.

The next step is to setup the .emacs file for Org-mode. Now, there are many many customizations that can be done to Org-mode as can be seen here. As a newbie user, I wanted to keep it very simple and add features one-by-one. The basic features I wanted to add were: * All .org files would be opened by Emacs in Org-mode directly * Org-mode would use a clean, indented mode for lists * Org-mode would have automatic spell checking throughout

Enabling these features, required me to add the following lines to my .emacs file and then we’re nearly there to using Org-mode:

1 ;; All .org files will be opened automatically in org-mode
2   (add-to-list 'auto-mode-alist '("\\.org\\ '" . org-mode))
3   ;; We switch on spell check in org-mode using flyspell
4   (add-hook 'org-mode-hook 'turn-on-flyspell 'append)
5   ;; We start org-mode in indented mode
6   (setq org-startup-indented t)

Installing Aspell

Now you would have seen above that I added in a spell-check function called Flyspell. This is not loaded with Emacs so if you run it, you will get an error. What needs to be done now is to get the program from the Flyspell website, and copy flyspell.el into your Emacs load path.

The next step is to add the following line into your .emacs file

1 ;; Loading flyspell for automatic spell check and correction
2    (autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)

Are we there yet? Not quite.

Flyspell is actually a wrapper around a program called ispell - which does the actual spell-checking.Now, ispell is a pretty old program and there are newer ones such as Aspell and Hunspell that have better spell-check algorithms and dictionaries in place. I chose to go with the former as the installation seemed to be much simpler.

On my Mac (with MacPorts up and running), installing Aspell just required a simple sudo port install aspell. Installing the English dictionary file was just as simple with sudo port install aspell-dict-en. The final step is configure Flyspell to use Aspell in place of ispell. That requires the following lines to be inserted into your .emacs file:

1 ;; Set Aspell as the spell-checker in place of ispell
2   (setq ispell-program-name "/opt/local/bin/aspell")
3   (setq ispell-list-command "list")
4   (setq ispell-extra-args '("--sug-mode=fast"))

Your on-the-fly spell-check should be up and running in Org-mode now!

Installing markdown-mode

As I am trying to use MultiMarkDown as far as possible in my writing workflow - especially by using NVAlt, I wanted to use its markup in Emacs as well. To do this, meant I had to install the markdown-mode package. If you’re package.el is up and running, just hit M-x package-install RET and markdown RET. In a minute or so, the package will be installed.

The next step is to install MultiMarkDown. Download the appropriate packager from here and let the automatic install run its course.

Are we there yet? Not quite.

The markdown-mode package is configured to use markdown as its processor and not multimarkdown. Adding the following line to your .emacs file will tell the program to use the mmd executable instead of the markdown program name that markdown-mode expects.

'(markdown-command "/usr/local/bin/mmd"))

The final setup we need to do now is to associate .markdown files with the markdown-mode so that Emacs automatically loads these files. Finally, as we did for Org-mode, we want to setup automatic spell-checking in markdown files that we’re working on. The following lines in your .emacs file will set this up:

1 ;; We initialize markdown-mode for .markdown files
2   (add-to-list 'auto-mode-alist '("\\.markdown" . markdown-mode))
3   ;; We switch on flyspell checking for markdown-mode
4   (add-hook 'markdown-mode-hook 'turn-on-flyspell 'append)

That’s it. We’re all set!

Ending thoughts

Now that I’ve setup the environment, it’s time to get to work! Or is it? I’m already being distracted by the prospect of inching closer to my ideal work environment by using gnus to access email from within Emacs and even better, link it to Org-mode allowing me to convert emails directly into todos!

As a beginner to Emacs, I find the following resources to be extremely useful in getting my head around this amazingly vast program:

Btw, this is my first post using Octopress!


  1. My hope is also that using a text-based environment will reduce my usage of browsers and stop my impulsive behavior of chasing cars on the Internet 

  2. Read Phil Hagelberg’s post on adding the Marmalade repository to package.el over and above ELPA, increasing the number of Emacs packages available for installation 

Category: Computing

comments


MobileMe = Apple+GMail

Fri 05 September 2008

When I bought my first laptop, a 12" Powerbook G4 (still chugging along nicely), I was asked by the salesman if I wanted a .Mac subscription also. Hmmm, while the vanity of having a @mac.com address was attractive, paying $99 annually for it was not. Irrespective of the free ...

Category: Computing

comments

Read More
Page 1 of 1