Fork me on GitHub
#cursive
<
2021-11-01
>
SK14:11:51

i! when using cursive for debugging, how to use the parameter of an anonymous function in intelliJ's "Evalute" window? I've tried using "%" but for that it says "unable to resolve %". In the "Variables" windows this parameter is listed as "p1--52131#" however it is not working with this name in the Evaluate window. Any ideas?

cfleming21:11:06

Hmm, good catch - I don’t think this is possible right now. I think you’d have to refactor your anonymous function to fn to do this.

indy19:11:38

I seem to have to explicitly switch to the ns for the REPL command to resolve the selection, maybe the Execute in original namespace setting is what I need but that is disabled for all commands except for when Re-execute last command is on. Can the Execute in original namespace also be allowed to be toggled on for other REPL commands?

onetom06:11:20

I, personally, don't really understand your question. Maybe that's why others hasn't reacted yet either. But it looks interesting what you are trying to do, so I would like to understand what are you up to. so this command would evaluate whatever text is selected. copies the prettified form of it into the clipboard. then returns the evaluation result. this much is clear. in other words, this command would behave, like the built-in Send Top Form to REPL or Send Form Before Caret to REPL, but also puts the prettified evaluation result into the clipboard.

indy06:11:09

Okay maybe a screen recording might help elaborate this convenience issue.

indy06:11:38

The convenience issue is that, I have to Switch REPL to current NS for my custom REPL command to work as expected otherwise it won’t resolve the var. This is in contrast to the usual Send Form to REPL commands. It’s only a convenience issue and not anything major, just wanted to highlight it.

onetom08:11:49

I was just thinking about a similar action this other day and had the idea of decomplecting the evaluation from the clipboard operation. I think regardless of which namespace you are evaluating something, clojure.repl/*{1,2,3} will be updated, so you could just have an operation, which puts the pretty-printed *1 into the clipboard.

onetom08:11:39

also, maybe u can utilize something like (in-ns ~file-namespace) yourself. i wonder if there is already something off the shelf, which can eval an expression within a namespace, without affecting *ns*... would (binding [*ns* ~file-namespace] ~selected-form) work?...

onetom08:11:30

for other readers benefit, these special ~something variables are documented here: https://cursive-ide.com/userguide/repl.html#repl-commands

onetom08:11:07

i just remembered that i've done something like this before

onetom08:11:37

end that Copy *1 to clipboard command was defined as ((requiring-resolve 'gini.clipboard/write) *1), where that clipboard/write fn was using java's built-in AWT, just to be cross-platform. but then i just discovered a few days ago, that such code is also available here: https://github.com/AvisoNovate/pretty/blob/master/src/io/aviso/clipboard.clj

onetom08:11:02

here is the code of the Open *1 in browser action, in case anyone wants to try:

(if (and (string? *1) (re-find #"^http|file" *1))
  ((requiring-resolve 'clojure.java.browse/browse-url) *1)
  (throw (ex-info "*1 was not a `file://` or `https?://` URL" {:*1 *1})))

indy13:11:21

Thanks @U086D6TBN, I’m going to try the binding suggestion or explore in that direction, which if it works will solve my exact problem. And TIL clojure.java.browse. Usually for dev things like browsing a URL or opening a certain type of file with the correct app on a mac, I’ll simply do (clojure.java.shell/sh "open" file-path) .

onetom13:11:07

I also work on macOS mostly, but trying to be cross-platform, so we can run the same code on Linux CI servers too.

👍 1
onetom13:11:40

I even have a direnv wrapper around clojure.java.shell/sh to make sure I have the same exact software on the path, regardless of the OS. I have an .envrc for every project, which has use nix , which ensures the environment I've declared in the shell.nix file in the same project directory.