7474(defvar inf-clojure-startup-forms '((lein . " lein repl" )
7575 (boot . " boot repl" )
7676 (clojure . " clojure" )
77- (cljs . " clojure -m cljs.main -r" )
77+ (cljs . " clojure -M - m cljs.main -r" )
7878 (lein-clr . " lein clr repl" )
7979 (planck . " planck -d" )
8080 (babashka . " bb" )
176176Its root binding is nil and it can be further customized using
177177either `setq-local` or an entry in `.dir-locals.el`." )
178178
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-
182179(defvar inf-clojure-buffer nil
183180 " The current `inf-clojure' process buffer.
184181
@@ -816,18 +813,19 @@ process buffer for a list of commands.)"
816813 (format " inf-clojure %s " (inf-clojure--project-name project-dir))
817814 " inf-clojure" )))
818815 ; ; 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)))
824817 ; ; Create a new comint buffer if needed
825818 (unless (comint-check-proc repl-buffer-name)
826819 ; ; run the new process in the project's root when in a project folder
827820 (let ((default-directory (or project-dir default-directory))
828821 (cmdlist (if (consp cmd)
829822 (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))))
831829 (message " Starting Clojure REPL via `%s' ... " cmd)
832830 (with-current-buffer (apply #'make-comint
833831 process-buffer-name (car cmdlist) nil (cdr cmdlist))
@@ -879,93 +877,68 @@ OUTPUT is the latest data received from the process"
879877 (funcall inf-clojure-socket-callback)))))))
880878
881879(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."
883883 (when (not (process-live-p process))
884884 (let ((repl-buffer (process-buffer process)))
885885 (with-current-buffer repl-buffer
886886 (when inf-clojure-socket-buffer
887887 (kill-buffer inf-clojure-socket-buffer))))))
888888
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" )
904895 (planck . " planck -n %s" )
905896 (babashka . " bb socket-repl %s" )))
906897
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+
907905;;;### autoload
908- (defun inf-clojure-socket ( &optional &rest args )
906+ (defun inf-clojure-socket-repl ( cmd )
909907 " 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" )))
950925 (socket-process-name (format " *%s -%s -socket-server* " project-name repl-type))
951926 (socket-buffer-name (format " *%s -%s -socket* " project-name repl-type))
952927 (socket-buffer (get-buffer-create socket-buffer-name))
953928 (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)))
960933 (start-file-process-shell-command
961934 socket-process-name socket-buffer
962935 socket-cmd))))
963936 (with-current-buffer socket-buffer
964937 (setq-local
965938 inf-clojure-socket-callback
966939 (lambda ()
967- (setq inf-clojure-custom -repl-type
968- ( intern repl-type)
940+ (setq inf-clojure-socket -repl-type
941+ repl-type
969942 inf-clojure-custom-repl-name
970943 ; ; comint mode includes the ** chars
971944 repl-buffer-name
@@ -978,7 +951,7 @@ or flags for your chosen tool. e.g `-Adev:test' for `clojure'"
978951 (get-buffer-process (get-buffer (concat " *" repl-buffer-name " *" )))
979952 #'inf-clojure-repl-sentinel ))))
980953 (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)))
982955
983956
984957(defun inf-clojure--forms-without-newlines (str )
@@ -1070,7 +1043,7 @@ Indent FORM. FORM is expected to have been trimmed."
10701043 (let ((clojure-process (inf-clojure-proc)))
10711044 ; ; ensure the repl buffer scrolls. See similar fix in CIDER:
10721045 ; ; 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)
10741047 (selected-window ))
10751048 (with-current-buffer (process-buffer clojure-process)
10761049 (comint-goto-process-mark )
0 commit comments