Skip to content

Instantly share code, notes, and snippets.

@devn devn/devn-clojure.el
Created Apr 26, 2012

What would you like to do?
clojure config
(require 'clojure-mode)
(require 'slime)
(require 'slime-repl)
(require 'paredit)
(require 'midje-mode)
(autoload 'clojure-mode "clojure-mode" "A major mode for Clojure" t)
(add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
(add-to-list 'auto-mode-alist '("\\.cljs$" . clojure-mode))
;; paredit for mini/buffers in lispy langs
(dolist (hook '(emacs-lisp-mode-hook
(add-hook hook (lambda ()
(paredit-mode 1)
(show-paren-mode 1)
(add-hook 'minibuffer-setup-hook (lambda () (paredit-mode 1))))))
(eval-after-load "paredit"
'(progn (define-key paredit-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
(define-key paredit-mode-map (kbd "C-c )") 'paredit-forward-barf-sexp)
(define-key paredit-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
(define-key paredit-mode-map (kbd "C-c (") 'paredit-backward-barf-sexp)
(define-key paredit-mode-map (kbd "M-R") 'paredit-raise-sexp)
(define-key paredit-mode-map (kbd "M-)") 'paredit-forward-slurp-sexp)
(define-key paredit-mode-map (kbd "M-r") nil)))
(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 ?= "'"))
(defmacro defclojureface (name color desc &optional others)
`(defface ,name '((((class color)) (:foreground ,color ,@others))) ,desc :group 'faces))
(defclojureface clojure-parens "DimGrey" "Clojure parens")
(defclojureface clojure-braces "#49b2c7" "Clojure braces")
(defclojureface clojure-brackets "SteelBlue" "Clojure brackets")
(defclojureface clojure-keyword "khaki" "Clojure keywords")
(defclojureface clojure-java-call "#4bcf68" "Clojure Java calls")
(defclojureface clojure-special "#b8bb00" "Clojure special")
(defclojureface clojure-double-quote "#b8bb00" "Clojure special")
;; (defclojureface clojure-double-quote "#b8bb00" "Clojure special" (:background "unspecified"))
(defun tweak-clojure-syntax (mode)
(mapcar (lambda (x) (font-lock-add-keywords mode x))
'((("#?['`]*(\\|)" . 'clojure-parens))
(("#?\\^?{\\|}" . 'clojure-braces))
(("\\[\\|\\]" . 'clojure-brackets))
((":\\w+" . 'clojure-keyword))
(("#?\"" 0 'clojure-double-quote prepend))
(("nil\\|true\\|false\\|%[1-9]?" . 'clojure-special))
(("(\\(\\.[^ \n)]*\\|[^ \n)]+\\.\\|new\\)\\([ )\n]\\|$\\)" 1
(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 'font-lock-warning-face t))
;; (("(\\(fn\\>\\)" 0 (progn (compose-region (match-beginning 1)
;; (match-end 1) "ƒ") nil)))
;; (("(\\(complement\\>\\)" 0 (progn (compose-region
;; (match-beginning 1)
;; (match-end 1) "¬") nil)))
(("^[a-zA-Z0-9-.*+!_?]+?>" . 'slime-repl-prompt-face)))))
;; Slime
(eval-after-load "slime"
(slime-setup '(slime-repl))
(setq slime-net-coding-system 'utf-8-unix)
(setq slime-highlight-compiler-notes nil)))
;; Slime-REPL tweaks
(eval-after-load "slime-repl"
(add-hook 'slime-repl-mode-hook 'setup-slime-repl-paredit)
(add-hook 'slime-repl-mode-hook (lambda () (paredit-mode 1)))
(add-hook 'slime-repl-mode-hook
(lambda ()
(font-lock-mode nil)
(font-lock-mode t)))
(tweak-clojure-syntax 'slime-repl-mode)
(setq lisp-indent-function 'clojure-indent-function)))
;; Tweak clojure syntax, replace (fn by (ƒ and highlight characters
;; beyond the 80 char limit
(eval-after-load "clojure-mode"
;; (add-hook 'clojure-mode-hook 'highlight-80+-mode)
(add-hook 'clojure-mode-hook 'midje-mode)
(add-hook 'clojure-mode-hook 'slime-editing-mode)
(define-key clojure-mode-map (kbd "C-j") 'slime-eval-print-last-expression)
(define-key clojure-mode-map (kbd "M-TAB") 'slime-complete-symbol)
(whitespace-mode 1)
(tweak-clojure-syntax 'clojure-mode)))
(provide 'devn-clojure)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.