With a deps.edn project, is there a way to jack-in using a specific fixed nrepl port instead of the random one?
If you use the prefix argument key binding C-u before the biding to jack in i.e. C-u C-c C-x j j then add :port 56789 to the end of the command it should use the specified port number.
https://docs.cider.mx/cider/basics/up_and_running.html#customizing-the-jack-in-command-behavior
I was looking for a way to configure that part of the command, but changing it every time should work for now. Thanks!
You could override the jack-in command https://docs.cider.mx/cider/basics/up_and_running.html#override-the-jack-in-command to make it permanent ( look into adding the customization to a .dir-locals.el in the root of your project if you want different ports for different projects (the 'Setting project wide command' section shows that). That's not perfect as if you switch from project to project the .dir-locals.el would only be eval'ed on buffer revert or opening a new file buffer in the new project.
I haven't tried setting a port using the override but I think it would work.
yeah, maybe that works. I use .dir-locals.el in all my projects. I guess being able to customize the nrepl port could be a nice addition
I have a PR open for a similar feature for cider-connect https://github.com/clojure-emacs/cider/pull/3359 I find jack-in useful mostly for one-offs where you don't really care about the specific port number - if you need a stable port for other editors or tooling to connect to, it seems more sensible to launch it in an external terminal rather than an Emacs sub-process
and perhaps not helpful, but just so you know, you can specify an .nrepl.edn file in the directory to specify a port
https://nrepl.org/nrepl/usage/server.html#server-configuration
example provided is
{:bind "localhost"
:port 12345
:ack 23456
:handler some.ns/awesome-handler
:transport nrepl.transport/bencode}oh that's nice!
I'm trying to get a custom cider-jack-in-cmd to work, but it seems to hang CIDER. How does CIDER determine the command has finished booting up? I assumed it would check the nREPL port?
vague memory. but there’s a process filter watching the output of the nrepl server buffer that when it sees a phrase it fires a callback
(defun cider-repl-create (params)
"Create new repl buffer.
PARAMS is a plist which contains :repl-type, :host, :port, :project-dir,
:repl-init-function and :session-name. When non-nil, :repl-init-function
must be a function with no arguments which is called after repl creation
function with the repl buffer set as current."
;; Connection might not have been set as yet. Please don't send requests in
;; this function, but use cider--connected-handler instead.
(let ((buffer (or (plist-get params :repl-buffer)
(and cider-reuse-dead-repls
(cider--choose-reusable-repl-buffer params))
(get-buffer-create (generate-new-buffer-name "*cider-uninitialized-repl*"))))
(ses-name (or (plist-get params :session-name)
(cider-make-session-name params))))
(with-current-buffer buffer
(setq-local sesman-system 'CIDER)
(setq-local default-directory (or (plist-get params :project-dir) default-directory))
;; creates a new session if session with ses-name doesn't already exist
(sesman-add-object 'CIDER ses-name buffer 'allow-new)
(unless (derived-mode-p 'cider-repl-mode)
(cider-repl-mode))
(setq nrepl-err-handler #'cider-default-err-handler
;; used as a new-repl marker in cider-set-repl-type
mode-name nil
cider-session-name ses-name
nrepl-project-dir (plist-get params :project-dir)
;; Cljs repls are pending until they are upgraded. See cider-repl--state-handler
cider-repl-type (plist-get params :repl-type)
cider-repl-cljs-upgrade-pending (plist-get params :cider-repl-cljs-upgrade-pending)
;; ran at the end of cider--connected-handler
cider-repl-init-function (plist-get params :repl-init-function)
cider-launch-params params)
(when-let ((type (plist-get params :cljs-repl-type)))
(setq cider-cljs-repl-type type))
(cider-repl-reset-markers)
(add-hook 'nrepl-response-handler-functions #'cider-repl--state-handler nil 'local)
(add-hook 'nrepl-connected-hook #'cider--connected-handler nil 'local)
(add-hook 'nrepl-disconnected-hook #'cider--disconnected-handler nil 'local)
(current-buffer))))
this code here with the connected hooksand cider does it’s post connection stuff in cider--connected-handler i think
Thanks for the tip! I found where it's defined: https://github.com/clojure-emacs/cider/blob/master/nrepl-client.el#L1155
So in theory I just need to output "nREPL server started on..." with the port.
its been a while but i think so
Looks like it worked. Thanks for the help!
nice! glad you got it working