command to increment number in varname on each line
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "kiss-vscode",
|
||||
"version": "0.0.18",
|
||||
"name": "kiss-lang-vscode",
|
||||
"version": "0.1.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kiss-vscode",
|
||||
"version": "0.0.18",
|
||||
"name": "kiss-lang-vscode",
|
||||
"version": "0.1.1",
|
||||
"devDependencies": {
|
||||
"vsce": "^2.15.0"
|
||||
},
|
||||
|
12
package.json
12
package.json
@@ -108,6 +108,14 @@
|
||||
{
|
||||
"title": "kiss-lang-vscode: Sort the selected lines lexicographically from the end of each line",
|
||||
"command": "kiss-lang-vscode.sortLinesSyncEOL"
|
||||
},
|
||||
{
|
||||
"title": "kiss-lang-vscode: Find and replace a token, matching case",
|
||||
"command": "kiss-lang-vscode.findReplaceTokenMatchCase"
|
||||
},
|
||||
{
|
||||
"title": "kiss-lang-vscode: Find text suffixed by a non-negative integer, and replace it, incrementing the number by line",
|
||||
"command": "kiss-lang-vscode.findReplaceIncrement"
|
||||
}
|
||||
],
|
||||
"languages": [
|
||||
@@ -130,7 +138,7 @@
|
||||
"devDependencies": {
|
||||
"vsce": "^2.15.0"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"activationEvents": [],
|
||||
"displayName": "Kiss VSCode"
|
||||
}
|
||||
}
|
||||
|
@@ -79,4 +79,38 @@
|
||||
(let [editor activeTextEditor]
|
||||
(e.delete editor.selection)
|
||||
(e.insert editor.selection.active output))))
|
||||
(return)))
|
||||
|
||||
(defCommand context findReplaceIncrement "Find text suffixed by a non-negative integer, and replace it, incrementing the number by line" "" []
|
||||
(localVar &mut outputLines [])
|
||||
(localVar &mut lineFound 0)
|
||||
(awaitLet [findNumStr (inputBox)
|
||||
&sync length findNumStr.length
|
||||
&sync text (selectedText)]
|
||||
(unless text (print "No text selected!") (return))
|
||||
(unless findNumStr (print "Nothing to find!") (return))
|
||||
// Find where the number suffix starts
|
||||
(let [&mut numStartIdx 0]
|
||||
(while (< numStartIdx length)
|
||||
(when (.contains "0123456789" (findNumStr.charAt numStartIdx))
|
||||
(break))
|
||||
++numStartIdx)
|
||||
(when (>= numStartIdx length) (print "text must be suffixed by a non-negative integer!") (return))
|
||||
|
||||
(let [prefix (findNumStr.substr 0 numStartIdx)
|
||||
num (Std.parseInt (findNumStr.substr numStartIdx))
|
||||
lines (text.split "\n")]
|
||||
(doFor line lines
|
||||
(if (line.contains findNumStr)
|
||||
{
|
||||
(let [newStr "${prefix}$(+ num lineFound)"]
|
||||
(outputLines.push (line.replace findNumStr newStr)))
|
||||
++lineFound
|
||||
}
|
||||
(outputLines.push line)))))
|
||||
(.edit activeTextEditor
|
||||
(lambda [e]
|
||||
(let [editor activeTextEditor]
|
||||
(e.delete editor.selection)
|
||||
(e.insert editor.selection.active (outputLines.join "\n")))))
|
||||
(return)))
|
Reference in New Issue
Block a user