aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2022-01-15 13:07:10 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2022-01-15 13:07:10 +0530
commitd9063a1e2aaeab2e231b1e12ccb8f30413743923 (patch)
treea60abdd23780ae07919fe5fef9d3b6babbe631a2
parent44dd260faad218bb05171c28e2af0c03cf73cb05 (diff)
downloaddotfiles-d9063a1e2aaeab2e231b1e12ccb8f30413743923.tar.gz
nvim: rework fzy jump to use nvim_open_win()
-rw-r--r--config/nvim/init.lua1
-rw-r--r--config/nvim/lua/fzy/fzy.lua42
-rw-r--r--config/nvim/lua/fzy/jump.lua38
-rw-r--r--config/nvim/lua/settings.lua2
4 files changed, 55 insertions, 28 deletions
diff --git a/config/nvim/init.lua b/config/nvim/init.lua
index bb21870..ff59ec8 100644
--- a/config/nvim/init.lua
+++ b/config/nvim/init.lua
@@ -22,6 +22,7 @@ require('settings')
22require('maps') 22require('maps')
23require('statusline.line') 23require('statusline.line')
24require('treesitter') 24require('treesitter')
25require('fzy/fzy')
25 26
26-- lsp setup 27-- lsp setup
27-- require('lsp.yaml') shits too noisy 28-- require('lsp.yaml') shits too noisy
diff --git a/config/nvim/lua/fzy/fzy.lua b/config/nvim/lua/fzy/fzy.lua
new file mode 100644
index 0000000..9ac1b37
--- /dev/null
+++ b/config/nvim/lua/fzy/fzy.lua
@@ -0,0 +1,42 @@
1local M = {}
2local api = vim.api
3local o = vim.o
4local fn = vim.fn
5
6function M.fzy_search(cmd, exit_fn)
7 local width = o.columns - 4
8 local height = 11
9 if (o.columns >= 85) then
10 width = 80
11 end
12
13 buf = api.nvim_create_buf(false, true)
14 api.nvim_buf_set_option(buf, 'bufhidden', 'wipe')
15 api.nvim_buf_set_option(buf, 'modifiable', true)
16
17 api.nvim_open_win(
18 buf,
19 true,
20 {
21 relative = 'editor',
22 style = 'minimal',
23 noautocmd = true,
24 border = 'none',
25 width = width,
26 height = height,
27 col = math.min((o.columns - width) / 2),
28 row = math.min((o.lines - height) / 2 - 1),
29 }
30 )
31 local file = vim.fn.tempname()
32 api.nvim_command('startinsert!')
33
34 vim.fn.termopen(cmd .. ' > ' .. file, {on_exit = function()
35 local f = io.open(file, 'r')
36 stdout = f:read('*all')
37 exit_fn(stdout)
38 f:close()
39 os.remove(file)
40 end})
41end
42return M
diff --git a/config/nvim/lua/fzy/jump.lua b/config/nvim/lua/fzy/jump.lua
index e3e3791..5a723f8 100644
--- a/config/nvim/lua/fzy/jump.lua
+++ b/config/nvim/lua/fzy/jump.lua
@@ -9,7 +9,6 @@ local function get_line_nr(s)
9 end 9 end
10end 10end
11 11
12
13local function annotated_input() 12local function annotated_input()
14 local lines = {} 13 local lines = {}
15 14
@@ -20,7 +19,6 @@ local function annotated_input()
20 table.insert(lines, fn.getline(nr)) 19 table.insert(lines, fn.getline(nr))
21 end 20 end
22 21
23
24 local outfile = fn.tempname() 22 local outfile = fn.tempname()
25 local f = io.open(outfile, 'a') 23 local f = io.open(outfile, 'a')
26 for n, l in pairs(lines) do 24 for n, l in pairs(lines) do
@@ -32,39 +30,25 @@ local function annotated_input()
32end 30end
33 31
34function M.fzy_jmp() 32function M.fzy_jmp()
35 local outfile = fn.tempname()
36 local idxfile, lines = annotated_input() 33 local idxfile, lines = annotated_input()
37 shell_cmd = {
38 '/bin/sh',
39 '-c',
40 'fzy -p "jmp > " < ' .. idxfile .. ' > ' .. outfile
41 }
42
43 winid = fn.win_getid()
44 -- start a new buffer
45 cmd('botright 10 new')
46 cmd('startinsert')
47
48 fn.termopen(shell_cmd, { on_exit = function()
49 -- delete buffer on exit
50 cmd('bd!')
51 fn.win_gotoid(winid)
52 34
53 -- read contents of file 35 fzy_cmd = {
54 local f = io.open(outfile, 'r') 36 'fzy -p "jmp > " ',
55 line_choice = f:read('*all') 37 '< ' .. idxfile,
38 }
56 39
40 require('fzy/fzy').fzy_search(table.concat(fzy_cmd), function(stdout)
57 -- strip '\n' 41 -- strip '\n'
58 selected, _ = string.gsub(line_choice, '\n', '') 42 local selected, _ = stdout:gsub('\n', '')
43 cmd('bd!')
59 44
45 print(get_line_nr(selected))
60 -- jump to line 46 -- jump to line
61 cmd(':' .. get_line_nr(selected)) 47 cmd(':' .. get_line_nr(selected))
62
63 -- housekeeping 48 -- housekeeping
64 f:close()
65 os.remove(outfile)
66 os.remove(idxfile) 49 os.remove(idxfile)
67 end }) 50 end
68end 51 )
69 52
53end
70return M 54return M
diff --git a/config/nvim/lua/settings.lua b/config/nvim/lua/settings.lua
index e5b362f..b64692d 100644
--- a/config/nvim/lua/settings.lua
+++ b/config/nvim/lua/settings.lua
@@ -46,7 +46,7 @@ vim.cmd("syntax on")
46vim.cmd('colorscheme plain') 46vim.cmd('colorscheme plain')
47 47
48vim.cmd('au TextYankPost * lua vim.highlight.on_yank{timeout=200}') 48vim.cmd('au TextYankPost * lua vim.highlight.on_yank{timeout=200}')
49o.background = 'dark' 49o.background = 'light'
50 50
51-- gitgutter options 51-- gitgutter options
52g.gitgutter_override_sign_column_highlight = 0 52g.gitgutter_override_sign_column_highlight = 0