10

I am using emacs 24 on Windows 7 and have installed technomancy's clojure-mode along with paredit 23 beta. I load the source file from my leiningen project and get a repl using clojure-jack-in. The problem is that while paredit is enabled in both Clojure mode and the repl, curly braces are not matched in the repl only in source files.

How can I get it to match braces in the repl as well?

pventura
  • 117
  • 6

2 Answers2

6

I added the following to my .emacs file, that does the trick for me (I did not invent this myself, it's a snippet I found somewhere online - but I can't remember where):

(defun setup-slime-repl-paredit ()
  (define-key slime-repl-mode-map
    (kbd "DEL") 'paredit-backward-delete)
  (define-key slime-repl-mode-map
    (kbd "{") 'paredit-open-curly)
  (define-key slime-repl-mode-map
    (kbd "}") 'paredit-close-curly)
  (modify-syntax-entry ?\{ "(}")
  (modify-syntax-entry ?\} "){")
  (modify-syntax-entry ?\[ "(]")
  (modify-syntax-entry ?\] ")[")
  (modify-syntax-entry ?~ "'   ")
  (modify-syntax-entry ?, "    ")
  (modify-syntax-entry ?^ "'")
  (modify-syntax-entry ?= "'"))

(add-hook 'slime-repl-mode-hook 'setup-slime-repl-paredit)

(add-hook 'slime-repl-mode-hook       'enable-paredit-mode)
Gert
  • 3,839
  • 19
  • 22
1

Grab Phil Hagelberg's durendal package, which provide some clojure-specific enhancements to slime, then try this snippet:

(require 'durendal)
(durendal-enable t)

(defun slime-clojure-repl-setup ()
  (when (string-equal (slime-lisp-implementation-name) "clojure")
    (set-syntax-table clojure-mode-syntax-table)
    (setq lisp-indent-function 'clojure-indent-function)))

(add-hook 'slime-repl-mode-hook 'slime-clojure-repl-setup)

In future, Phil may include the functionality of durendal in swank-clojure itself as an additional lisp payload, at which point the above would become unnecessary.

sanityinc
  • 15,002
  • 2
  • 49
  • 43
  • I tried installing durendal, which then required that I install slime and slime-repl. Even after installing all of them and adding the code above it still did not do matching of curly braces. – pventura Dec 23 '11 at 04:30
  • Odd. I assume you restarted your Emacs? Durendal provides exactly the same hook function that @gertalot provided above. But since you've got that solution working anyway, you're all set. For the record, the Clojure-specific chunk of my emacs config is here: https://github.com/purcell/emacs.d/blob/master/init-clojure.el – sanityinc Dec 23 '11 at 08:41
  • @sanityinc - is my snippet actually *from* Durendal? I don't know where I found it, but if it is I'll edit and add credit. – Gert Dec 23 '11 at 09:52
  • @gertalot Maybe, but I think it was a snippet that was floating around in various people's Emacs configs for a while before being included in durendal. – sanityinc Dec 23 '11 at 09:58
  • Yes, I restarted emacs each time after the changes. I thought it was odd too. – pventura Dec 23 '11 at 18:48