Fork me on GitHub
#cursive
<
2022-02-16
>
steveb8n02:02:26

Q: I’m often editing edn or clojure files and need to insert a uuid. I jump to the repl and call (UUID/randomUUID) then copy and paste. Could Cursive automate this so I can have a keybinding that inserts a fresh uuid at the cursor location?

Andrew13:02:19

how about a REPL command similar to this, with a keybinding assigned?

🙏 1
cfleming23:02:22

Nice solution! I’m also planning to allow REPL commands to insert the results in the editor, which would make that even slicker.

metal 2
steveb8n21:02:23

Thanks! I never would have figured that out. works great. will look forward to that new feature @U0567Q30W so that it’s 1 keystroke instead of 2

cjsauer19:10:21

Very late to this thread but there is also this plugin: https://plugins.jetbrains.com/plugin/8320-uuid-generator

onetom02:11:24

also, there is a /usr/bin/uuidgen on macOS by default. then u can also pipe it into pbcopy, if u want it on the clipboard (or as macOS calls it, Paste Board, hence *pb*copy) so u can have some shell command runner plugin, which does this on a keystroke. i usually just run such stuff from the built-in terminal (which i've bound to Cmd-2) i do miss the ability to copy the last REPL evaluation result into the clipboard though... that would be a great, reusable action!

cfleming02:02:43

The latest EAP, just out now, will allow you insert the results directly into the open editor, or also easily copy the result value (or both, if you’re really keen!): https://clojurians.slack.com/archives/C0744GXCJ/p1675908328557129

🎉 2
GGfpc10:02:07

Does cursive support inspecting data inside threaded macros or is adding a let the only way to see the intermediate state?

imre10:02:33

I'm not aware of a built-in way, but it would be nice

imre10:02:13

I usually do a tap thing in this case btw, like (-> foo :bar (doto tap>) :baz)

cfleming23:02:46

There’s no built-in solution for this at the moment, sorry.

👍 2
onetom02:11:09

there is https://github.com/philoskim/debux, which works on clojurescript too, but it's a bit too heavy-weight for my taste, so i've resorted to 1. have a live template definition, which types this for me: [our.company.common :refer :all] 2. then i add this to most of our NS forms 3. i defined a ? function, which pretty-prints any value (with puget.printer/cprint) and also returns it, so i can just drop it into threading forms i've originally called it probe, but ? doesn't seem to collide with anything so far and it's far easier to add and remove. it really feels akin to probing an electrical circuit with a multi-meter.

onetom02:11:31

this is the source code:

(defn probe
  ([x]
   ;; Print info about call-site
   (let [[_this-invokeStatic _this-invoke call-site]
         (-> (ex-info "" {}) .getStackTrace)]
     (println)
     (println "=== PROBE ===")
     (println " at" (.toString call-site)))
   (pp x)
   x)
  ([xform x]
   (probe (xform x))
   x))
i use that stack trace trickery to 1. ignore the stackelement of the probe function itself 2. print the top-most, relevant stack element in a format, which cursive can turn into a link in the REPL window that way i know where my probes are and quickly get to them, if i want to remove them.

onetom02:11:32

pp is just a little automation around picking between clojure.pprint and puget.printer:

(defmacro >stderr [& body] `(binding [*out* *err*] ~@body))

(def ^:private pretty-printer-fn
  "Delay loading the pretty-printer namespaces until they are actually used,
   to reduce process startup time."
  (delay (or #?(:clj (try (requiring-resolve 'puget.printer/cprint)
                          (catch Exception _)))
             pp/pprint)))

(defn pp
  "Pretty-print val, preferably in color, if the puget lib is available."
  ([val]
   (@pretty-printer-fn val))
  ([val opts-or-writer]
   (@pretty-printer-fn val opts-or-writer)))

kwladyka17:02:20

ava.lang.Throwable: Error handling response
java.lang.IndexOutOfBoundsException: Wrong line: 523. Available lines count: 100
 at com.intellij.openapi.editor.impl.LineSet.checkLineIndex (LineSet.java:200)
    com.intellij.openapi.editor.impl.LineSet.getLineStart (LineSet.java:181)
    com.intellij.openapi.editor.impl.DocumentImpl.getLineStartOffset (DocumentImpl.java:1017)
    cursive.testing.actions$annotate_test$reify__17591.compute (actions.clj:102)
    com.intellij.openapi.application.impl.ApplicationImpl.runReadAction (ApplicationImpl.java:841)
    cursive.testing.actions$annotate_test.invokeStatic (actions.clj:99)
    cursive.testing.actions$annotate_test.invoke (actions.clj:97)
    cursive.testing.actions$fn__17692.invokeStatic (actions.clj:219)
    cursive.testing.actions/fn (actions.clj:215)
    clojure.lang.MultiFn.invoke (MultiFn.java:229)
    cursive.testing.actions$test_handler$process__17725.invoke (actions.clj:298)
    cursive.testing.actions$test_handler$reify__17728.out (actions.clj:310)
    cursive.repl.nrepl$handler.invokeStatic (nrepl.clj:78)
    cursive.repl.nrepl$handler.invoke (nrepl.clj:61)
    cursive.repl.nrepl$start$reify__14845$fn__14853.invoke (nrepl.clj:141)
    cursive.repl.nrepl$start$reify__14845.run (nrepl.clj:140)
    com.intellij.openapi.application.impl.ApplicationImpl$1.run (ApplicationImpl.java:265)
    java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    java.util.concurrent.FutureTask.run (FutureTask.java:264)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run (Executors.java:668)
    java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run (Executors.java:665)
    java.security.AccessController.doPrivileged (AccessController.java:-2)
    java.util.concurrent.Executors$PrivilegedThreadFactory$1.run (Executors.java:665)
    java.lang.Thread.run (Thread.java:829)

	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:182)
	at cursive.logging$do_error.invokeStatic(logging.clj:60)
	at cursive.logging$do_error.invoke(logging.clj:59)
	at cursive.logging$do_log.invokeStatic(logging.clj:45)
	at cursive.logging$do_log.doInvoke(logging.clj:38)
	at clojure.lang.RestFn.invoke(RestFn.java:464)
	at cursive.repl$print_exception.invokeStatic(repl.clj:152)
	at cursive.repl$print_exception.invoke(repl.clj:150)
	at cursive.repl.nrepl$start$reify__14845$fn__14853.invoke(nrepl.clj:143)
	at cursive.repl.nrepl$start$reify__14845.run(nrepl.clj:140)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:265)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)
Unfortunately I can’t paste tests.

cfleming23:02:24

Does the name of your test file conflict with another test file in your project?

kwladyka13:02:57

no, at least I didn’t catch any

kwladyka13:02:21

but wait, probably you were right. I removed some extra code for debugging purpose and not I don’t have this errror

kwladyka13:02:35

this is huge code base old project

kwladyka17:02:09

tests work if run not in cursive

kwladyka17:02:05

although it works on another developer computer which use cursive too. I have the newest intellij and cursive stable version

kwladyka17:02:12

it is happening in 1 ns, for the specific code, but it is very regular simple code without nothing special.

souenzzo20:02:08

Anyone using cursive in a remote setup? Do REPL's run at local or at remote machine? https://www.jetbrains.com/help/idea/remote-development-starting-page.html

cfleming23:02:57

I don’t do this myself, but I’m also interested to know if anyone has tried this, and how well it worked.

souenzzo02:02:27

intellij/idea remote still do not work. tried via local network (wired) and it is too slow.

souenzzo02:02:46

I was not able to enable cursive plugin

souenzzo02:02:53

(because it is too slow)

souenzzo12:02:12

Ok @U0567Q30W, now in a fresh morning I did new tests: • Remote intellij works in small projects • I created a new file: deps.edn, it offers to install cursive. Accept & restart • After restart, even simple operations like show files in the project now are too slow/do not work • If i keep trying to use intellij (open menus, reboot ide, etc), it somehow autodisable cursive

souenzzo12:02:40

I would like to send you some logs but I didn't understand where is the logs. The one that I found is from the client, that feels useless.

souenzzo12:02:18

TLDR; you will need to explicitly support remote intellij 😕

souenzzo12:02:57

2022-02-17 09:24:42,106 [ 419019] INFO - e.plugins.DisabledPluginsState - Plugins to disable: [com.cursiveclojure.cursive]