(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! ๐ )
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.
@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...?
@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.
Ah, right, Badly named then in VS Code ๐ I'll see how long I last with ctrl + left/right ๐
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
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?
Love the new custom REPL command feature. tap>
+ Reveal invoked from a keyboard shortcut is very nice indeed.
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
@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
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.
The user can always copy the generic keybinding into their user keybinding json file and place that last I guess.
One other thing - hitting 'ESC' when the custom REPL list (ctrl+alt+space) is up throws an error: "Cannot read property 'snippet' of undefined"
Thanks! Found that last bug and fixed it in dev. Still figuring about what to do with that other thingโฆ. And @brandon.ringe found a problem with running the commands when the cursor is in the output window.
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?
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. ๐
Can't help there as I've settled on my own shortcuts for the limited range of paredit ops I use.
@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.
I ended up doing this: https://github.com/seancorfield/vscode-clover-setup/blob/develop/keybindings.json#L102-L141
On Mac I need alt+right / alt+left for word-wise nav. On Windows I need ctrl+right / ctrl-left for word-wise nav.
There are win
and mac
fields you can use in addition to key
. Have you tried that?
(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!)
I hadn't found win
/`mac` in the VS Code docs but I found isMac
๐
The new default keybindings leave word-wise navigation alone for the respective platform.
So you might get away with removing your custom bindings.
The default settings just didn't work for me.
Other than backward/forward sexp, the other key bindings are fine. Well, I'm getting used to them but they're not un-fine.
Would a context variable like calva:inComment
help?
I don't want that nav to be different in different parts of the file.
Do you ever use word navigation in sexpressions?
Yes, all the time ๐
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.
Can you give me an example when you move by word in sexpressions?
What do you mean? Word-by-word is word-by-word.
Well, depends. ๐ What are the words in (defn foo [a b] :bar)
?
With the ;
that isn't legal Clojure as it stands -- is that what you meant?
Fixed ๐
|(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)|
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
(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)
Thanks. Is there even a command that would move the cursor like that?
Who is that question addressed at?
To you. ๐
Found it. cursorWordRight
.
@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/"
}
Not sure if key
is needed in any of them. The schema complained if I omitted them. ๐
Welcome @brdloush!
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
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.
Thanks for that info!
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.
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 ๐
What issues, if I may be curious? ๐
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
Cool. I launch Reveal as part of repl start, btw.
That seems cleaner than what I have so I'll take that for a spin shortly. Thanks.
If it works, we can add it to the http://calva.io
Working thus far for my (very vanilla) test cases.
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-repl
window.
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)I donโt think that could be the reason. The snippet should be printed to the repl windowโฆ What system are you on?
โ 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
Try without the repl
property. Donโt think that could be it, but anyway.
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.
might be just a coincidence though
switched back to my original project, custom commands still seem to work
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. ๐)
perhaps reloading the plugin somehow flushed some broken caches or something? :man-shrugging:
letโs hope weโll never see it again, haha. ยฏ\(ใ)/ยฏ
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!
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.
{
"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"
}
(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)
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.
At some point I'll replace my Mac with a Windows desktop and maybe then I'll remove this and learn the platform defaults ๐
(but I'm on the Mac slightly more than Windows at the moment)
I only use Windows when I test how Calva things work there. ๐