Calva When Clause Contexts#
When clause contexts is a powerful customization mechanism in VS Code. The most common use for end users is with keyboard shortcut bindings. Extensions can provide their own. The following contexts are available with Calva:
calva:keybindingsEnabled
: a master switch that you find in the settingsparedit:keyMap
:strict
,original
, ornone
from the corresponding Calva setting (see Paredit)calva:connected
:true
when Calva is connected to a REPL (there is alsocalva:connecting
||calva:launching
)calva:outputWindowActive
:true
when the Output/REPL window has input focuscalva:replHistoryCommandsActive
:true
when the cursor is in the Output/REPL window at the top level after the last promptcalva:replWindowSubmitOnEnter
:true
when the cursor is adjacent after the last top level form in the Output/REPL windowcalva:cursorInString
:true
when the cursor/caret is in a string or a regexpcalva:cursorInComment
:true
when the cursor is in, or adjacent to a line commentcalva:cursorBeforeComment
:true
when the cursor is adjacent before a line commentcalva:cursorAfterComment
:true
when the cursor is adjacent after a line commentcalva:cursorInWhitespaceAfterComment
:true
when the cursor is in whitespace after a line commentcalva:cursorAtStartOfLine
:true
when the cursor is at the start of a line including any leading whitespacecalva:cursorAtEndOfLine
:true
when the cursor is at the end of a line including any trailing whitespacecalva:projectRoot
: A string with the absolute path to the repl project root, without trailing slashcalva:ns
: A string with the current namespacecalva:replSessionType
:clj
, orcljs
depending on the file type of the current filecalva:connectSequence
: The name of the currently selected Connect Sequence
Here's an example using the calva:connectSequence
context for binding keyboard shortcuts depending on it. (Requires Joyride, which you really should have installed!)
{
"key": "cmd+ctrl+r",
"command": "joyride.runCode",
"args": "(require '[\"vscode\" :as vscode]) (vscode/window.showInformationMessage \"deps.edn + shadow-cljs\")",
"when": "calva:connectSequence == 'deps.edn + shadow-cljs'"
},
{
"key": "cmd+ctrl+r",
"command": "joyride.runCode",
"args": "(require '[\"vscode\" :as vscode]) (vscode/window.showInformationMessage \"deps.edn\")",
"when": "calva:connectSequence == 'deps.edn'"
},
See also the Calva extension manifest for how the built in keybindings use these contexts. (Search for keybindings
on that page).