NicolaiSoeborg / manipulator-plugin

A plugin for manipulating text (UPPER, lower, base64, etc) in the editor "Micro"
MIT License
39 stars 3 forks source link

wrap in braces & capital case #2

Closed marinopposite closed 7 years ago

marinopposite commented 7 years ago

I wrote some small enhancements to your manipulator.lua:

Command: capital (uppercases the first letter of marked block or letter at cursor when nothing is marked)

function capital() manipulate("[%a]", string.upper, 1) end
MakeCommand("capital", "manipulator.capital")

As per resolving issue #707 in micro, these wrap the marked text either in braces, curly braces or square brackets:

Command: curly, brace, square

function curly()   manipulate(".*", "{%1}", 1) end
MakeCommand("curly", "manipulator.curly")

function brace()   manipulate(".*", "(%1)", 1) end
MakeCommand("brace", "manipulator.brace")

function square()  manipulate(".*", "[%1]", 1) end
MakeCommand("square", "manipulator.square")

To accomodate this I needed to change the declaration of the function manipulate at line 44 by adding the argument num:

function manipulate(regex, manipulator, num)

and line 49 in it:

local newTxt = string.gsub(oldTxt, regex, manipulator, num)

to control the number of replacements (effectively to restrict them to only one).

I apologize for not going through entire pull/push routine due to this being so small.

Best regards.

marinopposite commented 7 years ago
function quote()   manipulate(".*", '"%1"', 1) end
MakeCommand("quote", "manipulator.quote" )

function single()  manipulate(".*", "'%1'", 1) end
MakeCommand("single", "manipulator.single")

function generic() manipulate(".*", "<%1>", 1) end
MakeCommand("generic", "manipulator.generic")
NicolaiSoeborg commented 7 years ago

Hi @marinopposite

Thanks for the contribution! It has been added now and I will make a PR to get it upstream in micro's repo.