forked from jochu/clojure-mode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclojure-mode.el
662 lines (571 loc) · 24.2 KB
/
clojure-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
;;; clojure-mode.el --- Major mode for Clojure code
;; Copyright (C) 2007, 2008, 2009 Jeffrey Chu, Lennart Staflin, Phil Hagelberg
;;
;; Authors: Jeffrey Chu <[email protected]>
;; Lennart Staflin <[email protected]>
;; Phil Hagelberg <[email protected]>
;; URL: http://www.emacswiki.org/cgi-bin/wiki/ClojureMode
;; Version: 1.5
;; Keywords: languages, lisp
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Provides font-lock, indentation, and navigation for the Clojure
;; language. (http://clojure.org)
;;; Installation:
;; If you use ELPA (http://tromey.com/elpa), you can install via the
;; M-x package-list-packages interface. This is preferrable as you
;; will have access to updates automatically.
;; If you need to install by hand for some reason:
;; (0) Add this file to your load-path, usually the ~/.emacs.d directory.
;; (1) Either:
;; Add this to your .emacs config: (require 'clojure-mode)
;; Or generate autoloads with the `update-directory-autoloads' function.
;; The clojure-install function can check out and configure all the
;; dependencies get going with Clojure, including SLIME integration.
;; To use this function, you may have to manually load clojure-mode.el
;; using M-x load-file or M-x eval-buffer.
;; Users of older Emacs (pre-22) should get version 1.4:
;; http://github.com/technomancy/clojure-mode/tree/1.4
;; Paredit users:
;; Download paredit v21 or greater
;; http://mumble.net/~campbell/emacs/paredit.el
;; Use paredit as you normally would with any other mode; for instance:
;;
;; ;; require or autoload paredit-mode
;; (defun lisp-enable-paredit-hook () (paredit-mode 1))
;; (add-hook 'clojure-mode-hook 'lisp-enable-paredit-hook)
;;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; 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.
;;; Code:
(require 'cl)
(defgroup clojure-mode nil
"A mode for Clojure"
:prefix "clojure-mode-"
:group 'applications)
(defcustom clojure-mode-font-lock-comment-sexp nil
"Set to non-nil in order to enable font-lock of (comment...)
forms. This option is experimental. Changing this will require a
restart (ie. M-x clojure-mode) of existing clojure mode buffers."
:type 'boolean
:group 'clojure-mode)
(defcustom clojure-mode-use-backtracking-indent nil
"Set to non-nil to enable backtracking/context sensitive indentation."
:type 'boolean
:group 'clojure-mode)
(defcustom clojure-max-backtracking 3
"Maximum amount to backtrack up a list to check for context."
:type 'integer
:group 'clojure-mode)
(defcustom clojure-mode-cleanup-whitespace nil
"Non-nil to invoke `delete-trailing-whitespace' before saves."
:type 'boolean
:group 'clojure-mode)
(defvar clojure-mode-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map lisp-mode-shared-map)
map)
"Keymap for Clojure mode. Inherits from `lisp-mode-shared-map'.")
(defvar clojure-mode-syntax-table
(let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
(modify-syntax-entry ?~ "' " table)
(modify-syntax-entry ?, " " table)
(modify-syntax-entry ?\{ "(}" table)
(modify-syntax-entry ?\} "){" table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
(modify-syntax-entry ?^ "'" table)
table))
(defvar clojure-mode-abbrev-table nil
"Abbrev table used in clojure-mode buffers.")
(define-abbrev-table 'clojure-mode-abbrev-table ())
(defvar clojure-def-regexp "^\\s *\\((def\\S *\\s +\\(\[^ \n\t\]+\\)\\)"
"A regular expression to match any top-level definitions.")
;;;###autoload
(defun clojure-mode ()
"Major mode for editing Clojure code - similar to Lisp mode..
Commands:
Delete converts tabs to spaces as it moves back.
Blank lines separate paragraphs. Semicolons start comments.
\\{clojure-mode-map}
Entry to this mode calls the value of `clojure-mode-hook'
if that value is non-nil."
(interactive)
(kill-all-local-variables)
(use-local-map clojure-mode-map)
(setq major-mode 'clojure-mode)
(setq mode-name "Clojure")
(lisp-mode-variables nil)
(set-syntax-table clojure-mode-syntax-table)
(setq local-abbrev-table clojure-mode-abbrev-table)
(set (make-local-variable 'comment-start-skip)
"\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(;+\\|#|\\) *")
(set (make-local-variable 'lisp-indent-function)
'clojure-indent-function)
(set (make-local-variable 'lisp-doc-string-elt-property)
'clojure-doc-string-elt)
(set (make-local-variable 'font-lock-multiline) t)
(set (make-local-variable 'before-save-hook) #'clojure-mode-before-save)
(setq lisp-imenu-generic-expression
`((nil ,clojure-def-regexp 2)))
(setq imenu-create-index-function
(lambda ()
(imenu--generic-function lisp-imenu-generic-expression)))
(add-to-list 'font-lock-extend-region-functions
'clojure-font-lock-extend-region-def t)
(when clojure-mode-font-lock-comment-sexp
(add-to-list 'font-lock-extend-region-functions
'clojure-font-lock-extend-region-comment t)
(make-local-variable 'clojure-font-lock-keywords)
(add-to-list 'clojure-font-lock-keywords
'clojure-font-lock-mark-comment t)
(set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil))
(setq font-lock-defaults
'(clojure-font-lock-keywords ; keywords
nil nil
(("+-*/.<>=!?$%_&~^:@" . "w")) ; syntax alist
nil
(font-lock-mark-block-function . mark-defun)
(font-lock-syntactic-face-function
. lisp-font-lock-syntactic-face-function)))
(run-mode-hooks 'clojure-mode-hook)
;; Enable curly braces when paredit is enabled in clojure-mode-hook
(when (and (featurep 'paredit) paredit-mode (>= paredit-version 21))
(define-key clojure-mode-map "{" 'paredit-open-curly)
(define-key clojure-mode-map "}" 'paredit-close-curly)))
;; (define-key clojure-mode-map "{" 'self-insert-command)
;; (define-key clojure-mode-map "}" 'self-insert-command)
(defun clojure-mode-before-save ()
"Clean up whitespace before saving file.
You can disable this by customizing `clojure-mode-cleanup-whitespace'."
(when clojure-mode-cleanup-whitespace
(let ((col (current-column)))
(delete-trailing-whitespace)
;; don't change trailing whitespace on current line
(unless (eq (current-column) col)
(indent-to col)))))
(defun clojure-font-lock-def-at-point (point)
"Find the position range between the top-most def* and the
fourth element afterwards. Note that this means there's no
gaurantee of proper font locking in def* forms that are not at
top-level."
(goto-char point)
(condition-case nil
(beginning-of-defun)
(error nil))
(let ((beg-def (point)))
(when (and (not (= point beg-def))
(looking-at "(def"))
(condition-case nil
(progn
;; move forward as much as possible until failure (or success)
(forward-char)
(dotimes (i 4)
(forward-sexp)))
(error nil))
(cons beg-def (point)))))
(defun clojure-font-lock-extend-region-def ()
"Move fontification boundaries to always include the first four
elements of a def* forms."
(let ((changed nil))
(let ((def (clojure-font-lock-def-at-point font-lock-beg)))
(when def
(destructuring-bind (def-beg . def-end) def
(when (and (< def-beg font-lock-beg)
(< font-lock-beg def-end))
(setq font-lock-beg def-beg
changed t)))))
(let ((def (clojure-font-lock-def-at-point font-lock-end)))
(when def
(destructuring-bind (def-beg . def-end) def
(when (and (< def-beg font-lock-end)
(< font-lock-end def-end))
(setq font-lock-end def-end
changed t)))))
changed))
(defun clojure-font-lock-extend-region-comment ()
"Move fontification boundaries to always contain
entire (comment ..) sexp. Does not work if you have a
white-space between ( and comment, but that is omitted to make
this run faster."
(let ((changed nil))
(goto-char font-lock-beg)
(condition-case nil (beginning-of-defun) (error nil))
(let ((pos (re-search-forward "(comment\\>" font-lock-end t)))
(when pos
(forward-char -8)
(when (< (point) font-lock-beg)
(setq font-lock-beg (point)
changed t))
(condition-case nil (forward-sexp) (error nil))
(when (> (point) font-lock-end)
(setq font-lock-end (point)
changed t))))
changed))
(defun clojure-font-lock-mark-comment (limit)
"Marks all (comment ..) forms with font-lock-comment-face."
(let (pos)
(while (and (< (point) limit)
(setq pos (re-search-forward "(comment\\>" limit t)))
(when pos
(forward-char -8)
(condition-case nil
(add-text-properties (1+ (point)) (progn
(forward-sexp) (1- (point)))
'(face font-lock-comment-face multiline t))
(error (forward-char 8))))))
nil)
(defconst clojure-font-lock-keywords
(eval-when-compile
`( ;; Definitions.
(,(concat "(\\(?:clojure.core/\\)?\\("
(regexp-opt '("defn" "defn-"
"defmulti" "defmethod"
"defmacro"
"deftest"
"defstruct"
"def" "defonce"))
;; Function declarations.
"\\)\\>"
;; Any whitespace
"[ \r\n\t]*"
;; Possibly type or metadata
"\\(?:#^\\(?:{[^}]*}\\|\\sw+\\)[ \r\n\t]*\\)?"
"\\(\\sw+\\)?")
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
;; Control structures
(,(concat
"(\\(?:clojure.core/\\)?"
(regexp-opt
'("let" "letfn" "do"
"cond" "condp"
"for" "loop" "recur"
"when" "when-not" "when-let" "when-first"
"if" "if-let" "if-not"
"." ".." "->" "doto"
"and" "or"
"dosync" "doseq" "dotimes" "dorun" "doall"
"load" "import" "unimport" "ns" "in-ns" "refer"
"try" "catch" "finally" "throw"
"with-open" "with-local-vars" "binding"
"gen-class" "gen-and-load-class" "gen-and-save-class") t)
"\\>")
. 1)
;; Built-ins
(,(concat
"(\\(?:clojure.core/\\)?"
(regexp-opt
'("implement" "proxy" "lazy-cons" "with-meta"
"struct" "struct-map" "delay" "locking" "sync" "time" "apply"
"remove" "merge" "interleave" "interpose" "distinct" "for"
"cons" "concat" "lazy-cat" "cycle" "rest" "frest" "drop"
"drop-while" "nthrest" "take" "take-while" "take-nth" "butlast"
"reverse" "sort" "sort-by" "split-at" "partition" "split-with"
"first" "ffirst" "rfirst" "when-first" "zipmap" "into" "set" "vec"
"to-array-2d" "not-empty" "seq?" "not-every?" "every?" "not-any?"
"map" "mapcat" "vector?" "list?" "hash-map" "reduce" "filter"
"vals" "keys" "rseq" "subseq" "rsubseq" "count" "empty?"
"fnseq" "lazy-cons" "repeatedly" "iterate" "drop-last"
"repeat" "replicate" "range" "into-array"
"line-seq" "resultset-seq" "re-seq" "re-find" "tree-seq" "file-seq"
"iterator-seq" "enumeration-seq" "declare" "xml-seq"
"symbol?" "string?" "vector" "conj" "str"
"pos?" "neg?" "zero?" "nil?" "inc" "format"
"alter" "commute" "ref-set" "floor" "assoc" "send" "send-off" ) t)
"\\>")
1 font-lock-builtin-face)
;; (fn name? args ...)
(,(concat "(\\(?:clojure.core/\\)?\\(fn\\)[ \t]+"
;; Possibly type
"\\(?:#^\\sw+[ \t]*\\)?"
;; Possibly name
"\\(\\sw+\\)?" )
(1 font-lock-keyword-face)
(2 font-lock-function-name-face nil t))
;; Constant values (keywords).
("\\<:\\(\\sw\\|#\\)+\\>" 0 font-lock-builtin-face)
;; Meta type annotation #^Type
("#^\\sw+" 0 font-lock-type-face)
("\\<io\\!\\>" 0 font-lock-warning-face)))
"Default expressions to highlight in Clojure mode.")
;; Docstring positions
(put 'defn 'clojure-doc-string-elt 2)
(put 'defn- 'clojure-doc-string-elt 2)
(put 'defmulti 'clojure-doc-string-elt 2)
(put 'defmacro 'clojure-doc-string-elt 2)
(defun clojure-indent-function (indent-point state)
"This function is the normal value of the variable `lisp-indent-function'.
It is used when indenting a line within a function call, to see if the
called function says anything special about how to indent the line.
INDENT-POINT is the position where the user typed TAB, or equivalent.
Point is located at the point to indent under (for default indentation);
STATE is the `parse-partial-sexp' state for that position.
If the current line is in a call to a Lisp function
which has a non-nil property `lisp-indent-function',
that specifies how to do the indentation. The property value can be
* `defun', meaning indent `defun'-style;
* an integer N, meaning indent the first N arguments specially
like ordinary function arguments and then indent any further
arguments like a body;
* a function to call just as this function was called.
If that function returns nil, that means it doesn't specify
the indentation.
This function also returns nil meaning don't specify the indentation."
(let ((normal-indent (current-column)))
(goto-char (1+ (elt state 1)))
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
(if (and (elt state 2)
(not (looking-at "\\sw\\|\\s_")))
;; car of form doesn't seem to be a symbol
(progn
(if (not (> (save-excursion (forward-line 1) (point))
calculate-lisp-indent-last-sexp))
(progn (goto-char calculate-lisp-indent-last-sexp)
(beginning-of-line)
(parse-partial-sexp (point)
calculate-lisp-indent-last-sexp 0 t)))
;; Indent under the list or under the first sexp on the same
;; line as calculate-lisp-indent-last-sexp. Note that first
;; thing on that line has to be complete sexp since we are
;; inside the innermost containing sexp.
(backward-prefix-chars)
(if (and (eq (char-after (point)) ?\[)
(eq (char-after (elt state 1)) ?\())
(+ (current-column) 2) ;; this is probably inside a defn
(current-column)))
(let ((function (buffer-substring (point)
(progn (forward-sexp 1) (point))))
(open-paren (elt state 1))
method)
(setq method (get (intern-soft function) 'clojure-indent-function))
(cond ((member (char-after open-paren) '(?\[ ?\{))
(goto-char open-paren)
(1+ (current-column)))
((or (eq method 'defun)
(and (null method)
(> (length function) 3)
(string-match "\\`\\(?:\\S +/\\)?def\\|with-"
function)))
(lisp-indent-defform state indent-point))
((integerp method)
(lisp-indent-specform method state
indent-point normal-indent))
(method
(funcall method indent-point state))
(clojure-mode-use-backtracking-indent
(clojure-backtracking-indent
indent-point state normal-indent)))))))
(defun clojure-backtracking-indent (indent-point state normal-indent)
"Experimental backtracking support. Will upwards in an sexp to
check for contextual indenting."
(let (indent (path) (depth 0))
(goto-char (elt state 1))
(while (and (not indent)
(< depth clojure-max-backtracking))
(let ((containing-sexp (point)))
(parse-partial-sexp (1+ containing-sexp) indent-point 1 t)
(when (looking-at "\\sw\\|\\s_")
(let* ((start (point))
(fn (buffer-substring start (progn (forward-sexp 1) (point))))
(meth (get (intern-soft fn) 'clojure-backtracking-indent)))
(let ((n 0))
(when (< (point) indent-point)
(condition-case ()
(progn
(forward-sexp 1)
(while (< (point) indent-point)
(parse-partial-sexp (point) indent-point 1 t)
(incf n)
(forward-sexp 1)))
(error nil)))
(push n path))
(when meth
(let ((def meth))
(dolist (p path)
(if (and (listp def)
(< p (length def)))
(setq def (nth p def))
(if (listp def)
(setq def (car (last def)))
(setq def nil))))
(goto-char (elt state 1))
(when def
(setq indent (+ (current-column) def)))))))
(goto-char containing-sexp)
(condition-case ()
(progn
(backward-up-list 1)
(incf depth))
(error (setq depth clojure-max-backtracking)))))
indent))
;; clojure backtracking indent is experimental and the format for these
;; entries are subject to change
(put 'implement 'clojure-backtracking-indent '(4 (2)))
(put 'letfn 'clojure-backtracking-indent '((2) 2))
(put 'proxy 'clojure-backtracking-indent '(4 4 (2)))
(defun put-clojure-indent (sym indent)
(put sym 'clojure-indent-function indent)
(put (intern (format "clojure/%s" (symbol-name sym)))
'clojure-indent-function indent))
(defmacro define-clojure-indent (&rest kvs)
`(progn
,@(mapcar (lambda (x) `(put-clojure-indent
(quote ,(first x)) ,(second x))) kvs)))
(define-clojure-indent
(catch 2)
(defmuti 1)
(do 0)
(for 1)
(if 1)
(if-not 1)
(let 1)
(letfn 1)
(loop 1)
(struct-map 1)
(assoc 1)
(condp 2)
(fn 'defun)
(testing 1))
;; built-ins
(define-clojure-indent
(ns 1)
(binding 1)
(comment 0)
(defstruct 1)
(doseq 1)
(dotimes 1)
(doto 1)
(implement 1)
(let 1)
(when-let 1)
(if-let 1)
(locking 1)
(proxy 2)
(sync 1)
(when 1)
(when-first 1)
(when-let 1)
(when-not 1)
(with-local-vars 1)
(with-open 1)
(with-precision 1))
;;; SLIME integration
;;;###autoload
(progn
(defcustom clojure-src-root (expand-file-name "~/src")
"Directory that contains checkouts for clojure, clojure-contrib,
slime, and swank-clojure. This value is used by `clojure-install'
and `clojure-slime-config'."
:type 'string
:group 'clojure-mode)
;; We want this function to be able to be loaded without loading the
;; whole of clojure-mode.el since it runs at every startup.
(defun clojure-slime-config (&optional src-root)
"Load Clojure SLIME support out of the `clojure-src-root' directory.
Since there's no single conventional place to keep Clojure, this
is bundled up as a function so that you can call it after you've set
`clojure-src-root' in your personal config."
(if src-root (setq clojure-src-root src-root))
(add-to-list 'load-path (concat clojure-src-root "/slime"))
(add-to-list 'load-path (concat clojure-src-root "/slime/contrib"))
(add-to-list 'load-path (concat clojure-src-root "/swank-clojure"))
(require 'slime-autoloads)
(require 'swank-clojure-autoload)
(slime-setup '(slime-fancy))
(setq swank-clojure-classpath
(list
(concat clojure-src-root "/clojure/clojure.jar")
(concat clojure-src-root "/clojure-contrib/clojure-contrib.jar")))
(eval-after-load 'slime
'(progn (require 'swank-clojure)
(setq slime-lisp-implementations
(cons `(clojure ,(swank-clojure-cmd) :init
swank-clojure-init)
(remove-if #'(lambda (x) (eq (car x) 'clojure))
slime-lisp-implementations)))))))
;;;###autoload
(defun clojure-install (src-root)
"Perform the initial Clojure install along with Emacs support libs.
This requires git, a JVM, ant, and an active Internet connection."
(interactive (list
(read-string (concat "Install Clojure in (default: "
clojure-src-root "): ")
nil nil clojure-src-root)))
(let ((orig-directory default-directory))
(make-directory src-root t)
(cd src-root)
(if (file-exists-p (concat src-root "/clojure"))
(error "Clojure is already installed at %s/clojure" src-root))
(message "Checking out source... this will take a while...")
(dolist (cmd '("git clone git://github.com/richhickey/clojure.git"
"git clone git://github.com/richhickey/clojure-contrib.git"
"git clone --depth 2 git://github.com/technomancy/slime.git"
"git clone git://github.com/technomancy/swank-clojure.git"))
(unless (= 0 (shell-command cmd))
(error "Clojure installation step failed: %s" cmd)))
(cd (format "%s/clojure" src-root))
(shell-command "git checkout 1.0")
(unless (= 0 (shell-command "ant"))
(error "Couldn't compile Clojure."))
(cd (format "%s/clojure-contrib" src-root))
(shell-command "git checkout clojure-1.0-compatible")
(unless (= 0 (shell-command "ant -Dclojure.jar=../clojure/clojure.jar"))
(error "Couldn't compile Contrib."))
(with-output-to-temp-buffer "clojure-install-note"
(princ
(if (equal src-root clojure-src-root)
"Add a call to \"\(clojure-slime-config\)\"
to your .emacs so you can use SLIME in future sessions."
(setq clojure-src-root src-root)
(format "You've installed clojure in a non-default location. If you
want to use this installation in the future, you will need to add the following
lines to your personal Emacs config somewhere:
\(clojure-slime-config \"%s\"\)" src-root)))
(princ "\n\n Press M-x slime to launch Clojure."))
(clojure-slime-config)
(cd orig-directory)))
(defun clojure-update ()
"Update clojure-related repositories from upstream master and recompile clojure.
Works with clojure etc. installed via `clojure-install'. Code
should be checked out in the `clojure-src-root' directory."
(interactive)
(message "Updating...")
(let ((orig-directory default-directory))
(dolist (repo '("clojure" "clojure-contrib" "swank-clojure" "slime"))
(cd (concat clojure-src-root "/" repo))
(unless (= 0 (shell-command "git checkout master && git pull"))
(error "Clojure update failed: %s" repo)))
(message "Compiling...")
(cd (format "%s/clojure" clojure-src-root))
(unless (= 0 (shell-command "ant"))
(error "Couldn't compile Clojure."))
(cd (format "%s/clojure-contrib" clojure-src-root))
(unless (= 0 (shell-command "ant -Dclojure.jar=../clojure/clojure.jar"))
(error "Couldn't compile Contrib."))
(message "Finished updating Clojure.")
(cd orig-directory)))
(defun clojure-enable-slime-on-existing-buffers ()
(interactive)
(add-hook 'clojure-mode-hook 'swank-clojure-slime-mode-hook)
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(if (equal major-mode 'clojure-mode)
(swank-clojure-slime-mode-hook)))))
(add-hook 'slime-connected-hook 'clojure-enable-slime-on-existing-buffers)
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.clj$" . clojure-mode))
(provide 'clojure-mode)
;;; clojure-mode.el ends here