Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (75 sloc) 3.43 KB
;;; clojurescript-mode.el --- Major mode for ClojureScript code
;; Copyright (C) 2011 Luke Amdor
;; Authors: Luke Amdor <>
;; URL:
;; Version: 0.5
;; Keywords: languages, lisp, javascript
;; Package-Requires: ((clojure-mode "1.7"))
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Provides an REPL to the
;; ClojureScript language. (
;; For information on how to start up the REPL correctly see
;; and
;;; License:
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
(require 'clojure-mode)
(defvar clojurescript-home
"Path to ClojureScript home directory")
(defvar clojurescript-clj-repl
(when clojurescript-home
(expand-file-name "script/repl" clojurescript-home))
"Path to the ClojureScript Clojure REPL")
(defvar clojurescript-repl-interface
"Which ClojureScript REPL interface to use")
(defun clojurescript-repl-init-commands ()
(concat "(require 'cljs.repl)" "\n"
"(require '" clojurescript-repl-interface ")" "\n"
"(cljs.repl/repl (" clojurescript-repl-interface "/repl-env)" ")" "\n"))
(defun clojurescript-start-cljs-repl ()
;; I know, I know; major facepalm. But that's the way it is.
(when (not clojurescript-home)
(error "CLOJURESCRIPT_HOME not configured. See ClojureScript docs."))
(comint-send-string (inferior-lisp-proc) (clojurescript-repl-init-commands)))
(defun clojurescript-eval-last-expression ()
(let ((expr (slime-last-expression)))
(comint-send-string (inferior-lisp-proc) (concat expr "\n"))))
(defun clojurescript-compile-and-load-file ()
(comint-send-string (inferior-lisp-proc) (buffer-string)))
(define-derived-mode clojurescript-mode clojure-mode "ClojureScript"
"Major mode for ClojureScript"
(set (make-local-variable 'inferior-lisp-program) clojurescript-clj-repl)
(add-hook 'inferior-lisp-mode-hook 'clojurescript-start-cljs-repl)
(when (and (featurep 'paredit) paredit-mode (>= paredit-version 21))
(define-key clojurescript-mode-map "{" 'paredit-open-curly)
(define-key clojurescript-mode-map "}" 'paredit-close-curly))
(when (functionp 'slime-mode)
(slime-mode -1))
(define-key clojurescript-mode-map "\C-x\C-e" 'clojurescript-eval-last-expression)
(define-key clojurescript-mode-map "\C-c\C-k" 'clojurescript-compile-and-load-file))
(put-clojure-indent 'this-as 'defun)
(add-to-list 'auto-mode-alist '("\\.cljs$" . clojurescript-mode))
(provide 'clojurescript-mode)
;;; clojurescript-mode.el ends here
Jump to Line
Something went wrong with that request. Please try again.