Fixed lines to conform to style guidelines.
This commit is contained in:
parent
a66e1f1559
commit
bf09582478
|
@ -9,7 +9,8 @@ regex.match = function(pattern_string, string)
|
||||||
return regex.cmatch(pattern, string)
|
return regex.cmatch(pattern, string)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Will iterate back through any UTF-8 bytes so that we don't replace bits mid character.
|
-- Will iterate back through any UTF-8 bytes so that we don't replace bits
|
||||||
|
-- mid character.
|
||||||
local function previous_character(str, index)
|
local function previous_character(str, index)
|
||||||
local byte
|
local byte
|
||||||
repeat
|
repeat
|
||||||
|
@ -44,12 +45,17 @@ regex.gsub = function(pattern_string, string, replacement)
|
||||||
local currentReplacement = replacement
|
local currentReplacement = replacement
|
||||||
if #indices > 2 then
|
if #indices > 2 then
|
||||||
for i = 1, (#indices/2 - 1) do
|
for i = 1, (#indices/2 - 1) do
|
||||||
currentReplacement = string.gsub(currentReplacement, "\\" .. i, str:sub(indices[i*2+1], end_character(str,indices[i*2+2]-1)))
|
currentReplacement = string.gsub(
|
||||||
|
currentReplacement,
|
||||||
|
"\\" .. i,
|
||||||
|
str:sub(indices[i*2+1], end_character(str,indices[i*2+2]-1))
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
currentReplacement = string.gsub(currentReplacement, "\\%d", "")
|
currentReplacement = string.gsub(currentReplacement, "\\%d", "")
|
||||||
if indices[1] > 1 then
|
if indices[1] > 1 then
|
||||||
result = result .. str:sub(1, previous_character(str, indices[1])) .. currentReplacement
|
result = result ..
|
||||||
|
str:sub(1, previous_character(str, indices[1])) .. currentReplacement
|
||||||
else
|
else
|
||||||
result = result .. currentReplacement
|
result = result .. currentReplacement
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,10 +47,14 @@ local initial_regex_replace = "/"
|
||||||
command.add("core.docview", {
|
command.add("core.docview", {
|
||||||
["regex:find-replace"] = function()
|
["regex:find-replace"] = function()
|
||||||
core.command_view:set_text(initial_regex_replace)
|
core.command_view:set_text(initial_regex_replace)
|
||||||
core.command_view:enter("Regex Replace (enter pattern as /old/new/)", function(pattern)
|
core.command_view:enter(
|
||||||
|
"Regex Replace (enter pattern as /old/new/)",
|
||||||
|
function(pattern)
|
||||||
regex_replace_file(pattern)
|
regex_replace_file(pattern)
|
||||||
initial_regex_replace = pattern
|
initial_regex_replace = pattern
|
||||||
end) end
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue