74
74
(defvar inf-clojure-startup-forms '((lein . " lein repl" )
75
75
(boot . " boot repl" )
76
76
(clojure . " clojure" )
77
- (cljs . " clojure -m cljs.main -r" )
77
+ (cljs . " clojure -M - m cljs.main -r" )
78
78
(lein-clr . " lein clr repl" )
79
79
(planck . " planck -d" )
80
80
(babashka . " bb" )
176
176
Its root binding is nil and it can be further customized using
177
177
either `setq-local` or an entry in `.dir-locals.el`." )
178
178
179
- (defvar-local inf-clojure-repl-name nil
180
- " When creating a REPL, set the name to be given to the buffer it's output is sent to." )
181
-
182
179
(defvar inf-clojure-buffer nil
183
180
" The current `inf-clojure' process buffer.
184
181
@@ -816,18 +813,19 @@ process buffer for a list of commands.)"
816
813
(format " inf-clojure %s " (inf-clojure--project-name project-dir))
817
814
" inf-clojure" )))
818
815
; ; comint adds the asterisks to both sides
819
- (repl-buffer-name (format " *%s * " process-buffer-name))
820
- (repl-type (or (unless prefix-arg
821
- inf-clojure-custom-repl-type)
822
- (car (rassoc cmd inf-clojure-startup-forms))
823
- (inf-clojure--prompt-repl-type))))
816
+ (repl-buffer-name (format " *%s * " process-buffer-name)))
824
817
; ; Create a new comint buffer if needed
825
818
(unless (comint-check-proc repl-buffer-name)
826
819
; ; run the new process in the project's root when in a project folder
827
820
(let ((default-directory (or project-dir default-directory))
828
821
(cmdlist (if (consp cmd)
829
822
(list cmd)
830
- (split-string-and-unquote cmd))))
823
+ (split-string-and-unquote cmd)))
824
+ (repl-type (or inf-clojure-socket-repl-type
825
+ (unless prefix-arg
826
+ inf-clojure-custom-repl-type)
827
+ (car (rassoc cmd inf-clojure-startup-forms))
828
+ (inf-clojure--prompt-repl-type))))
831
829
(message " Starting Clojure REPL via `%s' ... " cmd)
832
830
(with-current-buffer (apply #'make-comint
833
831
process-buffer-name (car cmdlist) nil (cdr cmdlist))
@@ -879,93 +877,68 @@ OUTPUT is the latest data received from the process"
879
877
(funcall inf-clojure-socket-callback)))))))
880
878
881
879
(defun inf-clojure-repl-sentinel (process event )
882
- " This function is called on update change, it is mainly used to ensure the socket a REPL was connected to is cleaned up when the REPL buffer is closed."
880
+ " This function is called on update change, it is mainly used to
881
+ ensure the socket a REPL was connected to is cleaned up when the
882
+ REPL buffer is closed."
883
883
(when (not (process-live-p process))
884
884
(let ((repl-buffer (process-buffer process)))
885
885
(with-current-buffer repl-buffer
886
886
(when inf-clojure-socket-buffer
887
887
(kill-buffer inf-clojure-socket-buffer))))))
888
888
889
- (defvar inf-clojure-socket-forms
890
- `((lein . (concat " JVM_OPTS='-Dclojure.server.repl="
891
- " {:port %s :accept clojure.core.server/repl}' lein repl" ))
892
- (boot . (concat " export BOOT_JVM_OPTIONS='-Dclojure.server.repl="
893
- " \" {:port %s :accept clojure.core.server/repl}\" ' boot repl" ))
894
- (clojure . ,(concat
895
- " clojure"
896
- " -J-Dclojure.server.repl="
897
- " \" {:port %s :accept clojure.core.server/repl}\" " ))
898
- (cljs . ,(concat
899
- " clojure"
900
- " -J-Dclojure.server.repl="
901
- " \" {:port %s :accept clojure.core.server/repl}\" " ))
902
- (lein-clr . ,(concat " JVM_OPTS='-Dclojure.server.repl="
903
- " {:port %s :accept clojure.core.server/repl}' lein clr repl" ))
889
+ (defvar inf-clojure-socket-repl-startup-forms
890
+ '((lein . " JVM_OPTS='-Dclojure.server.repl={:port %s :accept clojure.core.server/repl}' lein repl" )
891
+ (boot . " export BOOT_JVM_OPTIONS='-Dclojure.server.repl=\" {:port %s :accept clojure.core.server/repl}\" ' boot repl" )
892
+ (clojure . " clojure -J-Dclojure.server.repl=\" {:port %s :accept clojure.core.server/repl}\" " )
893
+ (cljs . " clojure -J-Dclojure.server.repl=\" {:port %s :accept cljs.server.browser/repl}\" " )
894
+ (lein-clr . " JVM_OPTS='-Dclojure.server.repl={:port %s :accept clojure.core.server/repl}' lein clr repl" )
904
895
(planck . " planck -n %s" )
905
896
(babashka . " bb socket-repl %s" )))
906
897
898
+ (defcustom inf-clojure-socket-repl-port
899
+ nil
900
+ " Port to be used when creating a socket REPL via
901
+ `inf-clojure-socket-repl' . If left as nil a random port will be
902
+ selected between 5500-6000."
903
+ :type '(choice integer (const nil )))
904
+
907
905
;;;### autoload
908
- (defun inf-clojure-socket ( &optional &rest args )
906
+ (defun inf-clojure-socket-repl ( cmd )
909
907
" Starts a socket REPL server and connects to it via `inf-clojure' .
910
- ARGS are optional, in the case where PORT is not chosen one is
911
- randomly selected between 5500 and 6000. The default for
912
- REPL-TYPE is clojure. If you are inside a project, `inf-clojure-socket' will always run in the project directory.
913
-
914
- ARGS must come in pairs ATTRIBUTE VALUE.
915
-
916
- The following attributes are recognized:
917
-
918
- `:host'
919
-
920
- VALUE must be a string specifying the address that the socket is using. By default it is `localhost'
921
-
922
- `:port'
923
-
924
- VALUE must be a number specifying the port for the socket to listen.
925
-
926
- `:repl-type'
927
-
928
- VALUE must be a valid repl type, given as a string e.g clojure/cljs/lein/babashka. Note that `joker' and `lumo' are not supported.
929
-
930
- `:project-name'
931
-
932
- VALUE can be any string, by default this is either derived from your current directory if you are inside a project or `standalone'
933
-
934
- `:opts'
935
-
936
- VALUE can be any string, by default this is nil and nothing is
937
- added to the startup form is chosen according to your
938
- `repl-type' . This is useful when you want to add some arguments
939
- or flags for your chosen tool. e.g `-Adev:test' for `clojure' "
940
-
941
- (interactive )
942
- (setq args (purecopy args)) ; ; not sure if purecopy is useful, set-face-attribute does it.
943
- (let* ((host (or (plist-get args :host ) " localhost" ))
944
- (port (or (plist-get args :port ) (+ 5500 (random 500 ))))
945
- (repl-type (or (plist-get args :repl-type ) " clojure" ))
946
- (opts (plist-get args :opts ))
947
- (project-name (or (plist-get args :project-name )
948
- (inf-clojure--project-name (or (clojure-project-dir)
949
- " standalone" ))))
908
+ CMD is the command line used to start the socket REPL, if this
909
+ isn't provided you will be prompted to select from the defaults
910
+ provided in `inf-clojure-socket-repl-startup-forms' or
911
+ `inf-clojure-custom-startup' if this is defined."
912
+ (interactive (list (or (unless current-prefix-arg
913
+ inf-clojure-custom-startup)
914
+ (completing-read " Select Clojure REPL startup command: "
915
+ (mapcar #'cdr inf-clojure-socket-repl-startup-forms)
916
+ nil
917
+ 'confirm-after-completion ))))
918
+ (let* ((host " localhost" )
919
+ (port (or inf-clojure-socket-repl-port (+ 5500 (random 500 ))))
920
+ (repl-type (or (unless prefix-arg
921
+ inf-clojure-custom-repl-type)
922
+ (car (rassoc cmd inf-clojure-socket-repl-startup-forms))
923
+ (inf-clojure--prompt-repl-type)))
924
+ (project-name (inf-clojure--project-name (or (clojure-project-dir) " standalone" )))
950
925
(socket-process-name (format " *%s -%s -socket-server* " project-name repl-type))
951
926
(socket-buffer-name (format " *%s -%s -socket* " project-name repl-type))
952
927
(socket-buffer (get-buffer-create socket-buffer-name))
953
928
(repl-buffer-name (format " %s -%s -repl" project-name repl-type))
954
- (socket-form (cdr (assoc (intern repl-type) inf-clojure-socket-forms)))
955
- (socket-cmd (apply 'concat
956
- (format socket-form (number-to-string port))
957
- (when opts `(" " , opts ))))
958
- (sock (let ((default-directory (or (clojure-project-dir)
959
- default-directory)))
929
+ (socket-form (or (cdr (assoc repl-type inf-clojure-socket-repl-startup-forms))
930
+ inf-clojure-custom-startup))
931
+ (socket-cmd (format socket-form (number-to-string port)))
932
+ (sock (let ((default-directory (or (clojure-project-dir) default-directory)))
960
933
(start-file-process-shell-command
961
934
socket-process-name socket-buffer
962
935
socket-cmd))))
963
936
(with-current-buffer socket-buffer
964
937
(setq-local
965
938
inf-clojure-socket-callback
966
939
(lambda ()
967
- (setq inf-clojure-custom -repl-type
968
- ( intern repl-type)
940
+ (setq inf-clojure-socket -repl-type
941
+ repl-type
969
942
inf-clojure-custom-repl-name
970
943
; ; comint mode includes the ** chars
971
944
repl-buffer-name
@@ -978,7 +951,7 @@ or flags for your chosen tool. e.g `-Adev:test' for `clojure'"
978
951
(get-buffer-process (get-buffer (concat " *" repl-buffer-name " *" )))
979
952
#'inf-clojure-repl-sentinel ))))
980
953
(set-process-filter sock #'inf-clojure-socket-filter )
981
- (message " Starting socket server at %s :%s with ' %s ' " host port socket-cmd)))
954
+ (message " Starting %s socket REPL server at %s :%s with %s " repl-type host port socket-cmd)))
982
955
983
956
984
957
(defun inf-clojure--forms-without-newlines (str )
@@ -1070,7 +1043,7 @@ Indent FORM. FORM is expected to have been trimmed."
1070
1043
(let ((clojure-process (inf-clojure-proc)))
1071
1044
; ; ensure the repl buffer scrolls. See similar fix in CIDER:
1072
1045
; ; https://github.com/clojure-emacs/cider/pull/2590
1073
- (with-selected-window (or (get-buffer-window ( inf-clojure-buffer) )
1046
+ (with-selected-window (or (get-buffer-window inf-clojure-buffer)
1074
1047
(selected-window ))
1075
1048
(with-current-buffer (process-buffer clojure-process)
1076
1049
(comint-goto-process-mark )
0 commit comments