aboutsummaryrefslogtreecommitdiffstats
path: root/macros
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2022-12-22 18:26:42 +0000
committergarret <garret@airmail.cc>2022-12-22 19:04:15 +0000
commitaeb5c6182f5a8e13dc60799f0177ed92407b6d8b (patch)
treefde6f09770dfa24aa798189bc9dddd0babe0b4fb /macros
parentdcdbacb94ef6fc1205e32e3fa411be3833f41d5d (diff)
downloadaegisub-scripts-aeb5c6182f5a8e13dc60799f0177ed92407b6d8b.tar.gz
aegisub-scripts-aeb5c6182f5a8e13dc60799f0177ed92407b6d8b.tar.bz2
aegisub-scripts-aeb5c6182f5a8e13dc60799f0177ed92407b6d8b.zip
A-B: clean up code
local functions split a thing off into a function sane function name hmm lot of functions this time also local variables and addressing luacheck warnings
Diffstat (limited to 'macros')
-rw-r--r--macros/garret.a-b.lua34
1 files changed, 23 insertions, 11 deletions
diff --git a/macros/garret.a-b.lua b/macros/garret.a-b.lua
index 9b0277f..b57b4f8 100644
--- a/macros/garret.a-b.lua
+++ b/macros/garret.a-b.lua
@@ -11,7 +11,7 @@ if haveDepCtrl then
}
end
-function switch_number(i)
+local function switch_indicator(i)
if i == "a" then
return "b"
elseif i == "b" then
@@ -19,22 +19,34 @@ function switch_number(i)
end
end
-function main(sub, sel)
+local function strip_tags(text)
+ return text:gsub("{[^}]-}","")
+end
+
+local function get_indicator(letter, actor)
+ local indicator
+ if actor == "" then
+ indicator = letter
+ else
+ indicator = actor.." "..letter
+ end
+ return indicator
+end
+
+local function main(sub, sel)
local i = "a"
- for si,li in ipairs(sel) do
- line = sub[li]
- if line.actor == "" then
- indicator = i
- else
- indicator = line.actor.." "..i
- end
+ for _,li in ipairs(sel) do
+ local line = sub[li]
+ local indicator = get_indicator(i, line.actor)
+
if line.text == "" then
line.text = indicator
- elseif line.text:gsub("{[^}]-}","") == "" then
+ elseif strip_tags(line.text) == "" then
line.text = line.text .. indicator -- apply tags
end
+
sub[li] = line
- i = switch_number(i)
+ i = switch_indicator(i)
end
aegisub.set_undo_point(script_name)
end