summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/warp/col_selectors/grid.lua56
1 files changed, 27 insertions, 29 deletions
diff --git a/lua/warp/col_selectors/grid.lua b/lua/warp/col_selectors/grid.lua
index e00d590..ce99b96 100644
--- a/lua/warp/col_selectors/grid.lua
+++ b/lua/warp/col_selectors/grid.lua
@@ -3,41 +3,39 @@ local vim = assert(vim)
local util = require('warp.util')
local M = {}
-local hsel1 = "thnrdlcmwfpgkbvjxzq" -- 19
-local hsel2 = "aeiouys" -- 7
-
-local function char_at(s, i)
- local m = (i % #s) + 1
- return string.sub(s, m, m)
-end
-
-local function make_big_line()
- local col = 0
- local line = ''
-
- local v = ''
- local c = nil
- local i = 0
+local big_line, col_map = (function ()
+ -- Longest possible line alternating between vowels and (vowels + consanants)
+ -- which does not have a repeated substring of length 2.
+ --
+ -- Size is 5*(26 + 21) + 1
+ --
+ -- It can reference up 235 unique columns. That should be enough even for
+ -- Java.
+ local big_line =
+ "tetaoinuserahodilucemafoyiwugepabovikuxeqajozitunesarohidulecamofiyuw"
+ .. "egapobivukexaqojizutonasirehudelacomifuyewagopibuvekaxoqijuzenotisuri"
+ .. "hadalocumefeyawogipubevakoxiqujezanicimuhedosorufayoligupebavowixuqej"
+ .. "azokieaueoaiuaeiouooeeuuiiaat"
local col_map = {}
- while true do
- v = char_at(hsel1, i)
- if c then
- if col_map[c .. v] then break end
- col_map[c .. v] = col
+ local i = 0
+
+ while i < #big_line do
+ local sub = big_line:sub(i, i + 1)
+ if col_map[sub] then
+ -- Sanity check
+ error("repeated sequence: '" .. sub .. "'", 2)
end
- c = char_at(hsel2, i)
- col = col + 1
- if col_map[v .. c] then break end
- col_map[v .. c] = col
- line = line .. v .. c
- col = col + 1
+ col_map[sub] = i
i = i + 1
end
- return line, col_map
-end
+ return big_line, col_map
+end)()
-local big_line, col_map = make_big_line()
+local function char_at(s, i)
+ local m = (i % #s) + 1
+ return string.sub(s, m, m)
+end
M.strategy = function()
local filter