diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2020-03-16 23:09:07 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2020-03-16 23:09:07 +0100 |
commit | 65940dace47b7813516c59a03141d10083ce1247 (patch) | |
tree | 04d1e5ef9f1dd5d3f04941868666f288aef5f158 | |
parent | 4385b7eb94b953d90a533fd54e00e89417679846 (diff) | |
download | vis-jump-65940dace47b7813516c59a03141d10083ce1247.tar.gz |
First working version.
-rw-r--r-- | init.lua | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -2,20 +2,23 @@ local function get_query() local line = vis.win.selection.line local pos = vis.win.selection.col local str = vis.win.file.lines[line] + local len_str = string.len(str) - local from, to = 0, 0 - while pos > to do - from, to = str:find('[%a_]+[%a%d_]*', to + 1) - if from == nil or from > pos then - return nil - end + local to = str:find('%s', pos) - 1 + if to == nil then to = string.len(str) end + local from = str:reverse():find('%s', len_str - pos + 1) + if from == nil then + from = 1 + else + -- reverse index + from = len_str - from + 2 end - - return string.sub(str, from, to) + return str:sub(from, to) end vis:map(vis.modes.NORMAL, "gx", function() local cur_word = get_query() - print(cur_word) - os.execute("xdg-open " .. cur_word) + -- https://bugs.freedesktop.org/show_bug.cgi?id=103807 x + -- https://www.damejidlo.cz/potrefena-husa-vinohrady + os.execute("xdg-open '" .. cur_word .. "'") end, "Jump to URL") |