From 8a69569980e4f24642cf4270a6be53c9957aea2b Mon Sep 17 00:00:00 2001 From: Georgi Kirilov <> Date: Sun, 22 Nov 2020 15:10:49 +0200 Subject: DRY fixes --- pairs.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pairs.lua b/pairs.lua index 16b53c4..3b97ddf 100644 --- a/pairs.lua +++ b/pairs.lua @@ -297,15 +297,15 @@ vis.events.subscribe(vis.events.INIT, function() outer = new(vis.textobject, vis.textobject_register, M.prefix.outer, handler(outer), "Delimited block (outer variant)"), } - local tex_environment = {"\\begin{" * l.Cg(l.R("az", "AZ")^1, "t") * "}", l.Cmt("\\end{" * l.Cb("t") * l.C((1 - l.P"}")^1) * "}", function(_, _, c1, c2) return c1 == c2 end), {"\\begin{\xef\xbf\xbd}", "\\end{\xef\xbf\xbd}"}, "environment name"} + local function cmp(_, _, c1, c2) return c1 == c2 end + local function casecmp(_, _, c1, c2) return c1:lower() == c2:lower() end + local function closing(cmpfunc, s1, s2) return l.Cmt(s1 * l.Cb("t") * l.C((1 - l.P(s2))^1) * s2, cmpfunc) end + local tex_environment = {"\\begin{" * l.Cg(l.R("az", "AZ")^1, "t") * "}", closing(cmp, "\\end{", "}"), {"\\begin{\xef\xbf\xbd}", "\\end{\xef\xbf\xbd}"}, "environment name"} local function is(_, _, v) return v ~= 1 end local tag_name = (l.S"_:" + l.R("az", "AZ")) * (l.R("az", "AZ", "09") + l.S"_:.-")^0 - local function closing(cmpfunc) return l.Cmt(l.Cb("t") * l.C((1 - l.P">")^1), cmpfunc) end local noslash = l.Cmt(l.Cb("t") / string.lower / {--[[implicit:]] p=1, dt=1, dd=1, li=1, --[[void:]] img=1, input=1, hr=1, br=1, link=1, meta=1}, is) - local function casecmp(_, _, c1, c2) return c1:lower() == c2:lower() end - local html_tag = {"<" * l.Cg(tag_name, "t") * noslash * (1 - l.S"><")^0 * (">" - l.B"/"), "", {"<\xef\xbf\xbd>", ""}, "tag name"} - local function cmp(_, _, c1, c2) return c1 == c2 end - local xml_tag = {"<" * l.Cg(tag_name, "t") * (1 - l.S"><")^0 * (">" - l.B"/"), "", {"<\xef\xbf\xbd>", ""}, "tag name"} + local html_tag = {"<" * l.Cg(tag_name, "t") * noslash * (1 - l.S"><")^0 * (">" - l.B"/"), closing(casecmp, ""), {"<\xef\xbf\xbd>", ""}, "tag name"} + local xml_tag = {"<" * l.Cg(tag_name, "t") * (1 - l.S"><")^0 * (">" - l.B"/"), closing(cmp, ""), {"<\xef\xbf\xbd>", ""}, "tag name"} local function any_pair(set, default) return {l.Cg(l.S(set), "s"), l.Cmt(l.Cb("s") * l.C(1), function(_, _, c1, c2) return builtin_textobjects[c1][2] == c2 end), builtin_textobjects[default]} end local any_bracket = any_pair("({[", "(") local presets = { -- cgit