2 - Configure Emacs for Clojure


 Clone my basic configuration
You can clone my Emacs Clojure environment repository into your ~/.emacs.d folder to get a working Clojure environment quickly, 
otherwise skip onto creating your own configuration file to see how I have set things up in more detail.

mkdir ~/.emacs.d
git clone https://github.com/jr0cket/Emacs-clojure-kickstart.git ~/.emacs.d
 Get Emacs Live (Sam Aaron)
Get a ready made emacs setup by downloading the zip file or cloning the git repository from:

 http://github.com/overtone/emacs-live




Create your own configuration file
Add the following configuration to your emacs initialisation file ~/.emacs.d/init.el  - create this file if you have a new install and have not yet run emacs.
;; Add Marmalade package archive for Emacs starter kit and other Emacs packages

(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") )
(package-initialize)


;; Add Clojure and other supporting packages to the Emacs environment
;; Packages are installed if they are not already present
;; The list includes packages for the starter kit, Clojure and markdown files (used by github)

(when (not package-archive-contents)
  (package-refresh-contents))

(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-eshell starter-kit-bindings
clojure-mode clojure-test-mode
        rainbow-delimiters
        ac-slime
markdown-mode ))

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))


;; Useful global settings as Emacs is used predominantely for Clojure development

;; Launch the Clojure repl via Leiningen - M-x clojure-jack-in
;; Global shortcut definition to fire up clojure repl and connect to it

(
global-set-key (kbd "C-c C-j") 'clojure-jack-in)


;; Colour mach parens and other structure characters to make code easy to follow

(
global-rainbow-delimiters-mode)

This configuration adds the de-facto Emacs 24 repository, Marmalade, to emacs so you can install new packages via the excellent Emacs package manager.  As with Linux distributions like Ubuntu, the Emacs package manager takes care of package dependencies between the packages you would like to install.

The above configuration defines a list of packages, my packages, which should be installed by default.  If any of those packages are missing, then emacs connects to the Marmalade repository and downloads & installs those packages.  Therefore this script can also be used as an installation script.

Troubleshooting, Conflicts and Warnings
As the marmalade repository if gaining in adoption, there may be a few things packages that dont work well together.  If you have problems with packages not working, you can run emacs in debug mode to get more information.  Run emacs on the command line with the debug option:

emacs --debug-init


Adding auto-completion (work in progress)

Autocompletion uses a visual interface (using the popup emacs package) to show pattern matched words in any Emacs supported language.  To reduce overhead of completion, a statistic method is used for selections.  Autocompetion can also be configured to show documentation and give an "intellisence" experience.

Marmalade repo - no configuration docs, but link to original home page
Original home page

My experience
Installing Autocomplete via the marmalade package is easy but it just does not seem to work.  Errors are show that I do not understand as yet. 

Manually installing auto-compete from the git repository fails a dependency on popup.

Recommended approach
Add popup to the list of packages defined in your ~/.emacs.d/init.el configuration file.

Download (clone) a copy of the auto-complete git repository using a glt client or git on the command line

git clone https://github.com/m2ym/auto-complete.git

Run emacs and manually install auto-complete from using the provided install file

M - x load-file auto-complete/etc/install.el


The manual install of auto-complete sets up the ac-dict folder (something that seems missing from the marmalade package) and all you need to do is add the following lines to
your ~/.emacs.d/init.el configuration file and evaluate the buffer with M - x eval-buffer or just restart emacs.

(add-to-list 'load-path "~/.emacs.d/")
(require 'auto-complete-config)
(ac-config-default)


This is now set up to auto-complete for all languages for which you have a dictionary available.

 Load up a project and give it a whirl.  You should see AC in the status bar of the buffer you have code loaded into.

Emacs auto-complete in status bar of buffer