aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2020-03-11 13:48:39 +0100
committerMatěj Cepl <mcepl@cepl.eu>2020-03-11 13:48:39 +0100
commit4385b7eb94b953d90a533fd54e00e89417679846 (patch)
tree75cdfb6f8b0d38457a2fcadc0db13a50ccc0bcab /init.lua
parent188a52f7341b8099610f5c00061e89c1963a4218 (diff)
downloadvis-jump-4385b7eb94b953d90a533fd54e00e89417679846.tar.gz
Some progress, but not good <cword> implementation yet.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua24
1 files changed, 20 insertions, 4 deletions
diff --git a/init.lua b/init.lua
index c4dab36..584325e 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,21 @@
-vis:map(vis.modes.NORMAL, "gx", function(keys)
- local handle = io.popen("xdg-open https://reddit.com")
- local data = handle:read()
- local success, msg, status = handle:close()
+local function get_query()
+ local line = vis.win.selection.line
+ local pos = vis.win.selection.col
+ local str = vis.win.file.lines[line]
+
+ 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
+ end
+
+ return string.sub(str, from, to)
+end
+
+vis:map(vis.modes.NORMAL, "gx", function()
+ local cur_word = get_query()
+ print(cur_word)
+ os.execute("xdg-open " .. cur_word)
end, "Jump to URL")