Fork me on GitHub
#calva
<
2024-05-24
>
robert-stuttaford07:05:35

is there an example somewhere for how to do this with calva? set up a keybind that evaluates some code in the active repl: https://github.com/robert-stuttaford/.emacs.d/blob/master/cider.el#L86-L104

robert-stuttaford07:05:09

we have one VS code user on our team who doesn't have this helper and i'd like to provide it to her!

pez08:05:49

Hi! The gist of this you would use https://calva.io/custom-commands/ for. Here’s an example:

{
    "key": "ctrl+alt+c -",
    "command": "calva.runCustomREPLCommand",
    "args": {
      "snippet": "(clojure.repl/pst)"
    }
  },
You will need to escape newlines, because JSON. (There is a way to configure this in an EDN file, but it gets a bit involved given that you want to combine with saving the file.) To combine this with saving the file there’s a command for saving the file, workbench.action.files.save. And there’s a command for running several commands in succession, runCommands. I wrote a little something about runCommands here: https://blog.agical.se/en/posts/vs-code-runcommands-for-multi-commands-keyboard-shortcuts/ The check for wether the buffer has a filename I do not quite understand, but VS Code has a very expressive language for making keybindings conditional, using https://code.visualstudio.com/api/references/when-clause-contexts. You should be able to get at least very close to the Emacs solution this way. There is of course also #joyride, but I think it’s overkill for this one. Please don’t hesitate to ask more as you get more specific questions. It all looks like stuff for a blog post of mine (or yours) once you have implemented it. 😃

robert-stuttaford08:05:42

holy shit @U0ETXRFEW this is an amazing response, i feel honoured, thank you so much 😄

pez08:05:23

Oh, forgot, To find command ids for things you want to bind keys to, I recommend the Keyboard Shortcuts editor. Default keybinding on mac is cmd+k cmd+s. The search feature is quite powerful there. Right-click items to find actions like copying the command id and more.

pez08:05:39

You are entirely welcome, @U0509NKGK! 🙏

robert-stuttaford08:05:21

the save-buffer thing was a total red herring, i apologise - the thing i actually care about is preventing people from leaving lots of (comment (cognician.system/restart-systems!)) all over the countryside 😂

robert-stuttaford08:05:35

this is amazing and i think we're totally sorted here, thank you

1
pez08:05:29

A thing with keyboard shortcuts in VS Code is that they are always either predefined or entirely personal. There is no way I know of to share them as project config. If you find that you want to support this restart-systems! as a project config, you can define custom repl commands in either .calva/config.edn or in .vscode/settings.json. There are a bunch of predefined keyboard shortcuts that you can bind to. And Calva also can bring up a menu with the snippets. I know you said you were set, but anyway. And for anyone else finding this thread.

1
robert-stuttaford09:05:02

oh rad, this is valuable, thank you