Fork me on GitHub
#cider
<
2020-04-28
>
Ahmed Hassan02:04:22

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

unbalanced13:04:22

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?

unbalanced16:04:11

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

plins17:04:53

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

(defun cider-jack-in-with-profile ()
    (interactive)
    (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?

nick18:04:22

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"
 :via
 [{: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 "Compiler.java" 6808]}
  {:type java.lang.RuntimeException
   :message "Unable to resolve symbol: account-database in this context"
   :at [clojure.lang.Util runtimeException "Util.java" 221]}]
 :trace
 [[clojure.lang.Util runtimeException "Util.java" 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

nick18:04:29

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)
{:started
 ["#'app.server-components.config/config"
  "#'app.model.database/pool"
  "#'app.model.mock-database/conn"]}
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 https://github.com/fulcrologic/fulcro-template/blob/master/src/dev/user.clj looks like:
(ns user
  (:require
    [clojure.tools.namespace.repl :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:

  (tools-ns/refresh)

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

dpsutton19:04:08

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

nick04:04:16

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

dpsutton04:04:01

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

nick09:04:51

Thanks Dan. I'll keep on looking

tvaughan12:04:55

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

nick16:04:34

@U0P7ZBZCK thank you so much! It worked!

Spaceman22:04:52

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?

dpsutton23:04:51

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

dpsutton23:04:56

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

Spaceman23:04:19

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