Fork me on GitHub
#calva
<
2021-02-04
>
seancorfield01:02:05

(after grumbling the other day about how weird the Calva Paredit key bindings are and trying to customize it all back to what I was used it, I decided at lunchtime to revert to the default key bindings and just suffer through the learning period... and now I'm back to being fairly productive... but still having to mash undo frequently as I try several key chords before getting the right one! 🙂 )

Cris B02:02:59

Yes I've been through the keybindings shuffle a couple of times. I've settled on my own - Calva's seem to be nice & systematic but I can't quite get past the interference with common ones like ctrl + left/right arrows for wordwise cursor movement.

seancorfield03:02:14

@cb.lists Yeah, I think that was the one that caught me out late this afternoon after I'd been working with the default set for a few hours -- I was trying to move through a ;; line comment word-by-word and couldn't figure out how... But it seems like https://github.com/ailisp/strict-paredit-vscode uses ctrl + left/right for that and I still had wordwise cursor movement... so I think it was alt + left/right that was wordwise before. According to the keyboard shortcuts, alt + left/right is "Go Forward/Backward" with -- for "when" but...?

Cris B04:02:13

@seancorfield That's go forward/back in the editor navigation history a la web browsers. Very useful so I leave as-is. As for ctrl + left/right, I've reset those back to the (pre-calva) default wordwise movements as they're too locked into muscle memory for me to want to relinquish. Also useful within clj/s files within line comments as you suggest.

seancorfield04:02:04

Ah, right, Badly named then in VS Code 🙂 I'll see how long I last with ctrl + left/right 🙂

seancorfield04:02:14

Yup, switching forward/backward sexp to alt-right/left is much more natural, and now I have forward/backward word with ctrl-right/left. Thanks @cb.lists

6
chucklehead04:02:11

I've gotten pretty used to the Calva bindings on my laptop, but at my desk I use a Kinesis Advantage and there are several commands where I need to hit 3-4 buttons on one thumb cluster and I'm constantly short of thumbs - anyone have similar and figured out alternate keybindings that work well?

Cris B06:02:42

Love the new custom REPL command feature. tap> + Reveal invoked from a keyboard shortcut is very nice indeed.

metal 3
pez12:02:32

I want some help with testing a change to the custom REPL command feature. The main change is to enable binding keyboard shortcuts to the custom commands. (I also add built-in commands for tapping current and top-level form, so there will be no need to use the custom commands for that 😄.) Description of how it should work: https://github.com/BetterThanTomorrow/calva/issues/1011 VSIX: https://10836-125431277-gh.circle-artifacts.com/0/tmp/artifacts/calva-2.0.159-1008-custom-snippets-shortcuts-b10c0624.vsix

❤️ 6
Cris B21:02:53

Both methods of binding a key to a custom command work for me, at least with a naïve test. One oddity - the binding for the last custom command in the json keybindings file shows up as the shortcut for the generic 'Calva: run custom REPL command' in the 'show all commands' popup.

Cris B21:02:25

The user can always copy the generic keybinding into their user keybinding json file and place that last I guess.

Cris B21:02:39

One other thing - hitting 'ESC' when the custom REPL list (ctrl+alt+space) is up throws an error: "Cannot read property 'snippet' of undefined"

pez21:02:31

Thanks! Found that last bug and fixed it in dev. Still figuring about what to do with that other thing…. And @U9A1RLFNV found a problem with running the commands when the cursor is in the output window.

3
lread13:02:01

@chuck.cassel, I use a Kinesis Advantage too, I’m coming from spacemacs so am digging VSSpaceCode https://practicalli.github.io/clojure/clojure-editors/editor-install-guides/vspacecode-calva.html

chucklehead01:02:00

thanks, hadn't looked into this yet, I'll have to give it a try

lread02:02:31

If you like vim style editing, it is familiar.

pez22:02:28

I’ve already gotten semi-used to the new slurp/barf keyboard shortcuts. Managed to destroy quite a bit of structure while learning, though. ctrl+alt+left/right for jumping past sexpressions was second nature, but now… How are you other people faring with this?

bringe23:02:23

I'm loving the new defaults compared to the old. I can't say it's best to override the nav-by-word still, but it doesn't bother me personally. I know changing the nav keybindings throws off other bindings that were meant to be additive to those, like selection bindings, so idk a good solution, if anything should be changed. Default keybindings, when so many exist, are hard.

Bees06:02:05

I like how ctrl+left/right/up/down navigate. What I can't figure out is the new keys for the old behavior. After making navigation mistakes with the old keys I was finally adjusted how to work with paredit, then ctrl+left/right changed. 😕

pez07:02:19

I was just reminded on Reddit that we haven’t summarized the new Paredit keybindings after the change in version 2.0.157. I put them in a reply to there: https://www.reddit.com/r/Clojure/comments/lbsv97/using_calva_with_other_clojure_repl_extensions_is/gmslzrt/?utm_source=reddit&amp;utm_medium=web2x&amp;context=3

catjam 3
Cris B22:02:07

Can't help there as I've settled on my own shortcuts for the limited range of paredit ops I use.

seancorfield22:02:49

@pez The biggest problem for me was figuring out exactly how to make this "do the right thing" on both Mac and Windows so that I don't lose word-wise navigation.

seancorfield22:02:02

On Mac I need alt+right / alt+left for word-wise nav. On Windows I need ctrl+right / ctrl-left for word-wise nav.

pez22:02:57

There are win and mac fields you can use in addition to key. Have you tried that?

seancorfield22:02:08

(it's annoying to have to switch keys between Mac/Windows for word-wise nav but much more annoying to have Calva's paredit usurp one set of those keys differently!)

seancorfield22:02:30

I hadn't found win/`mac` in the VS Code docs but I found isMac 🙂

pez22:02:58

The new default keybindings leave word-wise navigation alone for the respective platform.

pez22:02:22

So you might get away with removing your custom bindings.

seancorfield22:02:45

The default settings just didn't work for me.

seancorfield22:02:41

Other than backward/forward sexp, the other key bindings are fine. Well, I'm getting used to them but they're not un-fine.

pez22:02:02

Would a context variable like calva:inComment help?

seancorfield22:02:03

I don't want that nav to be different in different parts of the file.

pez22:02:14

Do you ever use word navigation in sexpressions?

seancorfield22:02:49

Yes, all the time 🙂

pez22:02:11

I move by sexpressions there. But in comments there are no sexpressions so I would be fine if the forward/backward sexpr commands moved by words there.

pez22:02:04

Can you give me an example when you move by word in sexpressions?

seancorfield22:02:47

What do you mean? Word-by-word is word-by-word.

pez23:02:18

Well, depends. 😃 What are the words in (defn foo [a b] :bar)?

seancorfield23:02:06

With the ; that isn't legal Clojure as it stands -- is that what you meant?

pez23:02:21

Fixed 😃

seancorfield23:02:21

|(defn foo [a b] :bar)
 (defn| foo [a b] :bar)
 (defn foo| [a b] :bar)
 (defn foo [a| b] :bar)
 (defn foo [a b|] :bar)
 (defn foo [a b]| :bar)
 (defn foo [a b] :bar|)
 (defn foo [a b] :bar)|

borkdude23:02:42

One thing I miss in Calva when I'm using it is that paredit doesn't work in strings like "(foo (bar (baz)))". I use this quite a lot in emacs

seancorfield23:02:20

(and, to be clear, I don't care that going backwards word-wise through that code doesn't use the same cursor positions -- it's "close enough" to words for fast navigation where I don't have to switch key chords in the middle of an action)

pez23:02:26

Thanks. Is there even a command that would move the cursor like that?

seancorfield23:02:36

Who is that question addressed at?

pez23:02:48

To you. 😃

pez23:02:29

Found it. cursorWordRight.

bringe23:02:23

I'm loving the new defaults compared to the old. I can't say it's best to override the nav-by-word still, but it doesn't bother me personally. I know changing the nav keybindings throws off other bindings that were meant to be additive to those, like selection bindings, so idk a good solution, if anything should be changed. Default keybindings, when so many exist, are hard.

pez23:02:10

@seancorfield So then maybe these settings could work for you?

{
        "key": "ctrl+right",
        "win": "ctrl+right",
        "mac": "alt+right",
        "command": "cursorWordRight"
    },
    {
        "key": "ctrl+left",
        "win": "ctrl+left",
        "mac": "alt+left",
        "command": "cursorWordLeft"
    },
    {
        "key": "ctrl+right",
        "mac": "ctrl+right",
        "win": "alt+right",
        "command": "paredit.forwardSexp",
        "when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
    },
    {
        "key": "ctrl+left",
        "mac": "ctrl+left",
        "win": "alt+left",
        "command": "paredit.backwardSexp",
        "when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
    }

seancorfield23:02:03

That seems cleaner than what I have so I'll take that for a spin shortly. Thanks.

pez23:02:14

If it works, we can add it to the http://calva.io

seancorfield23:02:00

I decided to change it to the mac bindings even on Windows. My problem before was not knowing the cursorWordRight/`Left` commands so I didn't know how to force those to the alt versions!

seancorfield23:02:48

It's a win for me since I now have the exact same key bindings on Mac and Windows: ctrl right/left for sexp nav; alt right/left for word nav.

seancorfield23:02:19

{
      "key": "ctrl+right",
      "command": "paredit.forwardSexp",
      "when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
    },
    {
      "key": "alt+right",
      "command": "cursorWordRight"
    },
    {
      "key": "ctrl+left",
      "command": "paredit.backwardSexp",
      "when": "calva:keybindingsEnabled && editorTextFocus && editorLangId == 'clojure' && paredit:keyMap =~ /original|strict/"
    },
    {
      "key": "alt+left",
      "command": "cursorWordLeft"
    }

seancorfield23:02:26

(but your suggestion did work in terms of fixing the keys per-platform, as you expected -- I'd just rather have them be identical across platforms, instead of swapped across platforms)

👍 3
pez23:02:50

Awesome. We used to have the same bindings for defaults, but it caused troubles, so now we have some few defaults where it differs between mac and win. Makes total sense to use the same ones if you switch back and forth.

seancorfield23:02:44

At some point I'll replace my Mac with a Windows desktop and maybe then I'll remove this and learn the platform defaults 🙂

seancorfield23:02:02

(but I'm on the Mac slightly more than Windows at the moment)

pez23:02:01

I only use Windows when I test how Calva things work there. 😃

seancorfield00:02:44

Using ctrl right/left for sexp nav feels better because it's closer to the backward up/forward down sexp nav (ctrl up/down).

pez00:02:26

Indeed. The reason we changed away from that on Mac is that by default MacOS binds those to some Mission Control stuff.

pez00:02:41

I would change mine back if it wasn’t that I think I should be dog feeding the Calva defaults.

pez00:02:26

(And I am confusing things, on Mac ctrl+left/right actually used to slurp/barf.)

pez23:02:28

Not sure if key is needed in any of them. The schema complained if I omitted them. 😃

pez23:02:03

This VSIX has some fixes for the new keyboard shortcuts enabled custom REPL commands. Could you take it for a spin, @cb.lists, @janne.sauvala? (And anyone else of course,) https://10856-125431277-gh.circle-artifacts.com/0/tmp/artifacts/calva-2.0.159-dev-b89d4952.vsix

Tomas Brejla23:02:04

Seems that I arrived in perfect time 😄 I'm having issues on my calva v2.0.158 with custom commands. Will try this vsix, hopefully it will resolve it 🙂

pez23:02:42

What issues, if I may be curious? 😃

Janne Sauvala23:02:47

Will do! One thing I was trying to do was to create fairly complex custom snipped to launch Reveal from the REPL. The command is taken from Sean’s settings and I have used it previously only from inside comment-block. There was something funny happening when I was trying to execute the command. I’ll use this newer version and continue debugging

pez23:02:46

Cool. I launch Reveal as part of repl start, btw.

Cris B23:02:25

Working thus far for my (very vanilla) test cases.

❤️ 3
Tomas Brejla23:02:59

The commands do not get executed for me at all. Even trivial ones such as

"calva.customREPLCommandSnippets": [
        {
            "name": "Printout test",
            "snippet": "(println 42)",
            "repl": "clj"
        },
    ],
I can see the command in the popup window, but when I select it, just the empty line gets added to output.calva-replwindow. What's even more strange.. it happened once or twice tonight that it was working just fine for a while. I wonder whether it might be caused by some namespace reloading stuff I'm using in my project (integrant-repl and thus tools.namespace)

pez23:02:40

I don’t think that could be the reason. The snippet should be printed to the repl window… What system are you on?

Tomas Brejla23:02:30

➜  emptyproj cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.10
DISTRIB_CODENAME=groovy
DISTRIB_DESCRIPTION="Ubuntu 20.10"
➜  emptyproj uname -a            
Linux brdloush-nb 5.8.0-41-generic #46-Ubuntu SMP Mon Jan 18 16:48:44 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

pez23:02:23

Try without the repl property. Don’t think that could be it, but anyway.

Tomas Brejla23:02:52

I tried killing all my vs code windows, then created empty lein new emptyproj project. Cider jack in, tried the Printout test.. didn't work. Upgraded to the VSIX version, reloaded plugin... cider jack in... and it seems to work.

Tomas Brejla23:02:04

might be just a coincidence though

Tomas Brejla23:02:02

switched back to my original project, custom commands still seem to work

pez23:02:18

The VSIX version is quite a major change from the currently released one, so it might have done away with that particular problem. (Probably introduced some new problems, but hopefully on an evolved level, if so. 😄)

😀 3
Tomas Brejla23:02:27

perhaps reloading the plugin somehow flushed some broken caches or something? :man-shrugging:

pez23:02:48

let’s hope we’ll never see it again, haha. ¯\(ツ)

Tomas Brejla00:02:54

Good news is that it seems to be working nicely now with the VSIX version. Bad news is that it's 1:17AM, so it's time to get some sleep 😄 Thanks for your help!

❤️ 3
Janne Sauvala07:02:43

@pez what do you use to launch Reveal as part of your repl start?

pez07:02:16

I have this alias in my deps.edn and select it at jack-in:

:reveal
  {:extra-deps {vlaaad/reveal {:mvn/version "1.2.185"}}
   :jvm-opts   ["-Dvlaaad.reveal.prefs={:font-size,17}"]
   :main-opts  ["-m" "nrepl.cmdline"
                "--middleware" "[vlaaad.reveal.nrepl/middleware,cider.nrepl/cider-middleware]"]}

Janne Sauvala07:02:48

Thanks, I decided not to use the middleware since I felt it was a little too chatty to print everything to Reveal 🙂

pez07:02:55

This keybinding worked to start Reveal and start tapping to it:

{
        "key": "ctrl+alt+cmd+r",
        "command": "calva.runCustomREPLCommand",
        "args": "(require '[vlaaad.reveal :as reveal])(add-tap (reveal/ui))"
    }
I now have these aliases in deps.edn:
:reveal-nrepl-middleware
  {:extra-deps {vlaaad/reveal {:mvn/version "1.2.185"}}
   :jvm-opts   ["-Dvlaaad.reveal.prefs={:font-size,17}"]
   :main-opts  ["-m" "nrepl.cmdline"
                "--middleware" "[vlaaad.reveal.nrepl/middleware,cider.nrepl/cider-middleware]"]}
  :reveal-dep-only
  {:extra-deps {vlaaad/reveal {:mvn/version "1.2.185"}}}
I might be using some old version of reveal. I am not using it much yet, because I don’t quite understand how it is supposed to work, but since I see the tapped things in there, I am assuming it works. 😃

pez07:02:15

This custom command definition also works (for me, yeah, I know the saying 😄).

"calva.customREPLCommandSnippets": [
        ...
        {
            "name": "Start Reveal Tapper",
            "snippet": "(require '[vlaaad.reveal :as reveal])(add-tap (reveal/ui))",
            "key": "sr"
        },
        ...
    ]

seancorfield17:02:25

Nice! The latest Reveal is 1.3.194 I think. Big changes in 1.3: the ability to send forms to Reveal that control the UI, open new views etc.

pez17:02:29

Thanks for that info!

pez23:02:14

Issue https://github.com/BetterThanTomorrow/calva/issues/1011 has the documentation for how it should work. If you find typos and strange things there, please comment on the issue.

pez07:02:55

This keybinding worked to start Reveal and start tapping to it:

{
        "key": "ctrl+alt+cmd+r",
        "command": "calva.runCustomREPLCommand",
        "args": "(require '[vlaaad.reveal :as reveal])(add-tap (reveal/ui))"
    }
I now have these aliases in deps.edn:
:reveal-nrepl-middleware
  {:extra-deps {vlaaad/reveal {:mvn/version "1.2.185"}}
   :jvm-opts   ["-Dvlaaad.reveal.prefs={:font-size,17}"]
   :main-opts  ["-m" "nrepl.cmdline"
                "--middleware" "[vlaaad.reveal.nrepl/middleware,cider.nrepl/cider-middleware]"]}
  :reveal-dep-only
  {:extra-deps {vlaaad/reveal {:mvn/version "1.2.185"}}}
I might be using some old version of reveal. I am not using it much yet, because I don’t quite understand how it is supposed to work, but since I see the tapped things in there, I am assuming it works. 😃