vim

Setup Clojure Snow Leopard

*****

In 2013 you can now do:

brew install lein. ¬†You can then start a clojure repl by typing ‘lein repl’, to start a project type ‘lein new my-project’.

Don’t waste time reading the rest of this.

*****

 

 

 

Setting up clojure on the mac is fairly simple:
1. use port/homebrew
2. download (svn/git/zip)

If using (2) it is necessary to create a script to startup the REPL or run scripts with *command-line-args*. It’s also a good idea to grab jline to make the REPL a tad more user friendly.

The script used to run clojure, as clj, looks like this:


CLOJURE_HOME=/Users/biomunky/svn/clojure
CLOJURE=$CLOJURE_HOME/clojure/clojure.jar
CONTRIB=$CLOJURE_HOME/clojure-contrib-1.0.0/clojure-contrib.jar
JLINE=$CLOJURE_HOME/jline-0_9_5.jar #if you got it
CP=$PWD:$CLOJURE:$JLINE:$CONTRIB
if [ -f .clojure ];
	then
	CP=$CP:`cat .clojure`
fi

if [ -z "$1" ]; then
	java -server -cp $CP jline.ConsoleRunner clojure.main
else
	java -server -cp $CP clojure.main $*
fi

Add an alias to this script in the .bashrc/.bash_profile

alias clj=/Users/biomunky/svn/clojure/clojure.sh

Source your file and *boom* working clojure.

It’s also nice to have an editor, macvim/vim serves the purpose. First go and grab vim-clojure and copy the files to .vim/. It should look something like this in your .vim/


biomunky@joshua:.vim$ ls *
autoload:
vimclojure.vim

colors:
candycode.vim wombat.vim

doc:
clojure.txt

ftdetect:
clojure.vim scala.vim

ftplugin:
clojure     clojure.vim

indent:
clojure.vim scala.vim

syntax:
clojure.vim scala.vim

Then, to get some nice rainbow parentheses, add the following to the .vimrc file in ~/

syntax on
set title
set ttyfast
set smartindent
set number
" Settings for VimClojure
let g:clj_highlight_builtins=1      " Highlight Clojure's builtins
let g:clj_paren_rainbow=1           " Rainbow parentheses'!
" because light colors on a dark background are easy on the eye
colorscheme wombat

copy and paste the following code into a text file, save it as pdb-fetch.clj and then execute it clj pdb-fetch.clj 1hnn, about 20 seconds later a fasta sequence file will appear in the same directory … woo hoo

(use '[clojure.contrib.duck-streams :only (write-lines read-lines)])
(def pdbid ( .substring (nth *command-line-args* 0) 0 4 ) )
(def url (str  "http://www.pdb.org/pdb/files/fasta.txt?structureIdList=" pdbid ))
(def output (str pdbid ".fasta"))
(write-lines output  (read-lines (java.net.URL. url)))

The output:

>1HNN:B|PDBID|CHAIN|SEQUENCE
MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGDLCNPNGVGPWKLRCLAQTFATGEVSGRTLIDIGS
GPTVYQLLSACSHFEDITMTDFLEVNRQELGRWLQEEPGAFNWSMYSQHACLIEGKGECWQDKERQLRARVKRVLPIDVH
QPQPLGAGSPAPLPADALVSAFCLEAVSPDLASFQRALDHITTLLRPGGHLLLIGALEESWYLAGEARLTVVPVSEEEVR
EALVRSGYKVRDLRTYIMPAHLQTGVDDVKGVFFAWAQKVGL
>1HNN:A|PDBID|CHAIN|SEQUENCE
MSGADRSPNAGAAPDSAPGQAAVASAYQRFEPRAYLRNNYAPPRGDLCNPNGVGPWKLRCLAQTFATGEVSGRTLIDIGS
GPTVYQLLSACSHFEDITMTDFLEVNRQELGRWLQEEPGAFNWSMYSQHACLIEGKGECWQDKERQLRARVKRVLPIDVH
QPQPLGAGSPAPLPADALVSAFCLEAVSPDLASFQRALDHITTLLRPGGHLLLIGALEESWYLAGEARLTVVPVSEEEVR
EALVRSGYKVRDLRTYIMPAHLQTGVDDVKGVFFAWAQKVGL

the above code (probably) isn’t idiomatic, this is a learning experience – feel free to complain/suggest changes/fixes.