2

I'm brand-new to both Emacs and Clojure and would like to set up hinting and syntax highlighting somehow similar to the video here. I have installed:

  • Emacs 24.x
  • Leiningen 2.x
  • Marmalade

...Then within Emacs and via Marmalade, installed the following packages:

  • Evil
  • clojure-mode
  • nrepl

My big-idea question is how do these major/minor modes interact and is there a "right" way to set these things up?
My smaller-idea question is how do I get the pretty syntax highlighting and code-hinting? Thanks!

Alex Shroyer
  • 3,499
  • 2
  • 28
  • 54
  • 2
    Are you trying to learn Emacs? Just want to point out that if you are a Vim user (guessing from Evil), then vimclojure-static and fireplace make for a pretty good syntax highlighting and REPL interaction respectively. – A. Webb Aug 08 '13 at 15:10
  • Yes, I'm trying to learn Emacs. I would consider myself a novice Vim user but I found it faster to install Evil than to even navigate around the Emacs tutorial using the default Emacs shortcuts. :) I am okay with the other aspects of the Emacs learning curve since it appears to integrate better with Clojure. – Alex Shroyer Aug 08 '13 at 16:12
  • FYI: the setup shown in the videos is available here: https://github.com/overtone/emacs-live. You can just install it, `lein repl` and M-x nrepl and get going. – tungd Aug 09 '13 at 02:47

3 Answers3

3

Check out Emacs Live, its a full emacs configuration created by Sam Aaron. He codes allot of Clojure so this "battery included" setup works great for Clojure coding.

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

Once you have cloned this and follow the instructions you are up and running with Clojure, nrepl, git and much more.

pjc
  • 157
  • 3
1

I list my setup. Some of the stuff is redundant, since I haven't written in Clojure for a while, but I checked and it still works.

  1. Use clojure to start nrepl. You might have some issue with project.clj being in the appropriate directory, but you should figure this out.
  2. Open a source file e.g. foo.clj.
  3. Use C-c C-l to call nrepl-load-file By the way, it's the canonical shortcut to load the file into inferior process. It will work for Common Lisp, Python etc.
  4. Use C-c C-z to switch to repl. This again is the canonical shortcut that works for many languages.

Here's the setup code:

(require 'clojure-mode)
(defun set-syntax-parens ()
  "highlight []{} etc."
  (interactive)
  (modify-syntax-entry ?[ "(]")
  (modify-syntax-entry ?] ")[")
  (modify-syntax-entry ?{ "(}")
  (modify-syntax-entry ?} "){"))
(defvar clojure.jars '("clojure-1.3.0.jar" 
                       "swank-clojure-1.4.2.jar" 
                       "clojure-contrib-1.2.0.jar"))
(defvar clojure.jars.d (concat dropbox.d "source/clojure/lib/"))
(defvar clojure.classpath 
  (apply #'concat 
         (mapcar (lambda (jar) (concat clojure.jars.d jar path-separator)) 
                 clojure.jars)))
(setq clojure.classpath 
      (concat clojure.classpath 
              dropbox.d "source/clojure/include/" 
              path-separator))
;;;###autoload
(defun clojure ()
  (interactive)
  (nrepl-jack-in))
(defvar clojure-server-cmd 
  (concat "java -Xss4096k -cp " clojure.classpath " clojure.main &"))
(add-hook 'clojure-mode-hook
      (lambda()
        (set-syntax-parens)))
(require 'nrepl)
(add-hook 'nrepl-mode-hook
      (lambda()
        (define-key nrepl-mode-map (kbd "C-l") 'nrepl-clear-buffer)))
abo-abo
  • 20,038
  • 3
  • 50
  • 71
1

here is the operative section from my favorite emacs config:

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

;; Add in your own as you wish:                                                                                                                                           
(defvar my-packages '(starter-kit starter-kit-lisp starter-kit-bindings clojure-mode                                                                                      
                       nrepl auto-complete ac-nrepl org rainbow-delimiters)                                                                                                
  "A list of packages to ensure are installed at launch.")                                                                                                                

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

(require 'ac-nrepl)                                                                                                                                                       
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)                                                                                                                               
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)                                                                                                                   
(eval-after-load "auto-complete"                                                                                                                                          
     '(add-to-list 'ac-modes 'nrepl-mode))                                                                                                                                
(defun set-auto-complete-as-completion-at-point-function ()                                                                                                               
  (setq completion-at-point-functions '(auto-complete)))                                                                                                                  

(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                    

(add-hook 'nrepl-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                            
(add-hook 'nrepl-interaction-mode-hook 'set-auto-complete-as-completion-at-point-function)                                                                                
(define-key nrepl-interaction-mode-map (kbd "C-c C-d") 'ac-nrepl-popup-doc)                                                                                               
(add-hook 'prog-mode-hook 'auto-complete-mode)                                                                                                                            

(add-hook 'nrepl-interaction-mode-hook                                                                                                                                    
          'nrepl-turn-on-eldoc-mode)                                                                                                                                    

(add-hook 'nrepl-mode-hook 'paredit-mode) 

This turns on paredit-mode everywhere, which takes a bit of getting used to though it's entirely worth it because paredit and makes using Clojure much more fun. At least once you get a handle on slurping and barfing

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284