Created
May 9, 2010 22:51
-
-
Save michalmarczyk/395481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; from http://fons.github.com/adding-clojure-to-an-existing-slime-setup-in-emacs.html | |
(defun swank-clojure-autoloads () | |
(interactive) | |
(let ((generated-autoload-file "~/.emacs.d/lang-support/swank-clojure-autoload.el")) | |
(update-directory-autoloads "~/.emacs.d/lang-support"))) | |
;;; swank-clojure-autoload.el contains | |
;;; (autoload 'swank-clojure-cmd "swank-clojure" "Initialise Clojure for Swank") | |
;;; (provide 'swank-clojure-autoload) | |
;;; lifted from old swank-clojure | |
;; Change the repl to be more clojure friendly | |
(defun swank-clojure-slime-repl-modify-syntax () | |
(when (string-match "\\*slime-repl clojure\\*" (buffer-name)) | |
;; modify syntax | |
(modify-syntax-entry ?~ "' ") | |
(modify-syntax-entry ?, " ") | |
(modify-syntax-entry ?\{ "(}") | |
(modify-syntax-entry ?\} "){") | |
(modify-syntax-entry ?\[ "(]") | |
(modify-syntax-entry ?\] ")[") | |
(modify-syntax-entry ?^ "'") | |
(modify-syntax-entry ?= "'") | |
;; set indentation function (already local) | |
(setq lisp-indent-function 'clojure-indent-function) | |
;; set paredit keys | |
(when (and (featurep 'paredit) paredit-mode (>= paredit-version 21)) | |
(define-key slime-repl-mode-map "{" 'paredit-open-curly) | |
(define-key slime-repl-mode-map "}" 'paredit-close-curly)))) | |
(add-hook 'slime-repl-mode-hook | |
(lambda () | |
(my-basic-lisp-setup) | |
;; FIXME: make Lisp impl. dependent)) | |
(swank-clojure-slime-repl-modify-syntax))) | |
(setq swank-clojure-classpath | |
(directory-files "~/.clojure" t ".jar$")) | |
(require 'swank-clojure-autoload) | |
;;; this is really meant for Clojure and should perhaps not be performed | |
;;; with SBCL... | |
(add-hook 'slime-connected-hook | |
(lambda () | |
(interactive) | |
(slime-redirect-inferior-output) | |
(define-key slime-mode-map (kbd "C-c d") 'slime-java-describe) | |
(define-key slime-repl-mode-map (kbd "C-c d") 'slime-java-describe) | |
(define-key slime-mode-map (kbd "C-c D") 'slime-javadoc) | |
(define-key slime-repl-mode-map (kbd "C-c D") 'slime-javadoc))) | |
;;; clojure-mode font lock for the SLIME REPL | |
(add-hook 'slime-repl-mode-hook | |
(lambda () | |
(clojure-mode-font-lock-setup))) | |
(setq clojure-project-extra-classpaths | |
'( | |
; "deps/" | |
"src/" | |
"classes/" | |
"test/" | |
)) | |
(setq clojure-project-jar-classpaths | |
'( | |
; "deps/" | |
"lib/" | |
)) | |
(defun find-clojure-project-jars (path) | |
(apply #'append | |
(mapcar (lambda (d) | |
(loop for jar in (remove-if (lambda (f) (member f '("." ".."))) | |
(directory-files d t)) | |
collect jar into jars | |
finally return jars)) | |
(remove-if-not #'file-exists-p | |
clojure-project-jar-classpaths)))) | |
(defun find-jar (re jars &optional default) | |
(let ((candidates | |
(remove-if-not | |
(lambda (jar) | |
(string-match-p re jar)) | |
jars))) | |
(cond (candidates (car candidates)) | |
(default default) | |
(t nil)))) | |
(defun find-clojure-jar (jars) | |
(find-jar "clojure\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jars | |
(expand-file-name "~/.clojure/clojure.jar"))) | |
(defun find-clojure-contrib-jar (jars) | |
(find-jar "clojure-contrib\\([0-9.-]+\\(SNAPSHOT|MASTER\\)?\\)?\\.jar$" jars | |
(expand-file-name "~/.clojure/clojure-contrib.jar"))) | |
(defun find-swank-clojure-jar (jars) | |
(find-jar "swank-clojure.jar" jars ; FIXME: insert correct regex | |
(expand-file-name "~/.clojure/swank-clojure.jar"))) | |
;;; original due to Phil Hagelberg | |
;;; (see `Best practices for Slime with Clojure' thread on Clojure Google Group) | |
(defun clojure-project (path) | |
"Sets up classpaths for a clojure project and starts a new SLIME session. | |
Kills existing SLIME session, if any." | |
(interactive (list (ido-read-directory-name | |
"Project root:" | |
(locate-dominating-file default-directory "pom.xml")))) | |
(when (get-buffer "*inferior-lisp*") | |
(kill-buffer "*inferior-lisp*")) | |
(cd path) | |
;; I'm not sure if I want to mkdir; doing that would be a problem | |
;; if I wanted to open e.g. clojure or clojure-contrib as a project | |
;; (both lack "deps/") | |
; (mapcar (lambda (d) (mkdir d t)) '("deps" "src" "classes" "test")) | |
(let* ((jars (find-clojure-project-jars path)) | |
(clojure-jar (find-clojure-jar jars)) | |
(clojure-contrib-jar (find-clojure-contrib-jar jars)) | |
(swank-clojure-jar (find-swank-clojure-jar jars))) | |
; swank-clojure-binary nil | |
; swank-clojure-jar-path (expand-file-name "~/.clojure/clojure.jar") | |
; swank-clojure-jar-path clojure-jar | |
; swank-clojure-extra-classpaths (cons clojure-contrib-jar ...) | |
(setq swank-clojure-classpath | |
(append (list clojure-jar clojure-contrib-jar swank-clojure-jar) | |
(append (mapcar (lambda (d) (expand-file-name d path)) | |
clojure-project-extra-classpaths) | |
(find-clojure-project-jars path))) | |
swank-clojure-extra-vm-args | |
(list (format "-Dclojure.compile.path=%s" | |
(expand-file-name "classes/" path))) | |
slime-lisp-implementations | |
(cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init) | |
(remove-if #'(lambda (x) (eq (car x) 'clojure)) | |
slime-lisp-implementations)))) | |
(slime)) | |
;(save-window-excursion ; preserves window configurations; | |
; TODO: make this happen when a count is given | |
; (slime))) | |
;;; SLIME | |
(eval-after-load "slime" | |
'(progn (slime-setup '(slime-repl slime-fuzzy)))) | |
(setq slime-complete-symbol-function #'slime-fuzzy-complete-symbol | |
slime-fuzzy-completion-in-place t | |
slime-description-autofocus t | |
slime-net-coding-system 'utf-8-unix) | |
(require 'slime) | |
(slime-setup) | |
(defadvice slime-repl-emit (after sr-emit-ad activate) | |
(with-current-buffer (slime-output-buffer) | |
(add-text-properties slime-output-start slime-output-end | |
'(font-lock-face slime-repl-output-face | |
rear-nonsticky (font-lock-face))))) | |
(defadvice slime-repl-insert-prompt (after sr-prompt-ad activate) | |
(with-current-buffer (slime-output-buffer) | |
(let ((inhibit-read-only t)) | |
(add-text-properties slime-repl-prompt-start-mark (point-max) | |
'(font-lock-face slime-repl-prompt-face | |
rear-nonsticky | |
(slime-repl-prompt | |
read-only | |
font-lock-face | |
intangible)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment