Fork me on GitHub
Cora (she/her)02:04:07

I cannot for the life of me figure out how to influence calva's formatting


That’s not good. What have you tried? What do you want to influence about it?

Cora (she/her)14:04:10

I tried turning off Clojure > Format: Enable, Clojure > Format: Enable, tried configuring it via a .cljfmt.edn in the project, tried having clojure-lsp do the formatting

Cora (she/her)14:04:17

I can't get it to change what it's doing at all


According to Calva doesn't suport clojure-lsp doing the formatting. Just sayn 😃

Cora (she/her)14:04:12

yeeeaaaahhhh at that point I was just grasping at straws and didn't have time to look through the code to see what was up

Cora (she/her)14:04:25

but if there's a way to configure calva's indentation I cannot for the life of me figure out how

Cora (she/her)14:04:38

feel kind of slow 😬

Cora (she/her)14:04:05

I know I should just look at the code and debug it but


Curious at how you tried making clojiure-lsp doing the formatting?


maybe this issue should consider using clojure-lsp format as well 😅


Why would it, @UKFSJSM38?


Anyway, back to the issue. > I can't get it to change what it's doing at all What was it doing to begin with? What did you want it to do?


@U0ETXRFEW I see format as a feature that could have providers too, like from clojure-lsp, from Calva built-in system, from zprint etc

Cora (she/her)14:04:19

