Skip to content

Commit 9221090

Browse files
author
committed
[skip ci]
1 parent d912295 commit 9221090

File tree

4 files changed

+125
-67
lines changed

4 files changed

+125
-67
lines changed

custom-commands/index.html

+59-1
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,15 @@
781781
</label>
782782
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
783783

784+
<li class="md-nav__item">
785+
<a href="#interpolationsubstitution-modifiers" class="md-nav__link">
786+
<span class="md-ellipsis">
787+
Interpolation/substitution Modifiers
788+
</span>
789+
</a>
790+
791+
</li>
792+
784793
<li class="md-nav__item">
785794
<a href="#user-and-workspace-settings" class="md-nav__link">
786795
<span class="md-ellipsis">
@@ -2110,6 +2119,15 @@
21102119
</label>
21112120
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
21122121

2122+
<li class="md-nav__item">
2123+
<a href="#interpolationsubstitution-modifiers" class="md-nav__link">
2124+
<span class="md-ellipsis">
2125+
Interpolation/substitution Modifiers
2126+
</span>
2127+
</a>
2128+
2129+
</li>
2130+
21132131
<li class="md-nav__item">
21142132
<a href="#user-and-workspace-settings" class="md-nav__link">
21152133
<span class="md-ellipsis">
@@ -2200,6 +2218,7 @@ <h1 id="custom-repl-commands">Custom REPL Commands<a class="headerlink" href="#c
22002218
<li><code>$file-text</code>: The text of the current file edited</li>
22012219
<li><code>$ns</code>: The namespace used for evaluating the command</li>
22022220
<li><code>$editor-ns</code>: The namespace of the editor from which the command was run</li>
2221+
<li><code>$ns-form</code>: The <code>ns</code> form which would be used if evaluating something from the current cursor position (often the <code>ns</code> form of the current file)</li>
22032222
<li><code>$selection</code>: The currently selected text</li>
22042223
<li><code>$current-form</code>: The text of the <a href="../evaluation/#current-form">current form</a></li>
22052224
<li><code>$current-pair</code>: The text of the current pair if in a binding, otherwise empty string</li>
@@ -2210,11 +2229,40 @@ <h1 id="custom-repl-commands">Custom REPL Commands<a class="headerlink" href="#c
22102229
<li><code>$head</code>: The text between the start of the current list to the cursor</li>
22112230
<li><code>$tail</code>: The text between the cursor and the end of the current list</li>
22122231
</ul>
2232+
<p>The substitution variables can also be referenced using a <code>${variable}</code> syntax. This is to facilitate modifiers. Speaking of which...</p>
2233+
<h2 id="interpolationsubstitution-modifiers">Interpolation/substitution Modifiers<a class="headerlink" href="#interpolationsubstitution-modifiers" title="Permanent link">#</a></h2>
2234+
<p>You can transform substitution values using modifiers. The syntax is: <code>${variable|modifier|arg1|arg2...}</code>. Multiple modifiers can be chained, separated by <code>|</code>.</p>
2235+
<p>Available modifiers:</p>
2236+
<ul>
2237+
<li><code>pr-str</code>: Stringify the value</li>
2238+
<li><code>replace</code>: Replace text using regex pattern and replacement string. Takes two arguments: pattern and replacement</li>
2239+
<li><code>replace-first</code>: Replace first occurrence of pattern. Takes two arguments: pattern and replacement</li>
2240+
</ul>
2241+
<p>ClojureScript semantics apply. The modifications will happen client side, in Calva, and the modifiers will in fact be using the corresponding ClojureScript functions to perform the modification.</p>
2242+
<p>The interpolation special characters (<code>|</code>, <code>{</code>, and <code>}</code>) in replacement strings need to be escaped with a backslash.</p>
2243+
<p>Examples:</p>
2244+
<div class="highlight"><pre><span></span><code>// Stringify, then replace spaces
2245+
&quot;${selection|pr-str|replace|\\s+|_}&quot; // &quot;hello world&quot; -&gt; &quot;\&quot;hello_world\&quot;&quot;
2246+
2247+
// Replace spaces with underscores
2248+
&quot;${selection|replace|\\s+|_}&quot; // &quot;hello world&quot; -&gt; &quot;hello_world&quot;
2249+
2250+
// Multiple replacements
2251+
&quot;${selection|replace|hello|HELLO|replace|\\s+|_}&quot; // &quot;hello world&quot; -&gt; &quot;HELLO_world&quot;
2252+
2253+
// Some characters need to be escaped if used in the replacement arg
2254+
&quot;${selection|replace|\\s+|\\|}&quot; // &quot;hello world&quot; -&gt; &quot;hello|world&quot;
2255+
&quot;${selection|replace|\\s+|\\{}&quot; // &quot;hello world&quot; -&gt; &quot;hello{world&quot;
2256+
&quot;${selection|replace|\\(|\\{}&quot; // &quot;(foo)&quot; -&gt; &quot;{foo)&quot;
2257+
2258+
// Replace with capture groups
2259+
&quot;${selection|replace|(hello) (world)|$2 $1}&quot; // &quot;hello world&quot; -&gt; &quot;world hello&quot;
2260+
</code></pre></div>
22132261
<h2 id="user-and-workspace-settings">User and Workspace Settings<a class="headerlink" href="#user-and-workspace-settings" title="Permanent link">#</a></h2>
22142262
<p>Settings from your User (global) level and the workspace are concatenated. Except for the <code>key</code> field, are merged.</p>
22152263
<p>With these <strong>User</strong> settings:</p>
22162264
<div class="highlight"><pre><span></span><code><span class="w"> </span><span class="nt">&quot;calva.customREPLCommandSnippets&quot;</span><span class="p">:</span><span class="w"> </span><span class="p">[</span>
2217-
<span class="w"> </span><span class="p">{</span>
2265+
<span class="w"> </span><span class="p">{</span><span class="err">s</span>
22182266
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;Call Current Form&quot;</span><span class="p">,</span>
22192267
<span class="w"> </span><span class="nt">&quot;key&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;c&quot;</span><span class="p">,</span>
22202268
<span class="w"> </span><span class="nt">&quot;snippet&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;($current-form)&quot;</span>
@@ -2234,6 +2282,16 @@ <h2 id="user-and-workspace-settings">User and Workspace Settings<a class="header
22342282
<span class="w"> </span><span class="nt">&quot;repl&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;cljs&quot;</span><span class="p">,</span>
22352283
<span class="w"> </span><span class="nt">&quot;snippet&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(cljs.test/test-var #&#39;$top-level-defined-symbol)&quot;</span><span class="p">,</span>
22362284
<span class="w"> </span><span class="nt">&quot;key&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;tab&quot;</span>
2285+
<span class="w"> </span><span class="p">},</span>
2286+
<span class="w"> </span><span class="p">{</span>
2287+
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;qol: Add Snitch dependency&quot;</span><span class="p">,</span>
2288+
<span class="w"> </span><span class="nt">&quot;repl&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;clj&quot;</span><span class="p">,</span>
2289+
<span class="w"> </span><span class="nt">&quot;snippet&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(require &#39;[clojure.repl.deps :refer [add-libs]])\n\n\n(add-libs &#39;{org.clojars.abhinav/snitch {:mvn/version \&quot;0.1.16\&quot;}})&quot;</span>
2290+
<span class="w"> </span><span class="p">},</span>
2291+
<span class="w"> </span><span class="p">{</span>
2292+
<span class="w"> </span><span class="nt">&quot;name&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;qol: Evaluate as Snitch defn* &quot;</span><span class="p">,</span>
2293+
<span class="w"> </span><span class="nt">&quot;repl&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;clj&quot;</span><span class="p">,</span>
2294+
<span class="w"> </span><span class="nt">&quot;snippet&quot;</span><span class="p">:</span><span class="w"> </span><span class="s2">&quot;(require &#39;[snitch.core :refer [defn* defmethod* *fn *let]])\n${top-level-form|replace|^\\(defn-?|(defn*}&quot;</span>
22372295
<span class="w"> </span><span class="p">}</span>
22382296
<span class="w"> </span><span class="p">],</span>
22392297
</code></pre></div>

search/search_index.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)