Fork me on GitHub

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???


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?


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..


perfect, thanks! much appreciated


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)]
    (vscode/commands.executeCommand "paredit.rangeForDefun")
    (vscode/env.clipboard.writeText (.getText
                                     (.-document editor)
                                     (.-selection editor)))
    (set! (.-selection editor) original-selection)))


Indeed, Joyride is perfect for this. For your script there, @U015879P2F8, you could avoid saving and restoring the original selection by using the ranges.currentTopLevelDef 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.