Fork me on GitHub
Ahmed Hassan02:04:22

What is best way to create Evil Mode bindings of Cider keys?


so I'm doing an annoyingly complex dual build equivalent to

clj -m figwheel.main -bb serviceworker -b view
and the only way I can figure out how to do that in CIDER is cider-jack-in then inject
(do (use 'figwheel.main.api)
    (start {} "view" "serviceworker")
    (cljs-repl "view"))
is there away to avoid typing that do block into the REPL every time?


those are indeed the droids I'm looking for, thank you my good sir 🎩


I have two lein profiles that I use often while connecting to the repl using this function

(defun cider-jack-in-with-profile ()
    (letrec ((profile (read-string "Enter profile name: "))
             (lein-params (concat "with-profile +" profile " repl :headless")))
      (message "lein-params set to: %s" lein-params)
      (set-variable 'cider-lein-parameters lein-params)
      (cider-jack-in '())))
lets say Im using profile X, and now I want to connect with profile Y, whats the best way to the switch? is there a cider-jack-out where I can jack-in again with a new profile?


What's the proper workflow in cases when you have an error after you restart/reload your app using mount? An example:

user> (restart)
#error {
 :cause "Unable to resolve symbol: account-database in this context"
 [{:type clojure.lang.Compiler$CompilerException
   :message "Syntax error compiling at (app/model/session.clj:55:39)."
   :data #:clojure.error{:phase :compile-syntax-check, :line 55, :column 39, :source "app/model/session.clj"}
   :at [clojure.lang.Compiler analyze "" 6808]}
  {:type java.lang.RuntimeException
   :message "Unable to resolve symbol: account-database in this context"
   :at [clojure.lang.Util runtimeException "" 221]}]
 [[clojure.lang.Util runtimeException "" 221]
Reloadable Clojure REPL
user> (restart)
Syntax error compiling at (*cider-repl Projects/pollcro:localhost:43993(clj)*:597:7).
Unable to resolve symbol: restart in this context
user> (start)
Syntax error compiling at (*cider-repl Projects/pollcro:localhost:43993(clj)*:600:7).
Unable to resolve symbol: start in this context


After fixing an error, I can not (restart) this reply anymore due to the following error: > Unable to resolve symbol: restart in this context Is it always like this or am I doing something wrong with my REPL workflow? As a workaround, I cider-quit my REPL session and start it again but that's very annoying. It seems I can use mount/start after fixing an error:

user> (mount/start)
But it completely loses my user namespace scope, REPL doesn't see any of its methods + I can't send user namespace to repl because of the following error:
Syntax error compiling at (app/server_components/pathom.clj:1:1).
namespace 'app.model.session' not found
("src/main" "src/dev" "src/test")#function[expound.alpha/printer]nil#'user/start#'user/stop#'user/restartnil
That's what my looks like:
(ns user
    [ :as tools-ns :refer [set-refresh-dirs]]
    [expound.alpha :as expound]
    [clojure.spec.alpha :as s]
    [mount.core :as mount]
    ;; this is the top-level dependent component...mount will find the rest via ns requires
    [app.server-components.http-server :refer [http-server]]))

;; ==================== SERVER ====================
(set-refresh-dirs "src/main" "src/dev" "src/test")
;; Change the default output of spec to be more readable
(alter-var-root #'s/*explain-out* (constantly expound/printer))

(defn start
  "Start the web server"
  [] (mount/start))

(defn stop
  "Stop the web server"
  [] (mount/stop))

(defn restart
  "Stop, reload code, and restart the server. If there is a compile error, use:


  to recompile, and then use `start` once things are good."
  (tools-ns/refresh :after 'user/start))


can you recreate this with just clj or lein and see what happens?


just checked it - yes it works the same way if I just run it as standalone repl via clojure -A:dev -J-Dtrace -J-Dghostwheel.enabled=true


ah ok. so i'm not sure there's much CIDER can do here. seems your code is nuking vars so CIDER can't really rescue you


Thanks Dan. I'll keep on looking


I have to re-evaluate the broken file, then restart


@U0P7ZBZCK thank you so much! It worked!


Is there a way to define a custom function in the shadow.repl namespace to run automatically, i.e., shadow/watch for a couple of profiles + shadow/repl for a profile? Right now, in my Luminus template, when I start the repl, the following command is run:

/usr/local/bin/npx shadow-cljs -d nrepl:0.6.0 -d refactor-nrepl:2.5.0-SNAPSHOT -d cider/cider-nrepl:0.23.0 server
Given this, where do I specify a function to run automatically when the repl starts? I want to automate this behavior: 1. I connect to the shadow repl using cider-jack-in. 2. This shows the shadow.user> repl. 3. At the prompt I run: (do (shadow/watch :app) (shadow/watch :workspaces) (shadow/repl :workspaces)) to watch these two profiles and run the repl for one of them. How do I run this do automatically every time I connect with shadow?


That happens almost exactly if you cider jack in clojurescript and select shadow cljs


Ah you have two different watches. You could create a custom repl type


and then want to start a repl too on the workspace watch. Okay, how to create a custom repl type? @dpsutton