Fork me on GitHub
#calva
<
2022-04-06
>
Cora (she/her)02:04:07

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

pez04:04:59

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

pez14:04:33

According to https://calva.io/formatting/ 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

pez14:04:16

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

ericdallo14:04:30

maybe this issue should consider using clojure-lsp format as well 😅 https://github.com/BetterThanTomorrow/calva/issues/1498

pez14:04:12

Why would it, @UKFSJSM38?

pez14:04:02

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?

ericdallo14:04:22

@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-1)
        (do-1)

        (cond-2)
        (do-2)

        :always
        (do-3))

(cond-> value
  (cond-1)
  (do-1)

  (cond-2)
  (do-2)

  :always
  (do-3))

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

pez14:04:34

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 😅

ericdallo14:04:20

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

ericdallo14:04:47

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?

ericdallo14:04:54

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

ericdallo14:04:17

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

pez14:04:05

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

ericdallo14:04:05

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

pez14:04:06

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.

1
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

pez14:04:53

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

pez14:04:34

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

1
Cora (she/her)14:04:52

roger that, cap'n! o7

pez14:04:14

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

pez14:04:45

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

Cora (she/her)14:04:27

:remove-trailing-whitespace?

Cora (she/her)14:04:44

no that's not it either

pez14:04:53

Same. You can't target just comment blocks.

pez14:04:30

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.

ericdallo14:04:16

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

ericdallo14:04:35

I thought there was a issue there about that feature request

pez14:04:58

Yeah, would be surprised if there isn't.

pez15:04:12

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?

pez15:04:24

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?

pez15:04:33

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 😅

pez15:04:33

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

pez15:04:58

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

pez15:04:48

Cool. I am curious!

pez16:04:47

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

Thierry10:04:49

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.

Thierry10:04:09

hmm gonna check vscode, another shortcut doesnt work

pez10:04:47

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

Thierry10:04:53

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

Thierry10:04:45

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.

Thierry10:04:51

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

Thierry10:04:02

VSCode seems to ignore multiple keydown events

Thierry10:04:02

Here I press CTRL+ALT+C CTRL+ALT+J

Thierry10:04:07

[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.

Thierry10:04:50

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

Thierry10:04:55

CTRL ALT J seems to work

Thierry11:04:42

Found the issue, not sure why this wasnt there yesterday

Thierry11:04:01

Seems Windows overrides the shortcuts with certain keyboard layouts

Thierry11:04:26

definatly had the same config yesterday tho

pez11:04:05

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.

Thierry11:04:04

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

Thierry11:04:17

Theres actually an issue on the vscode github about this that pointed me in the right direction: https://github.com/microsoft/vscode/issues/68787

pez12:04:00

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

pez12:04:18

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
Thierry13:04:44

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.

pez15:04:12

Totally crazy.

Thierry17:04:08

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.

isak21:04:35

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
pez21:04:01

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.)

1
👍 2
isak21:04:30

Ok cool 🙂

oddsor08:04:42

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 🙈

pez08:04:04

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

sashton14:04:05

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.

pez14:04:42

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

isak14:04:08

Maybe you can use something like this (not tested) to record it and bind it to one keybind: https://marketplace.visualstudio.com/items?itemName=tshino.kb-macro

isak14:04:33

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

sashton14:04:00

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

pez15:04:29

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

sashton15:04:54

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

sashton15:04:35

those ideas worked perfectly, thanks!

😎 1
isak15:04:27

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

pez16:04:55

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.

rayat18:04:22

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

🙂 1
pez18:04:16

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. 😀

1