@@ -153,8 +153,28 @@ The following commands are available:
153
153
(add-to-list 'completion-at-point-functions
154
154
#'inf-clojure-completion-at-point ))
155
155
156
- (defcustom inf-clojure-program " lein repl"
157
- " The command used to start an inferior Clojure process in `inf-clojure-mode' .
156
+ (defcustom inf-clojure-lein-cmd " lein repl"
157
+ " The command used to start a Clojure REPL for Leiningen projects.
158
+
159
+ Alternative you can specify a TCP connection cons pair, instead
160
+ of command, consisting of a host and port
161
+ number (e.g. (\" localhost\" . 5555)). That's useful if you're
162
+ often connecting to a remote REPL process."
163
+ :type '(choice (string )
164
+ (cons string integer)))
165
+
166
+ (defcustom inf-clojure-boot-cmd " boot repl"
167
+ " The command used to start a Clojure REPL for Boot projects.
168
+
169
+ Alternative you can specify a TCP connection cons pair, instead
170
+ of command, consisting of a host and port
171
+ number (e.g. (\" localhost\" . 5555)). That's useful if you're
172
+ often connecting to a remote REPL process."
173
+ :type '(choice (string )
174
+ (cons string integer)))
175
+
176
+ (defcustom inf-clojure-generic-cmd " lein repl"
177
+ " The command used to start a Clojure REPL outside Lein/Boot projects.
158
178
159
179
Alternative you can specify a TCP connection cons pair, instead
160
180
of command, consisting of a host and port
@@ -232,11 +252,12 @@ whichever process buffer you want to use.")
232
252
233
253
(define-derived-mode inf-clojure-mode comint-mode " Inferior Clojure"
234
254
" Major mode for interacting with an inferior Clojure process.
235
- Runs a Clojure interpreter as a subprocess of Emacs, with Clojure I/O through an
236
- Emacs buffer. Variable `inf-clojure-program' controls which Clojure interpreter
237
- is run. Variables `inf-clojure-prompt' , `inf-clojure-filter-regexp' and
238
- `inf-clojure-load-command' can customize this mode for different Clojure
239
- interpreters.
255
+ Runs a Clojure interpreter as a subprocess of Emacs, with Clojure
256
+ I/O through an Emacs buffer. Variables of the type
257
+ `inf-clojure-*-cmd' combined with the project type controls how
258
+ a Clojure REPL is started. Variables `inf-clojure-prompt' ,
259
+ `inf-clojure-filter-regexp' and `inf-clojure-load-command' can
260
+ customize this mode for different Clojure REPLs.
240
261
241
262
For information on running multiple processes in multiple buffers, see
242
263
documentation for variable `inf-clojure-buffer' .
@@ -331,6 +352,20 @@ Fallback to `default-directory.' if not within a project."
331
352
inf-clojure-project-root-files)))
332
353
default-directory))
333
354
355
+ (defun inf-clojure-project-type ()
356
+ " Determine the type, either leiningen or boot of the current project."
357
+ (let ((default-directory (inf-clojure-project-root)))
358
+ (cond ((file-exists-p " project.clj" ) " lein" )
359
+ ((file-exists-p " build.boot" ) " boot" )
360
+ (t nil ))))
361
+
362
+ (defun inf-clojure-cmd (project-type )
363
+ " Determine the command `inf-clojure' needs to invoke for the PROJECT-TYPE."
364
+ (pcase project-type
365
+ (" lein" inf-clojure-lein-cmd)
366
+ (" boot" inf-clojure-boot-cmd)
367
+ (_ inf-clojure-generic-cmd)))
368
+
334
369
(defun inf-clojure-clear-repl-buffer ()
335
370
" Clear the REPL buffer."
336
371
(interactive )
@@ -343,18 +378,19 @@ Fallback to `default-directory.' if not within a project."
343
378
If there is a process already running in `*inf-clojure*' , just switch
344
379
to that buffer.
345
380
With argument, allows you to edit the command line (default is value
346
- of `inf-clojure-program ' ). Runs the hooks from
381
+ of `inf-clojure-*-cmd ' ). Runs the hooks from
347
382
`inf-clojure-mode-hook' (after the `comint-mode-hook' is run).
348
383
\( Type \\ [describe-mode] in the process buffer for a list of commands.)"
349
384
(interactive (list (if current-prefix-arg
350
- (read-string " Run Clojure: " inf-clojure-program )
351
- inf-clojure-program )))
385
+ (read-string " Run Clojure: " ( inf-clojure-cmd (inf-clojure-project-type)) )
386
+ ( inf-clojure-cmd (inf-clojure-project-type)) )))
352
387
(if (not (comint-check-proc " *inf-clojure*" ))
353
388
; ; run the new process in the project's root when in a project folder
354
389
(let ((default-directory (inf-clojure-project-root))
355
390
(cmdlist (if (consp cmd)
356
391
(list cmd)
357
392
(split-string cmd))))
393
+ (message " Starting Clojure REPL via `%s' ... " cmd)
358
394
(set-buffer (apply #'make-comint
359
395
" inf-clojure" (car cmdlist) nil (cdr cmdlist)))
360
396
(inf-clojure-mode)))
@@ -363,9 +399,6 @@ of `inf-clojure-program'). Runs the hooks from
363
399
(pop-to-buffer-same-window " *inf-clojure*" )
364
400
(pop-to-buffer " *inf-clojure*" )))
365
401
366
- ;;;### autoload
367
- (defalias 'run-clojure 'inf-clojure )
368
-
369
402
(defun inf-clojure-eval-region (start end &optional and-go )
370
403
" Send the current region to the inferior Clojure process.
371
404
Prefix argument AND-GO means switch to the Clojure buffer afterwards."
@@ -426,7 +459,7 @@ With prefix argument EOB-P, positions cursor at end of buffer."
426
459
(or pop-up-frames
427
460
(get-buffer-window inf-clojure-buffer t ))))
428
461
(pop-to-buffer inf-clojure-buffer))
429
- (run -clojure inf-clojure-program ))
462
+ (inf -clojure ( inf-clojure-cmd (inf-clojure-project-type)) ))
430
463
(when eob-p
431
464
(push-mark )
432
465
(goto-char (point-max ))))
@@ -840,7 +873,7 @@ to suppress the usage of the target buffer discovery logic."
840
873
(target-buffer-name (buffer-name target-buffer)))
841
874
; ; TODO: Try to recycle the old buffer instead of killing and recreating it
842
875
(inf-clojure-quit target-buffer)
843
- (inf-clojure inf-clojure-program )
876
+ (inf-clojure ( inf-clojure-cmd (inf-clojure-project-type)) )
844
877
(rename-buffer target-buffer-name)))
845
878
846
879
(provide 'inf-clojure )
0 commit comments