@@ -518,6 +518,9 @@ Should be a symbol that is a key in `inf-clojure-repl-features'."
518
518
(const :tag " babashka" babashka)
519
519
(const :tag " determine at startup" nil )))
520
520
521
+ (defvar inf-clojure-custom-repl-name nil
522
+ " A string to be used as the repl buffer name." )
523
+
521
524
(defun inf-clojure--whole-comment-line-p (string )
522
525
" Return non-nil iff STRING is a whole line semicolon comment."
523
526
(string-match-p " ^\s *;" string))
@@ -606,7 +609,9 @@ This should usually be a combination of `inf-clojure-prompt' and
606
609
:package-version '(inf-clojure . " 2.0.0" ))
607
610
608
611
(defcustom inf-clojure-auto-mode t
609
- " When non-nil, automatically enable inf-clojure-minor-mode for all Clojure buffers."
612
+ " Automatically enable inf-clojure-minor-mode.
613
+ All buffers in `clojure-mode' will automatically be in
614
+ `inf-clojure-minor-mode' unless set to nil."
610
615
:type 'boolean
611
616
:safe #'booleanp
612
617
:package-version '(inf-clojure . " 3.1.0" ))
@@ -795,7 +800,7 @@ The name is simply the final segment of the path."
795
800
(file-name-nondirectory (directory-file-name dir)))
796
801
797
802
;;;### autoload
798
- (defun inf-clojure (cmd )
803
+ (defun inf-clojure (cmd &optional suppress-message )
799
804
" Run an inferior Clojure process, input and output via buffer `*inf-clojure*' .
800
805
If there is a process already running in `*inf-clojure*' , just
801
806
switch to that buffer.
@@ -809,6 +814,9 @@ and `inf-clojure-custom-startup' if those are set.
809
814
Use a prefix to prevent using these when they
810
815
are set.
811
816
817
+ Prints a message that it has connected to the host and port
818
+ unless SUPPRESS-MESSAGE is truthy.
819
+
812
820
Runs the hooks from `inf-clojure-mode-hook' (after the
813
821
`comint-mode-hook' is run). \( Type \\ [describe-mode] in the
814
822
process buffer for a list of commands.)"
@@ -833,12 +841,12 @@ process buffer for a list of commands.)"
833
841
(cmdlist (if (consp cmd)
834
842
(list cmd)
835
843
(split-string-and-unquote cmd)))
836
- (repl-type (or inf-clojure-socket-repl-type
837
- (unless prefix-arg
844
+ (repl-type (or (unless prefix-arg
838
845
inf-clojure-custom-repl-type)
839
- (car (rassoc cmd inf-clojure-startup-forms))
840
- (inf-clojure--prompt-repl-type))))
841
- (message " Starting Clojure REPL via `%s' ... " cmd)
846
+ (car (rassoc cmd inf-clojure-startup-forms))
847
+ (inf-clojure--prompt-repl-type))))
848
+ (unless suppress-message
849
+ (message " Starting Clojure REPL via `%s' ... " cmd))
842
850
(with-current-buffer (apply #'make-comint
843
851
process-buffer-name (car cmdlist) nil (cdr cmdlist))
844
852
(inf-clojure-mode)
@@ -849,14 +857,17 @@ process buffer for a list of commands.)"
849
857
(setq inf-clojure-buffer (get-buffer repl-buffer-name))
850
858
(if inf-clojure-repl-use-same-window
851
859
(pop-to-buffer-same-window repl-buffer-name)
852
- (pop-to-buffer repl-buffer-name))))
860
+ (pop-to-buffer repl-buffer-name))
861
+ repl-buffer-name))
853
862
854
- ;;;### autoload
855
- (defun inf-clojure-connect (host port )
863
+ ; ;;###autol
864
+ (defun inf-clojure-connect (host port &optional suppress-message )
856
865
" Connect to a running socket REPL server via `inf-clojure' .
857
- HOST is the host the process is running on, PORT is where it's listening."
866
+ HOST is the host the process is running on, PORT is where it's
867
+ listening. SUPPRESS-MESSAGE is optional and if truthy will
868
+ prevent showing the startup message."
858
869
(interactive " shost: \n nport: " )
859
- (inf-clojure (cons host port)))
870
+ (inf-clojure (cons host port) suppress-message ))
860
871
861
872
(defvar-local inf-clojure-socket-callback nil
862
873
" Used to transfer state between the socket process buffer & REPL buffer." )
@@ -882,12 +893,11 @@ OUTPUT is the latest data received from the process"
882
893
(insert output)))
883
894
(let ((prompt-displayed (string-match inf-clojure-prompt output)))
884
895
(when prompt-displayed
885
- (message (format " Socket REPL startup detected for %s " (process-name process)))
886
896
(with-current-buffer server-buffer
887
897
(when inf-clojure-socket-callback
888
898
(funcall inf-clojure-socket-callback)))))))
889
899
890
- (defun inf-clojure-socket-repl-sentinel (process event )
900
+ (defun inf-clojure-socket-repl-sentinel (process _event )
891
901
" Ensures socket REPL are cleaned up when the REPL buffer is closed.
892
902
893
903
PROCESS is the process object that is connected to a socket REPL.
@@ -917,11 +927,11 @@ If left as nil a random port will be selected between 5500-6000."
917
927
918
928
;;;### autoload
919
929
(defun inf-clojure-socket-repl (cmd )
920
- " Start a socket REPL server and connect to it via `inf-clojure' .
921
- CMD is the command line used to start the socket REPL, if this
922
- isn't provided you will be prompted to select from the defaults
923
- provided in `inf-clojure-socket-repl- startup-forms ' or
924
- `inf-clojure-custom- startup' if this is defined ."
930
+ " Start a socket REPL server and connects to it via `inf-clojure-connect ' .
931
+ CMD is the command line instruction used to start the socket
932
+ REPL. It should be a string with \" %d \" in it to take a random
933
+ port. Set `inf-clojure-custom- startup' or choose from the
934
+ defaults provided in `inf-clojure-socket-repl- startup-forms' ."
925
935
(interactive (list (or (unless current-prefix-arg
926
936
inf-clojure-custom-startup)
927
937
(completing-read " Select Clojure socket REPL startup command: "
@@ -937,13 +947,9 @@ provided in `inf-clojure-socket-repl-startup-forms' or
937
947
(inf-clojure--prompt-repl-type)))
938
948
(project-name (inf-clojure--project-name (or project-dir " standalone" )))
939
949
(socket-process-name (format " *%s -%s -socket-server* " project-name repl-type))
940
- (socket-buffer-name (format " *%s -%s -socket* " project-name repl-type))
941
- (socket-buffer (get-buffer-create socket-buffer-name))
942
- (repl-buffer-name (format " %s -%s -repl" project-name repl-type))
943
- (socket-form (or cmd
944
- (cdr (assoc repl-type inf-clojure-socket-repl-startup-forms))
945
- inf-clojure-custom-startup))
946
- (socket-cmd (format socket-form port))
950
+ (socket-buffer (get-buffer-create
951
+ (format " *%s -%s -socket* " project-name repl-type)))
952
+ (socket-cmd (format cmd port))
947
953
(sock (let ((default-directory (or project-dir default-directory)))
948
954
(start-file-process-shell-command
949
955
socket-process-name socket-buffer
@@ -952,19 +958,13 @@ provided in `inf-clojure-socket-repl-startup-forms' or
952
958
(setq-local
953
959
inf-clojure-socket-callback
954
960
(lambda ()
955
- (let ((with-process-repl-buffer-name (concat " *" repl-buffer-name " *" )))
956
- (setq inf-clojure-socket-repl-type
957
- repl-type
958
- inf-clojure-custom-repl-name
959
- repl-buffer-name
960
- repl-buffer
961
- (get-buffer-create with-process-repl-buffer-name))
962
- (inf-clojure-connect host port)
963
- (with-current-buffer with-process-repl-buffer-name
964
- (setq inf-clojure-socket-buffer socket-buffer))
965
- (set-process-sentinel
966
- (get-buffer-process (get-buffer with-process-repl-buffer-name))
967
- #'inf-clojure-socket-repl-sentinel )))))
961
+ (let* ((inf-clojure-custom-repl-type repl-type)
962
+ (created-repl-buffer (inf-clojure-connect host port :suppress-message )))
963
+ (with-current-buffer (get-buffer created-repl-buffer)
964
+ (setq-local inf-clojure-socket-buffer socket-buffer)
965
+ (set-process-sentinel
966
+ (get-buffer-process (current-buffer ))
967
+ #'inf-clojure-socket-repl-sentinel ))))))
968
968
(set-process-filter sock #'inf-clojure-socket-filter )
969
969
(message " Starting %s socket REPL server at %s :%d with %s " repl-type host port socket-cmd)))
970
970
0 commit comments