65
65
66
66
(require 'comint )
67
67
(require 'clojure-mode )
68
+ (require 'clojure-ts-mode nil :no-error )
68
69
(require 'eldoc )
69
70
(require 'thingatpt )
70
71
(require 'ansi-color )
@@ -193,10 +194,10 @@ either `setq-local` or an entry in `.dir-locals.el`." )
193
194
MULTIPLE PROCESS SUPPORT
194
195
===========================================================================
195
196
To run multiple Clojure processes, you start the first up
196
- with \\ [inf-clojure]. It will be in a buffer named ` *inf-clojure*' .
197
+ with \\ [inf-clojure]. It will be in a buffer named *inf-clojure*.
197
198
Rename this buffer with \\ [rename-buffer]. You may now start up a new
198
199
process with another \\ [inf-clojure]. It will be in a new buffer,
199
- named ` *inf-clojure*' . You can switch between the different process
200
+ named *inf-clojure*. You can switch between the different process
200
201
buffers with \\ [switch-to-buffer].
201
202
202
203
Commands that send text from source buffers to Clojure processes --
@@ -205,7 +206,7 @@ process to send to, when you have more than one Clojure process around. This
205
206
is determined by the global variable `inf-clojure-buffer' . Suppose you
206
207
have three inferior Clojures running:
207
208
Buffer Process
208
- foo inf-clojure
209
+ foo ` inf-clojure'
209
210
bar inf-clojure<2>
210
211
*inf-clojure* inf-clojure<3>
211
212
If you do a \\ [inf-clojure-eval-defun] command on some Clojure source code,
@@ -269,7 +270,7 @@ has been found. See also variable `inf-clojure-buffer'."
269
270
(error " No Clojure subprocess; see variable `inf-clojure-buffer' " ))))
270
271
271
272
(defun inf-clojure-repl-p (&optional buf )
272
- " Indicates if BUF is an inf-clojure REPL.
273
+ " Indicates if BUF is an ` inf-clojure' REPL.
273
274
If BUF is nil then defaults to the current buffer.
274
275
Checks the mode and that there is a live process."
275
276
(let ((buf (or buf (current-buffer ))))
@@ -278,35 +279,35 @@ Checks the mode and that there is a live process."
278
279
(process-live-p (get-buffer-process buf)))))
279
280
280
281
(defun inf-clojure-repls ()
281
- " Return a list of all inf-clojure REPL buffers."
282
+ " Return a list of all ` inf-clojure' REPL buffers."
282
283
(let (repl-buffers)
283
284
(dolist (b (buffer-list ))
284
285
(when (inf-clojure-repl-p b)
285
286
(push (buffer-name b) repl-buffers)))
286
287
repl-buffers))
287
288
288
289
(defun inf-clojure--prompt-repl-buffer (prompt )
289
- " Prompt the user to select an inf-clojure repl buffer.
290
+ " Prompt the user to select an ` inf-clojure' repl buffer.
290
291
PROMPT is a string to prompt the user.
291
292
Returns nil when no buffer is selected."
292
293
(let ((repl-buffers (inf-clojure-repls)))
293
294
(if (> (length repl-buffers) 0 )
294
- (when-let ((repl-buffer (completing-read prompt repl-buffers nil t )))
295
+ (when-let* ((repl-buffer (completing-read prompt repl-buffers nil t )))
295
296
(get-buffer repl-buffer))
296
297
(user-error " No buffers have an inf-clojure process" ))))
297
298
298
299
(defun inf-clojure-set-repl (always-ask )
299
- " Set an inf-clojure buffer as the active (default) REPL.
300
+ " Set an ` inf-clojure' buffer as the active (default) REPL.
300
301
If in a REPL buffer already, use that unless a prefix is used (or
301
- ALWAYS-ASK). Otherwise get a list of all active inf-clojure
302
+ ALWAYS-ASK). Otherwise get a list of all active ` inf-clojure'
302
303
REPLS and offer a choice. It's recommended to rename REPL
303
304
buffers after they are created with `rename-buffer' ."
304
305
(interactive " P" )
305
- (when-let ((new-repl-buffer
306
- (if (or always-ask
307
- (not (inf-clojure-repl-p)))
308
- (inf-clojure--prompt-repl-buffer " Select default REPL: " )
309
- (current-buffer ))))
306
+ (when-let* ((new-repl-buffer
307
+ (if (or always-ask
308
+ (not (inf-clojure-repl-p)))
309
+ (inf-clojure--prompt-repl-buffer " Select default REPL: " )
310
+ (current-buffer ))))
310
311
(setq inf-clojure-buffer new-repl-buffer)
311
312
(message " Current inf-clojure REPL set to %s " new-repl-buffer)))
312
313
@@ -349,6 +350,14 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
349
350
\( as in :a, :c, etc.)"
350
351
:type 'regexp )
351
352
353
+ (defcustom inf-clojure-source-modes '(clojure-mode)
354
+ " Used to determine if a buffer contains Clojure source code.
355
+
356
+ Any buffer with one of these major modes, it's considered a Clojure
357
+ source file by all `inf-clojure' commands."
358
+ :type '(repeat symbol)
359
+ :safe #'symbolp )
360
+
352
361
(defun inf-clojure--modeline-info ()
353
362
" Return modeline info for `inf-clojure-minor-mode' .
354
363
Either \" no process\" or \" buffer-name(repl-type)\" "
@@ -453,7 +462,7 @@ The value of this variable is a mode line template as in
453
462
`mode-line-format' . See Info Node `(elisp)Mode Line Format' for details
454
463
about mode line templates.
455
464
456
- Customize this variable to change how inf-clojure-minor-mode
465
+ Customize this variable to change how ` inf-clojure-minor-mode'
457
466
displays its status in the mode line. The default value displays
458
467
the current REPL. Set this variable to nil to disable the
459
468
mode line entirely."
@@ -609,24 +618,35 @@ This should usually be a combination of `inf-clojure-prompt' and
609
618
:package-version '(inf-clojure . " 2.0.0" ))
610
619
611
620
(defcustom inf-clojure-auto-mode t
612
- " Automatically enable inf-clojure-minor-mode.
621
+ " Automatically enable ` inf-clojure-minor-mode' .
613
622
All buffers in `clojure-mode' will automatically be in
614
623
`inf-clojure-minor-mode' unless set to nil."
615
624
:type 'boolean
616
625
:safe #'booleanp
617
626
:package-version '(inf-clojure . " 3.1.0" ))
618
627
628
+ (defun inf-clojure--get-preferred-major-modes ()
629
+ " Return list of preferred major modes that are actually available."
630
+ (cl-remove-if-not (lambda (mode ) (featurep mode))
631
+ inf-clojure-source-modes))
632
+
633
+ (defun inf-clojure--clojure-buffer-p ()
634
+ " Return TRUE if the current buffer is a Clojure buffer."
635
+ (derived-mode-p (inf-clojure--get-preferred-major-modes)))
636
+
619
637
(defun inf-clojure--clojure-buffers ()
620
638
" Return a list of all existing `clojure-mode' buffers."
621
- (cl-remove-if-not
622
- (lambda (buffer ) (with-current-buffer buffer (derived-mode-p 'clojure-mode )))
623
- (buffer-list )))
639
+ (cl-remove-if-not (lambda (buffer )
640
+ (with-current-buffer buffer
641
+ (inf-clojure--clojure-buffer-p)))
642
+ (buffer-list )))
624
643
625
644
(defun inf-clojure-enable-on-existing-clojure-buffers ()
626
645
" Enable inf-clojure's minor mode on existing Clojure buffers.
627
646
See command `inf-clojure-minor-mode' ."
628
647
(interactive )
629
- (add-hook 'clojure-mode-hook #'inf-clojure-minor-mode )
648
+ (dolist (mode (inf-clojure--get-preferred-major-modes))
649
+ (add-hook (derived-mode-hook-name mode) #'inf-clojure-minor-mode ))
630
650
(dolist (buffer (inf-clojure--clojure-buffers))
631
651
(with-current-buffer buffer
632
652
(inf-clojure-minor-mode +1 ))))
@@ -688,8 +708,12 @@ If `comint-use-prompt-regexp' is nil (the default), \\[comint-insert-input] on
688
708
(setq comint-input-sender 'inf-clojure--send-string )
689
709
(setq comint-prompt-regexp inf-clojure-comint-prompt-regexp)
690
710
(setq mode-line-process '(" :%s" ))
691
- (clojure-mode-variables)
692
- (clojure-font-lock-setup)
711
+ ; ; We don't need to call it in Clojure buffers.
712
+ (unless (inf-clojure--clojure-buffer-p)
713
+ ; ; Using Tree-sitter based syntax highlighting in comint buffer is
714
+ ; ; currently not possible.
715
+ (clojure-mode-variables)
716
+ (clojure-font-lock-setup))
693
717
(when inf-clojure-enable-eldoc
694
718
(inf-clojure-eldoc-setup))
695
719
(setq comint-get-old-input #'inf-clojure-get-old-input )
@@ -801,8 +825,8 @@ The name is simply the final segment of the path."
801
825
802
826
;;;### autoload
803
827
(defun inf-clojure (cmd &optional suppress-message )
804
- " Run an inferior Clojure process, input and output via buffer ` *inf-clojure*' .
805
- If there is a process already running in ` *inf-clojure*' , just
828
+ " Run an inferior Clojure process, input and output via buffer *inf-clojure*.
829
+ If there is a process already running in *inf-clojure*, just
806
830
switch to that buffer.
807
831
808
832
CMD is a string which serves as the startup command or a cons of
@@ -826,6 +850,8 @@ process buffer for a list of commands.)"
826
850
(mapcar #'cdr inf-clojure-startup-forms)
827
851
nil
828
852
'confirm-after-completion ))))
853
+ ; ; TODO: Currently there is no `clojure-project-dir' analogue in
854
+ ; ; `clojure-ts-mode' .
829
855
(let* ((project-dir (clojure-project-dir))
830
856
(process-buffer-name (or
831
857
inf-clojure-custom-repl-name
@@ -850,7 +876,9 @@ process buffer for a list of commands.)"
850
876
(with-current-buffer (apply #'make-comint
851
877
process-buffer-name (car cmdlist) nil (cdr cmdlist))
852
878
(inf-clojure-mode)
853
- (set-syntax-table clojure-mode-syntax-table)
879
+ (set-syntax-table (pcase (car (inf-clojure--get-preferred-major-modes))
880
+ ('clojure-ts-mode clojure-ts-mode-syntax-table)
881
+ (_ clojure-mode-syntax-table)))
854
882
(setq-local inf-clojure-repl-type repl-type)
855
883
(hack-dir-local-variables-non-file-buffer ))))
856
884
; ; update the default comint buffer and switch to it
@@ -978,6 +1006,8 @@ of forms."
978
1006
(condition-case nil
979
1007
(with-temp-buffer
980
1008
(progn
1009
+ ; ; TODO: Should it be adjusted for `clojure-ts-mode'
1010
+ ; ; somehow?
981
1011
(clojurec-mode)
982
1012
(insert str)
983
1013
(whitespace-cleanup )
@@ -986,8 +1016,9 @@ of forms."
986
1016
(while (looking-at " \n " )
987
1017
(delete-char 1 ))
988
1018
(unless (eobp )
989
- (clojure-forward-logical-sexp))
990
- (unless (eobp )
1019
+ ; ; There is no special API for that in
1020
+ ; ; `clojure-ts-mode' , so probably for now lets keep this
1021
+ ; ; `clojure-mode' function.
991
1022
(forward-char )))
992
1023
(buffer-substring-no-properties (point-min ) (point-max ))))
993
1024
(scan-error str)))
@@ -1105,13 +1136,6 @@ START and END are the beginning and end positions in the buffer to send."
1105
1136
This holds a cons cell of the form `(DIRECTORY . FILE)'
1106
1137
describing the last `inf-clojure-load-file' command." )
1107
1138
1108
- (defcustom inf-clojure-source-modes '(clojure-mode)
1109
- " Used to determine if a buffer contains Clojure source code.
1110
- If it's loaded into a buffer that is in one of these major modes, it's
1111
- considered a Clojure source file by `inf-clojure-load-file' .
1112
- Used by this command to determine defaults."
1113
- :type '(repeat symbol))
1114
-
1115
1139
(defun inf-clojure-load-file (&optional switch-to-repl file-name )
1116
1140
" Load a Clojure file into the inferior Clojure process.
1117
1141
@@ -1123,7 +1147,7 @@ is present it will be used instead of the current file."
1123
1147
(file-name (or file-name
1124
1148
(car (comint-get-source " Load Clojure file: " inf-clojure-prev-l/c-dir/file
1125
1149
; ; nil because doesn't need an exact name
1126
- inf-clojure-source- modes nil ))))
1150
+ ( inf-clojure--get-preferred-major- modes) nil ))))
1127
1151
(load-form (inf-clojure-get-feature proc 'load )))
1128
1152
(comint-check-source file-name) ; Check to see if buffer needs saved.
1129
1153
(setq inf-clojure-prev-l/c-dir/file (cons (file-name-directory file-name)
@@ -1132,23 +1156,32 @@ is present it will be used instead of the current file."
1132
1156
(when switch-to-repl
1133
1157
(inf-clojure-switch-to-repl t ))))
1134
1158
1159
+ (defun inf-clojure--find-ns ()
1160
+ " Return the namespace of the current Clojure buffer.
1161
+
1162
+ This function delegates its job to an appropritate function, considering
1163
+ `inf-clojure-source-modes' ."
1164
+ (pcase (car (inf-clojure--get-preferred-major-modes))
1165
+ ('clojure-ts-mode (clojure-ts-find-ns))
1166
+ (_ (clojure-find-ns))))
1167
+
1135
1168
(defun inf-clojure-reload (arg )
1136
1169
" Send a query to the inferior Clojure for reloading the namespace.
1137
- See variable `inf-clojure-reload-form' and
1170
+ See variable `inf-clojure-reload-form' and variable
1138
1171
`inf-clojure-reload-all-form' .
1139
1172
1140
1173
The prefix argument ARG can change the behavior of the command:
1141
1174
1142
- - C-u M-x ` inf-clojure-reload' : prompts for a namespace name.
1143
- - M-- M-x ` inf-clojure-reload' : executes (require ... :reload-all).
1144
- - M-- C-u M-x ` inf-clojure-reload' : reloads all AND prompts."
1175
+ - \\ ` C-u' \\ [ inf-clojure-reload] : prompts for a namespace name.
1176
+ - \\ ` M--' \\ [ inf-clojure-reload] : executes (require ... :reload-all).
1177
+ - \\ ` M--' \\ ` C-u' \\ [ inf-clojure-reload] : reloads all AND prompts."
1145
1178
(interactive " P" )
1146
1179
(let* ((proc (inf-clojure-proc))
1147
1180
(reload-all-p (or (equal arg '- ) (equal arg '(-4 ))))
1148
1181
(prompt-p (or (equal arg '(4 )) (equal arg '(-4 ))))
1149
1182
(ns (if prompt-p
1150
- (car (inf-clojure-symprompt " Namespace" (clojure-find-ns)))
1151
- (clojure-find-ns)))
1183
+ (car (inf-clojure-symprompt " Namespace" (inf- clojure- -find-ns)))
1184
+ (inf- clojure- -find-ns)))
1152
1185
(form (if (not reload-all-p)
1153
1186
(inf-clojure-reload-form proc)
1154
1187
(inf-clojure-reload-all-form proc))))
@@ -1357,11 +1390,11 @@ for evaluation, therefore FORM should not include it."
1357
1390
(defun inf-clojure-arglists (fn )
1358
1391
" Send a query to the inferior Clojure for the arglists for function FN.
1359
1392
See variable `inf-clojure-arglists-form' ."
1360
- (when-let ((proc (inf-clojure-proc 'no-error ) ))
1361
- ( when-let ( (arglists-form (inf-clojure-get-feature proc 'arglists )))
1362
- (thread-first (format arglists-form fn)
1363
- (inf-clojure--process-response proc " (" " )" )
1364
- (inf-clojure--some) ))))
1393
+ (when-let* ((proc (inf-clojure-proc 'no-error ))
1394
+ (arglists-form (inf-clojure-get-feature proc 'arglists )))
1395
+ (thread-first (format arglists-form fn)
1396
+ (inf-clojure--process-response proc " (" " )" )
1397
+ (inf-clojure--some))))
1365
1398
1366
1399
(defun inf-clojure-show-arglists (prompt-for-symbol )
1367
1400
" Show the arglists for function FN in the mini-buffer.
@@ -1383,8 +1416,8 @@ prefix argument PROMPT-FOR-NS, it prompts for a namespace name."
1383
1416
(interactive " P" )
1384
1417
(let* ((proc (inf-clojure-proc))
1385
1418
(ns (if prompt-for-ns
1386
- (car (inf-clojure-symprompt " Ns vars" (clojure-find-ns)))
1387
- (clojure-find-ns)))
1419
+ (car (inf-clojure-symprompt " Ns vars" (inf- clojure- -find-ns)))
1420
+ (inf- clojure- -find-ns)))
1388
1421
(ns-vars-form (inf-clojure-get-feature proc 'ns-vars )))
1389
1422
(inf-clojure--send-string proc (format ns-vars-form ns))))
1390
1423
@@ -1396,8 +1429,8 @@ PROMPT-FOR-NS, it prompts for a namespace name."
1396
1429
(interactive " P" )
1397
1430
(let* ((proc (inf-clojure-proc))
1398
1431
(ns (if prompt-for-ns
1399
- (car (inf-clojure-symprompt " Set ns to" (clojure-find-ns)))
1400
- (clojure-find-ns)))
1432
+ (car (inf-clojure-symprompt " Set ns to" (inf- clojure- -find-ns)))
1433
+ (inf- clojure- -find-ns)))
1401
1434
(set-ns-form (inf-clojure-get-feature proc 'set-ns )))
1402
1435
(when (or (not ns) (equal ns " " ))
1403
1436
(user-error " No namespace selected" ))
0 commit comments