Fork me on GitHub
#calva
<
2022-06-06
>
Max16:06:28

Good timezone! Is there a single Calva command for "copy as kill" -- that is, instead of killing, copy what would have been killed? I know there are ways to achieve a comparable effect, but I'm looking for a single command.

Jon Boone16:06:47

How would that differ from regular kill? And if the answer is, the “killed text remains”, how is that different from regular copy???

Max16:06:51

I might be using the wrong terms (still new); my understanding of kill is "next/current form", so no selection necessary

Jon Boone16:06:50

So, you are looking for a way to select the current/next form and copy it with a single command/keyboard shortcut?

Max16:06:03

Yes! Thank you, that's a much better way of expressing it

Jon Boone16:06:05

I’d try searching for that using appropriate keywords: “calva” “copy form” (or some such) to see if someone else has already implemented it.. Or you could create your own VS Code command that invokes select, followed by copy..

Max16:06:18

perfect, thanks! much appreciated

chucklehead18:06:40

here's a joyride script that copies the content selected by the Calva Paredit: Select Current Top Level... command:

(ns copy-top-form
  (:require ["vscode" :as vscode]
            [promesa.core :as p]))

(let [editor ^js vscode/window.activeTextEditor
      original-selection (.-selection editor)]
  (p/do
    (vscode/commands.executeCommand "paredit.rangeForDefun")
    (vscode/env.clipboard.writeText (.getText
                                     (.-document editor)
                                     (.-selection editor)))
    (set! (.-selection editor) original-selection)))

pez19:06:47

Indeed, Joyride is perfect for this. For your script there, @U015879P2F8, you could avoid saving and restoring the original selection by using the ranges.currentTopLevelDefhttps://calva.io/api/#rangescurrenttopleveldef. There's no API for getting the range and text for the next form, though, @UEJUEMGHF, so for now you'll need to do that saving and restoring.

1