This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-08
Channels
- # asami (22)
- # babashka (35)
- # beginners (4)
- # calva (76)
- # cider (7)
- # clj-on-windows (89)
- # clojure (30)
- # clojure-europe (25)
- # clojurescript (10)
- # conjure (46)
- # fulcro (13)
- # gratitude (5)
- # lambdaisland (4)
- # lsp (13)
- # malli (5)
- # membrane (6)
- # nbb (1)
- # off-topic (11)
- # re-frame (2)
- # releases (1)
- # shadow-cljs (45)
- # xtdb (4)
I guess there is no Calva Paredit: Copy Sexp Forward
command? I.e. using that keyboard shortcut you could copy the sexp into the clipboard but the original code stays intact.
Correct. There is no such command. What I do is that I run Select forward sexp, Copy, Cursor Undo in succession. So: shift+alt+right cmd+c cmd+u
. You can use #joyride to automate this. There are several ways. Two of which:
1. Place a function like this in your user_activate.cljs
script:
(defn copy-forward-sexp []
(p/do
(vscode/commands.executeCommand "paredit.selectForwardSexp")
(vscode/commands.executeCommand "editor.action.clipboardCopyAction")
(vscode/commands.executeCommand "cursorUndo")))
Then in keybindings.json
:
{
"key": "shift+ctrl+alt+right",
"command": "joyride.runCode",
"args": "(copy-forward-sexp)"
},
2. Or put the whole sequence in the keybinding:
{
"key": "shift+ctrl+alt+right",
"command": "joyride.runCode",
"args": "(require '[\"vscode\" :as vscode]) (p/do (vscode/commands.executeCommand \"paredit.selectForwardSexp\") (vscode/commands.executeCommand \"editor.action.clipboardCopyAction\") (vscode/commands.executeCommand \"cursorUndo\"))"
},
Just configured this and it works great! Just had to restart VSCode, which I didn't immediately realize. Thanks! I put this hint to my new blog post. 🙂
You shouldn't need to restart Calva for this. Evaluating the function in the Joyride REPL is the civilized way to do it. 😃 Or, if starting that REPL is inconvenient right there and then: Joyride: Run User Script... and select user_activate.cljs
(if that is where you put the function). The default activate script is designed to support reloading.
As for restarting VS Code. Generally each VS Code window is pretty isolated, so Developer: Reload Window is often enough, for less dynamic things than Joyride scripts.
Ah, good to know!
Damn. I thought I keep this blog post article open for a few days but I already have quite a lot of stuff there. I think I post this part 2
today, and start working with part 3
immediately. 🙂
I make a PDF conversion and send it to you in private chat for review, if that is not too much trouble. 🙂
Oh, no problem at all. And I don't think it needs a review per se, just that if there are some things I know how to do, that seems that you don't, I can let you know.
Yep. 🙂
How to configure in Calva so that when I e.g. ctrl+click some Clojure function (like range
) then Calva opens core.clj
file in another tab in editor and scrolls the editor view to show the (defn range ...
?
Ah. I'm on Linux. I investigate why it is not working. Thanks!
Hm. For some reason I can't make it work. In context help there is Go to Definition
/ Go to Declaration
, but VSCode says: No definition found for comment
(if trying in (comment ...
).
Maybe you haven't started the REPL with dependencies that Calva needs? There is a command Calva: Copy Jack-in Command Line ... something something, that will give you a command line that starts the REPL with the dependencies met. (Or use Jack-in.)
On Linux myself, and Ctrl
-`<click>` or <F12>
does as described through Go to Definition
command.
Repl connection is not required, but you do need clojure-lsp to be running.
Works now with:
@backend-calva-kari:
clj -M:dev:test:common:backend:calva:kari -i -C
and in deps.edn
:
;; Calva specific
:calva {:extra-deps {cider/cider-nrepl {:mvn/version,"0.28.5"}}
:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}
Happy it works! You mean you don't need that for CIDER, @U76D9RZRR?
Öö, what do you mean: I don't need that for CIDER?
Calva is really good. I didn't find any issues. I didn't find anything that is missing compared using IntelliJ/Cursive or Emacs/Cider (in short evaluation). I start using Calva in my Clojure programming, let's see if I can find anything that I miss in Cursive.
Having some troubles to customize my Leuven theme with VSCode / Calva. If you have information about this and want to help, see 🧵 🙂
So, I'd like to change some of the off-the-shelf colors of VSCode Leuven theme.
E.g. to change the colors of numbers and keywords.
In settings.json
perhaps edit something like this:
"[Leuven Light]": {
"enabled": true,
"rules": {
// different color for all constants
"property.readonly": "#dc93b4",
// make all symbol declarations bold and italic
"*.declaration": {"bold": true, "italic": true}
}
},
I'm not familiar with how to do this. Have you found this one? https://code.visualstudio.com/api/extension-guides/color-theme#syntax-colors
My favorite theme Shades of Purple has basically no features for Lisp dialects. I added this prop to my settings.json
to cover the basics. (... I keep meaning to add more detail and make a pull request for it. :face_with_peeking_eye:).
Choose Developer: Inspect Editor Tokens and Scopes
from the Command Palette for a floating window that lists the active scopes for wherever you move the cursor.
"editor.tokenColorCustomizations": {
"[Shades of Purple]": {
"textMateRules": [
{
"scope": "entity.name.variable.clojure",
"settings": {
"foreground": "#9EFFFF",
}
},
{
"scope": "entity.name.function.clojure",
"settings": {
"foreground": "#FFEE80",
}
},
{
"scope": "storage.control.clojure",
"settings": {
"foreground": "#FF9D00",
}
},
{
"scope": "entity.global.clojure",
"settings": {
"foreground": "#FAD000",
}
},
{
"scope": "meta.metadata.simple.clojure,meta.metadata.simple.clojure entity.name.variable.clojure",
"settings": {
"foreground": "#d09fff"
}
},
],
},
},
Thanks. I now managed to configure my VSCode/Calva pretty much the same look I have in my IntelliJ/Cursive:
I'm writing a blog post about VSCode evaluation, I give more detailed instructions there.
So, the look part has been tackled now. 🙂
How can I set up my project so I can easily switch between repl ports? I have a clj/cljs project, but it's a pain to manually switch between them Also, when I use the calva command to start a project for deps.edn + shadow-cljs, it fails to start the cljs repl because it doesn't have the dependencies inside shadow-cljs.edn. It's running as though all it has access to is the deps.edn dependencies. Does the deps.edn + shadow.cljs command not work?
This is a common culprit. If it is two projects you will have to use two VS Code windows, as a Calva instance only connects to one project at a time. https://calva.io/workspace-layouts/#one-folder-two-windows in the Calva docs for some pointers on how to set this up. I think it sucks a bit, so maybe this is what you are doing today?
The deps.edn + shadow-cljs sequence works. Though, since what it does is to start clojure
, and clojure
will not read shadow-cljs dependencies, you will not have those in your REPL. You could possibly use add-lib together with a custom Calva connect sequence to get this to work, but I say that without having tried it.
For the smoothest Calva experience with this, you should let shadow-cljs use deps.edn
for its dependencies. Then you can use the either the deps.edn + shadow-cljs, or the shadow+cljs project type. I recommend the latter. I've written an article about this here: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ and there is also a video on @danielamber2’s channel about it: https://www.youtube.com/watch?v=islMjv55cN8 Check out @sakalli’s comment there which beautifully summarizes what I try to say with all those words.
Thanks for the reply. I'm trying the approach you blogged aout but I'm getting this:
Could not locate shadow/cljs/devtools/cli__init.class, shadow/cljs/devtools/cli.clj or shadow/cljs/devtools/cli.cljc on classpath.
Even though I have clojurescript and shadow-cljs in deps
shadow-cljs
I did try deps + shadow-cljs as well
I set deps to true in shadow-cljs.edn and added this to my deps.edn
:shadow {:extra-deps {binaryage/devtools {:mvn/version "1.0.6"}
cljs-ajax/cljs-ajax {:mvn/version "0.8.4"}
thheller/shadow-cljs {:mvn/version "2.20.2"}
org.clojure/clojurescript {:mvn/version "1.11.54"}
thheller/shadow-devtools {:mvn/version "1.0.20170516"}}}
Some of those just cause that's what was in my shadow-cljs
You'll need to either move that dependency out in the main deps declaration or tell shadow-cljs to include that alias. Instead of :deps true
do :deps {:aliases [:shadow]}
(from memory, but something similar to this).
Oh alright, got it
Okay that is building. But how would I evaluate my .clj code? Would I need to explicitly have shadow-cljs use every dependency listed in deps.edn?
Your blog seems to say we will use the Clojure Repl now for clj files, but I just get missing dependency errors if I try to evaluate things on the backend
If you have other dependencies needed for the backend that is in aliases, you’ll need to add those to shadow-cljs.edn
Ah. So there's no way to switch between these repls where it will know which dependencies to use. You'll just have to use all of them in one repl or the other if you want to work on one codebase
I thought when it switched to clj mode it might use the repl that has the deps.edn stuff by default
I could've sworn I had that workflow before
It doesn't seem like I can list multiple aliases using this method. If I list more than one in the vector, none of them work
So I'm not able to include the other dependencies
That is very strange ... What do you get if you define it like so:
:deps {:aliases [:this :that]}
You should see this in the Jack-in window (here I am using my example project)
npx shadow-cljs -d cider/cider-nrepl:0.28.5 watch :app
shadow-cljs - config: /Users/pez/Projects/tests/shadow-w-backend/shadow-cljs.edn
shadow-cljs - starting via "clojure"
WARNING: Specified aliases are undeclared and are not being used: [:this :that]
And if, from the terminal, I do
clj -A:this:that
WARNING: Specified aliases are undeclared and are not being used: [:this :that]
Clojure 1.11.1
user=>
Which tells us that that message comes from clojure
.This is a common culprit. If it is two projects you will have to use two VS Code windows, as a Calva instance only connects to one project at a time. https://calva.io/workspace-layouts/#one-folder-two-windows in the Calva docs for some pointers on how to set this up. I think it sucks a bit, so maybe this is what you are doing today?
The deps.edn + shadow-cljs sequence works. Though, since what it does is to start clojure
, and clojure
will not read shadow-cljs dependencies, you will not have those in your REPL. You could possibly use add-lib together with a custom Calva connect sequence to get this to work, but I say that without having tried it.
For the smoothest Calva experience with this, you should let shadow-cljs use deps.edn
for its dependencies. Then you can use the either the deps.edn + shadow-cljs, or the shadow+cljs project type. I recommend the latter. I've written an article about this here: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ and there is also a video on @danielamber2’s channel about it: https://www.youtube.com/watch?v=islMjv55cN8 Check out @sakalli’s comment there which beautifully summarizes what I try to say with all those words.
I listened to Cognicast Episode 167: Peter Strömberg and Calva. It was pretty interesting.

If I manage to configure my VSCode+Calva setup as much the same look-and-feel and developer experience as my IntelliJ+Cursive and Emacs+Cider setup, I will write a blog post about Calva, a bit like: https://www.karimarttila.fi/clojure/2021/01/27/clojure-emacs-vs-cursive.html
Heh, nice to hear. 🙂
How about this one, did you read it? https://www.metosin.fi/blog/metosin-favorite-editors/
Blog post is ready: https://www.karimarttila.fi/clojure/2022/10/08/clojure-calva.html
Really good Clojure programming experience with VSCode/Calva. I think I start using it with my 4Clojure exercises to have more experience.
I'm happy you like it. Especially as you can make the comparisons. It was a long time since I used CIDER and I've only tried Cursive occasionally to figure out how something works there that I should consider for Calva.
I don't know if you have tried Calva's Getting Started REPL? (It's a command in VS Code/Calva.) I'm curious what you think about it.
Very nice article by the way. Good with some quality posts out there mentioning the Calva alternative.
And also curious how you will like #joyride. Did you consider trying this? https://clojurians.slack.com/archives/CBE668G4R/p1665219491504609?thread_ts=1665211348.936869&cid=CBE668G4R
@U76D9RZRR One thing I'd change: when you specify cider/cider-nrepl
you don't need to also specify nrepl/nrepl
as the former depends on the latter, so you ensure you get the appropriate version of the CIDER middleware.
@U0ETXRFEW I guess that's a note for you too, since Calva's jack-in specifies both (and does not need to).
What if there’s a new version of nrepl which we want Calva to use, but cider-nrepl doesn’t yet include that newer version? Maybe that situation would not occur or would rarely occur since I would imagine cider-nrepl would be updated to include the latest nrepl, although maybe there’s a gap sometimes. Also, maybe Calva would never have that need, and if it did, we could just add the nrepl dep back to the jack-in command.
FYI: the cider-nrepl
docs specifically show it used without nrepl/nrepl
so that's kinda where I was going with that: https://docs.cider.mx/cider-nrepl/usage.html#via-clj
I guess Bug can give us the definitive answer (I won't @ him since it's 3 am over there right now)
https://clojurians.slack.com/archives/CBE668G4R/p1665257954265159?thread_ts=1665257172.454249&cid=CBE668G4R => Thanks for the hint @U0ETXRFEW ! I cloned the repo and decided to do the exercises using VSCode/Calva to get familiarized with my new setup. 🙂

