aboutsummaryrefslogtreecommitdiffstats
path: root/macros/em-dash.lua
blob: 3dfe6965b9a576c9545c1c0ba9abb4e5c3c6e141 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
script_name = "Em-dash"
script_description = "I do not have an em-dash key on my keyboard"
script_author = "garret"
script_version = "2.0.0"

local em = "—"

local function append(sub, sel)
	for si, li in ipairs(sel) do
		local line = sub[li]
		if string.sub(line.text, -1) == "-" then
			line.text = line.text:sub(1, #line.text - 1)
		end
			line.text = line.text..em
		sub[li] = line
	end
	aegisub.set_undo_point(script_name)
end

function replace(sub, sel)
    for si, li in ipairs(sel) do
        local line = sub[li]
        local text = sub[li].text
        text = text:gsub("%-%-",em)
    	line.text=text
        sub[li] = line
    end
	aegisub.set_undo_point(script_name)
end

aegisub.register_macro(script_name.."/Append", "Appends an Em-dash to the selected line(s)", append)
aegisub.register_macro(script_name.."/Replace", "Replaces -- with "..em, replace)