Clojure is at the end of the day Java. Whether you love it or hate it, Maven is here to stay for java builds. Here is a very good article by learningclojure.com on how to get Clojure REPL or Swank Clojure up and running in seconds with a simple Maven pom.xml file. Also, If you've wondered what goes on beneath leiningen, this is a good place to start:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html
Now, starting a REPL is as simple as:
$ mvn clojure:repl
Starting Swank server for Emacs is as simple as:
$ mvn clojure:swank
Friday, May 20, 2011
Saturday, May 14, 2011
Scheme in Emacs
If you're reading SICP or Little Schemer or any Scheme book and find MIT Scheme REPL not too comfortable, here is a brief guide to start hacking Scheme in Emacs:
1. Install MIT Scheme (using your platform's package manager)
$ sudo apt-get install mit-scheme
2. Emacs comes with inbuilt support for Lisp/Scheme. Open Scheme source file (*.ss or *.scm) for Scheme major mode to kick in.
3. M-x run-scheme
This will start MIT Scheme REPL in inferior-mode in a buffer.
4. With the REPL open, Open another buffer for your Scheme source code (using C-x 2 or C-x 3)
5. Now you can directly eval code from your buffer. Just move cursor to the end of any expression (C-e) and evaluate it using C-x C-e
1. Install MIT Scheme (using your platform's package manager)
$ sudo apt-get install mit-scheme
2. Emacs comes with inbuilt support for Lisp/Scheme. Open Scheme source file (*.ss or *.scm) for Scheme major mode to kick in.
3. M-x run-scheme
This will start MIT Scheme REPL in inferior-mode in a buffer.
4. With the REPL open, Open another buffer for your Scheme source code (using C-x 2 or C-x 3)
5. Now you can directly eval code from your buffer. Just move cursor to the end of any expression (C-e) and evaluate it using C-x C-e
Thursday, May 5, 2011
Clojure in Emacs
This is a brief guide to setting up and hacking Clojure in Emacs.
1. Install Emacs.
Install Emacs23 if you're on a Linux and Carbon Emacs if you're on OSX. Aquamacs is discouraged due to issues with Emacs starter kit.
2. Tutorial
Take an hour and work through the tutorial to get comfortable with Emacs shortcuts. It'll be the most productive hour you ever invested. Grab a cheatsheet and get used to it by coding away in your favorite language.
3. Get the Emacs starter kit. It comes with major/minor modes for most languages.
If you're on OSX, Grab this version by topfunky for Carbon Emacs:
https://github.com/topfunky/emacs-starter-kit
If you're on Linux, clone it from the original fork here by technomancy:
https://github.com/technomancy/emacs-starter-kit
After cloning the started kit, make it your ~/.emacs.d/ folder
4. Install Emacs packages for Clojure
4.1 M-x package-list-packages
to list available packages
(If this doesn't work, your Emacs starter kit isn't working)
4.2 Select the following packages by pressing I to mark for installation
clojure-mode
clojure-test-mode
slime
slime-repl
4.3 Press X to install selected packages
5. Inferior mode, SLIME and SWANK
A small digression on Inferior mode, Superior mode and Swank.
Emacs is a text editor which can be extended using EmacsLisp.
Inferior mode is how you eval snippet of code directly from editor in a Lisp (configured in inferior-lisp-program by the major mode you currently are in).
SLIME or Superior Lisp Interaction mode for Emacs is how you start a REPL in Emacs.
Emacs being just a text editor can't really eval Lisp code unless it's Emacs lisp. The way inferior mode and superior mode really work is through Swank which is sort of a REPL server to which Emacs connects.
5.1 To eval an expression in inferior-mode, just move to the end of a Clojure expression and press C-x C-e.
5.2 To start Swank server for Clojure REPL, you need to install Swank-Clojure:
5.2.1 Install Leiningen (https://github.com/technomancy/leiningen)
Leiningen is a build tool for Clojure. Leiningen can be used to install Swank clojure as a plugin and start the Swank server for Emacs
To install Lein, Download the script, make it executable and run it
$ wget https://github.com/technomancy/leiningen/raw/stable/bin/lein
$ sudo cp lein /usr/bin
$ sudo chmod +x /usr/bin/lein
$ lein
5.2.2 Install Swank clojure (https://github.com/technomancy/swank-clojure)
After installing Lein, Install Swank clojure as a plugin:
$ lein plugin install swank-clojure 1.3.0
Lein installs plugins in ~/.lein/bin. swank-clojure startup script is created there.
Add ~/.lein/bin to your path
5.2.3 Start Swank server and connect from Emacs
$ swank-clojure
starts Swank server for Clojure REPL
Start Clojure REPL in Emacs by connecting to Swank server. Accept defaults for host and port
M-x slime-connect
Now ogle at the most elegant editor you'll ever see and hack away in the most elegant language you'll ever write code in.
(Reference: http://technomancy.us/126)
1. Install Emacs.
Install Emacs23 if you're on a Linux and Carbon Emacs if you're on OSX. Aquamacs is discouraged due to issues with Emacs starter kit.
2. Tutorial
Take an hour and work through the tutorial to get comfortable with Emacs shortcuts. It'll be the most productive hour you ever invested. Grab a cheatsheet and get used to it by coding away in your favorite language.
3. Get the Emacs starter kit. It comes with major/minor modes for most languages.
If you're on OSX, Grab this version by topfunky for Carbon Emacs:
https://github.com/topfunky/emacs-starter-kit
If you're on Linux, clone it from the original fork here by technomancy:
https://github.com/technomancy/emacs-starter-kit
After cloning the started kit, make it your ~/.emacs.d/ folder
4. Install Emacs packages for Clojure
4.1 M-x package-list-packages
to list available packages
(If this doesn't work, your Emacs starter kit isn't working)
4.2 Select the following packages by pressing I to mark for installation
clojure-mode
clojure-test-mode
slime
slime-repl
4.3 Press X to install selected packages
5. Inferior mode, SLIME and SWANK
A small digression on Inferior mode, Superior mode and Swank.
Emacs is a text editor which can be extended using EmacsLisp.
Inferior mode is how you eval snippet of code directly from editor in a Lisp (configured in inferior-lisp-program by the major mode you currently are in).
SLIME or Superior Lisp Interaction mode for Emacs is how you start a REPL in Emacs.
Emacs being just a text editor can't really eval Lisp code unless it's Emacs lisp. The way inferior mode and superior mode really work is through Swank which is sort of a REPL server to which Emacs connects.
5.1 To eval an expression in inferior-mode, just move to the end of a Clojure expression and press C-x C-e.
5.2 To start Swank server for Clojure REPL, you need to install Swank-Clojure:
5.2.1 Install Leiningen (https://github.com/technomancy/leiningen)
Leiningen is a build tool for Clojure. Leiningen can be used to install Swank clojure as a plugin and start the Swank server for Emacs
To install Lein, Download the script, make it executable and run it
$ wget https://github.com/technomancy/leiningen/raw/stable/bin/lein
$ sudo cp lein /usr/bin
$ sudo chmod +x /usr/bin/lein
$ lein
5.2.2 Install Swank clojure (https://github.com/technomancy/swank-clojure)
After installing Lein, Install Swank clojure as a plugin:
$ lein plugin install swank-clojure 1.3.0
Lein installs plugins in ~/.lein/bin. swank-clojure startup script is created there.
Add ~/.lein/bin to your path
5.2.3 Start Swank server and connect from Emacs
$ swank-clojure
starts Swank server for Clojure REPL
Start Clojure REPL in Emacs by connecting to Swank server. Accept defaults for host and port
M-x slime-connect
Now ogle at the most elegant editor you'll ever see and hack away in the most elegant language you'll ever write code in.
(Reference: http://technomancy.us/126)
Subscribe to:
Posts (Atom)