Fork me on GitHub
#cider
<
2023-07-31
>
Garrett Hopper02:07:33

Is it possible to link a Sesman REPL to a buffer rather than a session with multiple REPLs? Sesman browser:

CIDER Sessions:

  1: Project/example:localhost:62628
      linked-to: proj(~/Development/project/)  
        objects: *cider-repl %s(clj)*  *cider-repl %s(cljs:shadow)*  
I'd like to link a buffer directly to the cljs REPL only so evaluations aren't sent to both REPLs. (Context: Trying out hyperfiddle/electric, where both REPLs have to be in the same JVM process, however it'd be convenient to evaluate CLJS code inline without it erroring out on the JVM REPL)

vemv06:07:43

Perhaps you'd have luck by redefining this function to introduce an if :

(defun cider-repl-type-for-buffer (&optional buffer)
  "Return the matching connection type (clj or cljs) for BUFFER.
BUFFER defaults to the `current-buffer'.  In cljc buffers return
multi.  This function infers connection type based on the major mode.
For the REPL type use the function `cider-repl-type'."
  (with-current-buffer (or buffer (current-buffer))
    (cond
     ((derived-mode-p 'clojurescript-mode) 'cljs)
     ((derived-mode-p 'clojurec-mode) (if "<current directory is named my_project>" ;; <---------------
                                          'cljs
                                        'multi))
     ((derived-mode-p 'clojure-mode) 'clj)
     (cider-repl-type))))
Maybe we could introduce a defcustom, at some point Edit: a more idiomatic way of hacking this defun is to add-advice :filter-return , inspect the return value, modify it if it is 'multi

Garrett Hopper14:07:00

Perfect, thank you! 🙂

Garrett Hopper14:07:57

Here's what I ended up with:

(defcustom cider-clojurec-repl-type-override nil
  "Override the REPL type for the current buffer."
  :type '(choice (const :tag "None" nil)
                 (const :tag "Clojure" clj)
                 (const :tag "ClojureScript" cljs)
                 (const :tag "Multi" multi))
  :group 'cider)

(defun cider-set-clojurec-repl-type-override ()
  "Set REPL type override for the current clojurec buffer."
  (interactive)
  (let ((type (intern (completing-read "Set REPL type to: " '("nil" "clj" "cljs" "multi")))))
    (setq-local cider-clojurec-repl-type-override type)
    (message "Set REPL type override to %s" type)))

(defun cider-repl-type-for-buffer (&optional buffer)
  "Return the matching connection type (clj or cljs) for BUFFER.
BUFFER defaults to the `current-buffer'.  In cljc buffers return
multi.  This function infers connection type based on the major mode.
For the REPL type use the function `cider-repl-type'."
  (with-current-buffer (or buffer (current-buffer))
    (cond
     ((derived-mode-p 'clojurescript-mode) 'cljs)
     ((derived-mode-p 'clojurec-mode) (or cider-clojurec-repl-type-override 'multi))
     ((derived-mode-p 'clojure-mode) 'clj)
     (cider-repl-type))))

vemv17:07:38

Cheers. It looks like PR material to me 🙂 feel free to