(cond-> value



(cond-> value



Cora (she/her)14:04:38

I want the former (to match intellij's, I think?) but it automatically formats to the latter

Cora (she/her)14:04:15

also it's removing whitespace at the end of comment blocks and I don't know how to disable that too

Cora (she/her)14:04:34

our team likes to leave the closing parens on a separate line


I don't think you can make cljfmt do that. (The comment block thing). Calva let's you do it while you are in the comment block, but then can't really do anything about the case when the file is formatted.

Cora (she/her)14:04:06

so the struggle here is that this creates churn when a team is using multiple editors 😞

Cora (she/her)14:04:33

me: I'd like this to be different also me, internally: I should just fix this 😅


At Nubank we solved that with a common library exporting a clojure-lsp config which say how format should behave


so instead of just allowing a config file for a project clojure-lsp provides a way to find the config in classpath, which is included our lib (nubank/codestyle)

Cora (she/her)14:04:32

so you'd need to disable format-on-save in the file and then ... have clojure-lsp format it somehow?


AFAIK Calva now supports using clojure-lsp formatting rules asking for clojure-lsp the config, right @U0ETXRFEW? If so, that would work properly


you could configure the formatting on clojure-lsp side and calva would just use it when calling cljfmt manually


Yes, Calva suports picking up the config from clojure-lsp.


So besides your issue with trailing ) , I can't see why changing the cond indentation rule is not possible


But what @U02N27RK69K describes about cond-> formatting sounds like a bug in how the config is applied, so it wouldn't matter where it comes from.

Cora (she/her)14:04:07

I need to try it again this morning with my brain fresh. I'll be able to do it in like 20m


Report it as an issue, @U02N27RK69K. I really don't get why it wouldn't work, but it should.

Cora (she/her)14:04:17

for sure, let me try it out again and see if I can't get it working this morning

Cora (she/her)14:04:28

I was just expression frustration last night but that's on me


As for the trailing comment paren, that's a feature request rather than a bug. 😃

Cora (she/her)14:04:52

roger that, cap'n! o7


And I think the feature request should go on cljfmt. We would have to do quite hacky-ish things trying to do it some other way.

Cora (she/her)14:04:08

it seems like :remove-surrounding-whitespace? should do it?

Cora (she/her)14:04:16

I'll have to play with it


Well, that would do it for all surrounding whitespace. Probably not what your team wants. 😃

Cora (she/her)14:04:27


Cora (she/her)14:04:44

no that's not it either


Same. You can't target just comment blocks.


What we do with the ”inside comment” formatting is to place a symbol before the closing paren, then format, then remove the symbol. We could consider doing something similar on a global level, but I have a feeling it would get messy.


yeah, sounds like something to be configured on cljfmt side indeed


I thought there was a issue there about that feature request


Yeah, would be surprised if there isn't.


I also think that a team should be able to unify around some greatest common denominator. Cursive doesn't support some formatting wishes, cljfmt doesn't suport others. That's unfortunate, but rather than create churn, chose the closest you can get to people wishes. It will probably boil down to folded comment forms and funny looking ns forms, but maybe the team can live with that?


Given that we fix the bug with the config management, of course. But that should be a quick fix... wait ... I just realized something. When you tried get the cond-> to format differently, did you do it with a string? Like

:indents {"cond->" [[:block 0]]}

Cora (she/her)15:04:23

no, but I'm not even sure it was picking up the config

Cora (she/her)15:04:29

should it be picking up .cljfmt.edn?


I don't know without checking, and I'm not at my dev computer. But according to the Calva docs there is no default file Calva is using. It instructs to configure calva.fmt.configPath.

Cora (she/her)15:04:57

ahhhh ok, that might be a reason for it not finding it then 😅


(And this is where you can set the value CLOJURE-LSP to make Calva pick up the config from there.)


I still think we have a bug when using strings for the pattern. We merge the default config with the custom one. And then the symbol and the string are both still there and it will be a bit random which one will be used. So I am guessing

:indents {cond-> [[:block 0]]}
Will work more reliably. If that works differently. Then my hunch is correct, and then I think I know how to fix it for strings, but for regexes I actually don't know... Hmmm, an interesting case. I hope it is all just happening in my head and that maybe cljfmt has some way to handle this.

Cora (she/her)15:04:24

harumph, can't test rn but will later today

Cora (she/her)15:04:42

in like 1.5 hours or so


Cool. I am curious!


Tested it now. I was right, unfortunately. But to some extent we can document our way around this for now.


What could be the cause of paredit shortcuts suddenly not working anymore? They did yesterday. Calva is enabled and so is paredit strict mode, which I always use. Except when I press CTRL+C CTRL+J jackin doesnt come up i get the © 😞 no other paredit command works. Jack in works fine from menu tho.


hmm gonna check vscode, another shortcut doesnt work


There is a Calva shortcuts kill-switch as well. Even if I doubt that's the issue. But you could check your settings:


Not it unfortunately. Some VSCode shortcut I made doesnt work either.


It's not paredit either, that seems to work. [2022-04-06 12:36:05.299] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [], code: Backspace, keyCode: 8, key: Backspace [2022-04-06 12:36:05.299] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: Backspace, keyCode: 1 ('Backspace') [2022-04-06 12:36:05.299] [renderer1] [info] [KeybindingService]: | Resolving Backspace [2022-04-06 12:36:05.299] [renderer1] [info] [KeybindingService]: \ From 2 keybinding entries, matched paredit.deleteBackward, when: calva:keybindingsEnabled && editorTextFocus && !calva:cursorInComment && !editorHasMultipleSelections && !editorReadOnly && editorLangId == 'clojure' && paredit:keyMap == 'strict', source: user extension betterthantomorrow.calva.


What I am missing tho is the message in the bottom vscode bar when you press a shortcut.


VSCode seems to ignore multiple keydown events




[2022-04-06 12:44:21.208] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 17, key: Control [2022-04-06 12:44:21.228] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlLeft, keyCode: 5 ('Ctrl') [2022-04-06 12:44:21.228] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. [2022-04-06 12:44:21.368] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,alt], code: AltLeft, keyCode: 18, key: Alt [2022-04-06 12:44:21.369] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,alt], code: AltLeft, keyCode: 6 ('Alt') [2022-04-06 12:44:21.369] [renderer1] [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase. [2022-04-06 12:44:21.704] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [], code: KeyC, keyCode: 67, key: © [2022-04-06 12:44:21.705] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [], code: KeyC, keyCode: 33 ('C') [2022-04-06 12:44:21.705] [renderer1] [info] [KeybindingService]: | Resolving C [2022-04-06 12:44:21.705] [renderer1] [info] [KeybindingService]: \ From 1 keybinding entries, no when clauses matched the context. [2022-04-06 12:44:22.098] [renderer1] [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl,alt], code: KeyJ, keyCode: 74, key: j [2022-04-06 12:44:22.098] [renderer1] [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl,alt], code: KeyJ, keyCode: 40 ('J') [2022-04-06 12:44:22.099] [renderer1] [info] [KeybindingService]: | Resolving ctrl+alt+J [2022-04-06 12:44:22.099] [renderer1] [info] [KeybindingService]: \ No keybinding entries. [2022-04-06 12:44:22.313] [renderer1] [info] [KeybindingService]: + Ignoring single modifier ctrl due to it being pressed together with other keys.


The moment I add the C to CTRL + ALT it switches to just C


CTRL ALT J seems to work


Found the issue, not sure why this wasnt there yesterday


Seems Windows overrides the shortcuts with certain keyboard layouts


definatly had the same config yesterday tho


Weird. And the whole shortcuts thing is weird and full of conflicts. Glad you found the cause, though! And thanks for reporting back. This might be starting to happen for a lot of users.


You're welcome. Changing the keyboard to 'US Keyboard' layout solved it. Still weird that it worked fine yesterday on US International.


Theres actually an issue on the vscode github about this that pointed me in the right direction:


Sometimes there is a keyboard shortcut for switching keyboard layouts. Maybe you pressed it?


As for that issue. We used to have just alt+ in Calva, until we realized that for some layouts that produced accented characters. Some years ahead I see jack-in being ctrl+alt+shift+fn+cmd+c ctrl+alt+shift+fn+cmd+j...

😰 1

Didnt press the keyboard layout switch. I had 2 languages defined with the same keyboard layout. I had to add the US one to fix this.


Totally crazy.


What's even more crazy is that later this afternoon I switched back to my normal keyboard layout and eveything still worked. Removed all separate layouts etc, all other languages and it still works.


In Calva I notice the kill commands don't place what is killed on the clipboard like other editors (Cursive / Emacs). Is that an intentional difference?

😃 1

Yes, intentional. VS Code is not Emacs. 😄 Seriously, I, for one, want to be able to kill stuff without trashing my clipboard. All is not lost though, there is a setting calva.paredit.killAlsoCutsToClipboard that adds this behaviour. (No kill-ring, though, just latest killed thing is written to the clipboard.)

👍 2

Ok cool 🙂


Glad this option exists, earlier I made a semi-functional macro that copied a form before deleting and bound it to the kill-hotkey! I for one do want my clipboard thrashed 🙈


I use the select commands and then cut, when I want that to happen.


Speaking of kill_ commands, is there a single command to delete the enclosing form? Until recently, I was using the vim extension to do this via vim keys:`da(` . But, due to extension conflicts I got rid of the vim ext, so now I’m looking for a good replacement command.


There is no command for that. But with two commands you can do it: Forward up sexp, Kill sexp backward. So with default keybindings ctrl+alt+down ctrl+alt+backspace. Or Expand selection x 2, then delete the selection, Default keybindings on mac ctrl+w ctrl+w backspace


Maybe you can use something like this (not tested) to record it and bind it to one keybind:


Actually that one looks a little wrong, but I'm sure an extension exists to easily combine commands


those both sound like good suggestions, I’ll try it out


Do you delete the enclosing form often? I don't think I do...


yeah, if i’ve included debugging stuff, printlns, etc


those ideas worked perfectly, thanks!

😎 1

Ah youre right, that is common, I'll will add that myself


I include debugging stuff all the time. Maybe I delete the enclosing form often, but just not think about it... Hmmm, so if I add (println "BOOM!") and then want to remove it. I don't think I first enter the form and then remove it. I just remove it with Kill sexp forwards/backwards.


Tbh I think I'd use a kill sexp/form now that I've read about it in this thread haha

🙂 1

The enclosing one? It's easy to add. I’d merge a PR. Especially if it comes from someone who hasn't contributed to the repo before. 😀