Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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)))

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top