cider

2025-06-10T10:54:47.317929Z

With a deps.edn project, is there a way to jack-in using a specific fixed nrepl port instead of the random one?

agile_geek 2025-06-10T11:08:39.018209Z

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

2025-06-10T11:10:22.943089Z

I was looking for a way to configure that part of the command, but changing it every time should work for now. Thanks!

agile_geek 2025-06-10T11:15:12.342019Z

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.

agile_geek 2025-06-10T11:15:51.701849Z

I haven't tried setting a port using the override but I think it would work.

2025-06-10T11:17:37.099329Z

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

yuhan 2025-06-10T11:44:42.793639Z

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

💯 1
dpsutton 2025-06-10T13:18:15.074289Z

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}

2025-06-10T13:22:49.120159Z

oh that's nice!

weavejester 2025-06-10T15:45:25.800049Z

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?

dpsutton 2025-06-10T16:16:48.638639Z

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

dpsutton 2025-06-10T16:17:45.534199Z

(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 hooks

dpsutton 2025-06-10T16:19:36.927969Z

and cider does it’s post connection stuff in cider--connected-handler i think

weavejester 2025-06-10T18:56:57.917859Z

Thanks for the tip! I found where it's defined: https://github.com/clojure-emacs/cider/blob/master/nrepl-client.el#L1155

weavejester 2025-06-10T18:57:28.647329Z

So in theory I just need to output "nREPL server started on..." with the port.

dpsutton 2025-06-10T20:23:19.972219Z

its been a while but i think so

weavejester 2025-06-11T19:28:40.251879Z

Looks like it worked. Thanks for the help!

dpsutton 2025-06-11T19:29:17.317059Z

nice! glad you got it working