Fork me on GitHub
#calva
<
2023-03-30
>
Dustin Getz19:03:19

Anyone know how to make deleteWordLeft work in clojure files? It works in .html files for me but in clj files it deletes 1 char

pez19:03:22

Calva binds alt+backspace to force delete backwards, so that you can override strict mode when it prevents you from deleting something. You basically have three options: 1. Move force-delete to some other keybinding, 2. Move deleteWordLeft to some other keybinding. 3. Be content with Calva’s delete form backwards, which is default bound to ctrl+alt+backspace. Here are keybindings for option 2:

{
        "key": ", backspace",
        "command": "deleteWordLeft",
        "when": "textInputFocus && !editorReadonly && editorLangId == 'clojure'"
    },
    {
        "key": "alt+backspace",
        "command": "-deleteWordLeft",
        "when": "textInputFocus && !editorReadonly"
    },
    {
        "command": "default:type",
        "key": ", ,",
        "args": {
            "text": ","
        },
        "when": "editorTextFocus && editorLangId == clojure"
    },
Moving deletWordLeft to the slightly more inconvenient [Comma] backspace sequence. Since 3 makes it a bit rarer that we need deleting based on words. Note that there’s also a bindning for typing an actual comma.

Dustin Getz20:03:29

how about editing inside strings and comments?

Dustin Getz20:03:22

What are the consequences of moving Calva's force-delete-backwards somewhere else? I assume you have a great reason for putting it on that specific chord

Dustin Getz20:03:55

What is: "so that you can override strict mode when it prevents you from deleting something."

pez20:03:15

See https://calva.io/paredit/ about strict mode. Most often it is fine, but in some situations it gets in the way. E.g. When there is unbalance, but Calva fails to recognize it.

Dustin Getz20:03:48

"strict mode" is a calva concept or a vscode concept?

pez20:03:00

It’s a Paredit concept.

👍 2
pez20:03:41

You can move Calva’s force-delete away without consequences as long as you remember where you move it. 😃

pez20:03:39

Calva adds some contexts you can use in the when clause for more precision. Like so:

{
        "command": "default:type",
        "key": ", ,",
        "args": {
            "text": ","
        },
        "when": "editorTextFocus && editorLangId == clojure && !calva:cursorInComment && !calva:cursorInString"
    },

pez20:03:11

You can leave Calva’s force delete unbound and use it from the command palette. You can also select the thing you want to delete and then hit backspace.

Dustin Getz20:03:21

ok i unmapped force-delete from calva and now alt-backspace works - however now alt-backspace can damage sexpr, is there a way to prevent that?

pez20:03:46

I don’t think there is. Strict mode is limited to single char deletes.

Dustin Getz20:03:23

I dont think i turned strict mode off, so iiuc it should have prevented the damage?

pez20:03:50

Strict mode only watches single char deletes. You still have it on for that, but if you tell vscode to delete the word to the left, it will do so without consulting Calva about it.

👍 2
pez20:03:35

You can always file a feature request about a pareditDeleteWordBackward command. Shouldn’t be too hard to add.

Dustin Getz20:03:39

I am looking for documentation for paredit, am I supposed to be on the emacs docs?

pez20:03:07

Calva’s Paredit is documented at the link I posted above.

Dustin Getz20:03:34

hmm ok, it doesn't define strict mode it just says it exists

pez20:03:21

I’d say it defines what it means by it. Not following.

Dustin Getz20:03:08

i think my question is: I don't have a mental model over the calva architecture and all the modules that are running (paredit, lsp etc) and I'm not sure which products I should be on the third party documentation

Dustin Getz20:03:39

googling paredit gets me here, is this the right page to understand how paredit works in calva?

Dustin Getz20:03:50

like concept definitions, etc

pez20:03:16

Calva’s Paredit is part of Calva. Emacs Paredit is only an inspiration.

pez20:03:56

I’m not aware of any formal definition of it. It goes back to old Symbolics LISP machines and even beyond, I think. Mostly defined by its various implementations. Strict mode loosely means to try help you not mess up the structure. But there’s no definition about how far that help stretches.

pez20:03:06

In Calva, strict mode is implemented by such that either Calva does the delete or VS Code does it. For Calva to do it, Calva needs to have implemented that deletion. In some cases we haven’t bothered with adding some deletes to strict mode, but rather just highjacked the keyboard shortcuts. Like with ctrl+k. In other cases there is no equivalent Calva Paredit deletion command, like with deleteWordLeft/Right.

pez20:03:18

There are also a setting for Hijacking more or less VS Code default shortcuts. (And no documentation about which shortcuts are affected…)

Dustin Getz20:03:39

I dont know enough about vscode to understand this, but thanks

Dustin Getz20:03:01

I have a configuration now that i understand

pez20:03:34

What you need to know about VS Code is that if it is told to delete something it will do so, unconditionally. While if you tell Paredit to do it, it will try to avoid destroying the structure.

skylize16:03:06

> There are also a setting for Hijacking more or less VS Code default shortcuts. (And no documentation about which shortcuts are affected…) > https://github.com/BetterThanTomorrow/calva/issues/2136