How to install Clojure for emacs?

10 views
Skip to first unread message

slix

unread,
Jul 2, 2008, 3:15:45 AM7/2/08
to Clojure
I want to use the emacs mode from Jeffrey Chu.

Where should I install it? in the clojure directory under emacs? then
set a load path to there and that is it?

Paul Barry

unread,
Jul 2, 2008, 10:32:53 AM7/2/08
to clo...@googlegroups.com
Here's how I do it using Aquamacs, you can alter this if you are using a different emacs:

0.  Follow instructions at http://en.wikibooks.org/wiki/Clojure_Programming#Installation_from_Source to get clj installed and in your path, verify that it works by running clj from the command line.
1.  mkdir ~/emacs
2.  cd ~/emacs
3a.  If you have git installed, run this:


3b. If you do not have git installed, download this tarball:

http://github.com/jochu/clojure-mode/tarball/master


And untar it in the ~/emacs directory


4.  Start Aquamacs
5.  C-x C-f ~/emacs/clojure-mode/clojure-mode-config.el (opens up that file for editing)
6.  Enter this:

(provide 'clojure-mode-config)

(setq inferior-lisp-program "clj")
(require 'clojure-mode)
(setq auto-mode-alist
      (cons '("\\.clj$" . clojure-mode)
            auto-mode-alist))

(add-hook 'clojure-mode-hook
          '(lambda ()
             (define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp)))

7.  C-x C-s (saves the file)
8.  C-x C-f ~/emacs/my-config.el
9.  Enter this:    

(provide 'my-config)

(add-to-list 'load-path "~/emacs/clojure-mode")

(require 'clojure_mode_config)

10.  C-x C-f ~/Library/Preferences/Aquamacs\ Emacs/customizations.el
11.  Add this:  

(add-to-list 'load-path "~/emacs")
(require 'my-config)

12.  C-x C-s
13.  M-x eval-buffer  (Reads the configuration in, if no errors, everything worked)
14.  C-x C-f ~/foo.clj (opens a new Clojure file)
15.  C-c C-z (starts the REPL)

Allen Rohner

unread,
Jul 2, 2008, 10:21:37 AM7/2/08
to Clojure
If you follow the link from clojure.org to the wiki site, you'll see a
section on setting up emacs:

http://en.wikibooks.org/wiki/Clojure_Programming#Editors.2FIDEs

I took a slightly different approach. I created a script that
contained the line to start clojure:

echo "java -cp jline-0.9.91.jar:clojure.jar jline.ConsoleRunner
clojure.lang.Repl" > ~/bin/clojure

Then inside emacs,

M-x set variable inferior-lisp-program "~/bin/clojure"

Matt Revelle

unread,
Jul 2, 2008, 10:12:35 AM7/2/08
to clo...@googlegroups.com
Wherever you'd like and basically yes.

For example:
(add-to-list 'load-path "~/src/clojure-extra")
(add-to-list 'load-path "~/src/swank-clojure")
(add-to-list 'load-path "~/src/clojure-mode")

The wiki should have the rest of the info.

klant

unread,
Jul 2, 2008, 1:43:52 PM7/2/08
to Clojure
But this is just a mode right?

I use a lot of different languages, I dont want to autostart clojure
or anything. just have it as an option.

klant

unread,
Jul 2, 2008, 2:09:55 PM7/2/08
to Clojure
Having some troubles:

---------------------------------------


("C:\\emacs-22.2\\bin\\emacs.exe")
Loading encoded-kb...done


An error has occurred while loading `c:/Users/saftarn/AppData/
Roaming/.emacs':

File error: Cannot open load file, clojure-mode

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.

For information about GNU Emacs and the GNU system, type C-h C-a.
Loading c:/Program Files/erl5.6.2/lib/tools-2.6.1/emacs/erlang.el
(source)...done
!! File erlang uses old-style backquotes !!
Loading dired...
Loading regexp-opt...done
Loading dired...done
Loading inf-lisp...done
apply: Spawning child process: invalid argument
call-interactively: Text is read-only [3 times]
(New file)
byte-code: Beginning of buffer [2 times]
byte-code: Beginning of buffer


--------------------------------------


(setq load-path (cons "C:/Program Files/erl5.6.2/lib/tools-2.6.1/
emacs"
load-path))
(setq erlang-root-dir "C:/Program Files/erl5.6.2")
(setq exec-path (cons "C:/Program Files/erl5.6.2/bin" exec-
path))
(require 'erlang-start)

(setq inferior-lisp-program
; Path to java implementation
(let* ((java-path "C:/Program Files/Java/")
; Extra command-line options
; to java.
(java-options "")
; Base directory to Clojure.
; Change this accordingly.
(clojure-path "C:/clojure_20080612/")
; The character between
; elements of your classpath.
(class-path-delimiter ";")
(class-path (mapconcat (lambda (s) s)
; Add other paths to this list
; if you want to have other
; things in your classpath.
(list (concat clojure-path
"clojure.jar"))
class-path-delimiter)))
(concat java-path
" " java-options
" -cp " class-path
" clojure.lang.Repl")))

;; Require clojure-mode to load and associate it to all .clj files.
(setq load-path (cons "C:/clojure_20080612/Progs/" load-path))
(require 'clojure-mode)
(setq auto-mode-alist
(cons '("\\.clj$" . clojure-mode)
auto-mode-alist))

;; These are extra key defines because I kept typing them.
;; Within clojure-mode, have Ctrl-x Ctrl-e evaluate the last
;; expression.
;; Ctrl-c Ctrl-e is also there, because I kept typoing it.
(add-hook 'clojure-mode-hook
'(lambda ()
(define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-
sexp)
(define-key clojure-mode-map "\C-x\C-e" 'lisp-eval-last-
sexp)))

klant

unread,
Jul 2, 2008, 2:23:49 PM7/2/08
to Clojure
i changed
(setq load-path (cons "C:/clojure_20080612/Progs/" load-path)) to
C:/emacs-22.2/clojure-mode/

is that correct?

still get:
Reply all
Reply to author
Forward
0 new messages