aboutsummaryrefslogtreecommitdiffstats
path: root/macros
diff options
context:
space:
mode:
authorgarret <garret@airmail.cc>2023-01-15 00:05:27 +0000
committergarret <garret@airmail.cc>2023-01-15 13:26:14 +0000
commit96bd8086c75576cfd77d83e6122428490869740b (patch)
tree242d62e6f1cee88683edeb1a6d47b0ecedef9190 /macros
parentb2f27bd080dd52f1a4e93019701ad4254f5d6176 (diff)
downloadaegisub-scripts-96bd8086c75576cfd77d83e6122428490869740b.tar.gz
aegisub-scripts-96bd8086c75576cfd77d83e6122428490869740b.tar.bz2
aegisub-scripts-96bd8086c75576cfd77d83e6122428490869740b.zip
dupe and comment: format and comment new "do" implementation
i find it easier to read when the different parts are separated, and while i have done one-line `if this then do that end`s before, i've only ever done it for short operations where it's immediately obvious what's going on and you don't need to do any thinking whatsoever. e.g. this function from depctrl config: local function get_log_level(num) if num == 0 then return "0: Fatal" elseif num == 1 then return "1: Error" elseif num == 2 then return "2: Warning" elseif num == 3 then return "3: Hint" elseif num == 4 then return "4: Debug" elseif num == 5 then return "5: Trace" end return nil end I don't think the bits that fix sel and act count, at least not without comments. speaking of comments, i've added some. i hope i've understood what's going on correctly, please feel free to correct me if not.
Diffstat (limited to 'macros')
-rw-r--r--macros/garret.dupe-and-comment.lua19
1 files changed, 14 insertions, 5 deletions
diff --git a/macros/garret.dupe-and-comment.lua b/macros/garret.dupe-and-comment.lua
index f8e4b4b..f819d40 100644
--- a/macros/garret.dupe-and-comment.lua
+++ b/macros/garret.dupe-and-comment.lua
@@ -13,11 +13,20 @@ end
local function comment(subs, sel, act)
for i=#sel,1,-1 do
- local line=subs[sel[i]]
- line.comment = true
- subs.insert(sel[i]+1, line)
- for j=i+1,#sel do sel[j] = sel[j] + 1 end
- if act > sel[i] then act = act + 1 end
+ local line=subs[sel[i]] -- grab copy of current line
+
+ -- now use that copy for a different line
+ line.comment = true -- comment out the new dupe line
+ subs.insert(sel[i]+1, line) -- and put it below
+
+ -- sort out selection
+ for j=i+1,#sel do
+ sel[j] = sel[j] + 1 -- bump all of sel by 1 to compensate for new line
+ end -- first item isnt included because it's not affected
+
+ if act > sel[i] then -- if we've not got to the active line yet
+ act = act + 1 -- bump by 1 to compensate for new lines above
+ end
end
aegisub.set_undo_point(script_name)
return sel, act