Skip to content

Commit afce27d

Browse files
author
cht
committed
format
1 parent b64947c commit afce27d

4 files changed

Lines changed: 110 additions & 94 deletions

File tree

.luacheckrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
self = false
2+
3+
ignore = {
4+
"631", -- max_line_length
5+
}
6+
7+
-- Global objects defined by the C code
8+
globals = {
9+
"vim",
10+
}

lua/csvtools.lua

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
local api = vim.api
22

33
local M = {
4-
winid = nil,
5-
buf = nil,
6-
mainwindowbuf = nil,
7-
before = 5,
8-
after = 5,
4+
winid = nil,
5+
buf = nil,
6+
mainwindowbuf = nil,
7+
before = 5,
8+
after = 5,
99
}
1010
local highlight = require("csvtools.topbarhighlight")
1111
function M.NewWindow()
12-
if M.winid == nil then
13-
M.mainwindowbuf = vim.api.nvim_get_current_buf()
14-
--local file = vim.api.nvim_buf_get_name(0)
15-
--local f = io.open(file, "r")
16-
local messages = unpack(api.nvim_buf_get_lines(M.mainwindowbuf, 0, 1, true))
17-
if messages == nil then
18-
return
19-
end
20-
--f:close()
21-
messages = messages:gsub("%,", "|")
22-
local buf = api.nvim_create_buf(false, true) -- create new emtpy buffer
23-
vim.cmd([[sview]])
24-
api.nvim_win_set_height(0, 1)
25-
local win = vim.api.nvim_get_current_win()
26-
api.nvim_buf_set_lines(buf, 0, -1, false, { messages })
27-
api.nvim_win_set_buf(win, buf)
28-
highlight.highlighttop(buf, messages)
29-
--api.nvim_buf_add_highlight(buf, -1, 'WhidHeader',0,0,1)
30-
--api.nvim_buf_add_highlight(buf, -1, 'WhidSubHeader', 0, 1, 2)
31-
M.winid = win
32-
M.buf = buf
33-
M.add_mappings()
34-
end
12+
if M.winid == nil then
13+
M.mainwindowbuf = vim.api.nvim_get_current_buf()
14+
--local file = vim.api.nvim_buf_get_name(0)
15+
--local f = io.open(file, "r")
16+
local messages = unpack(api.nvim_buf_get_lines(M.mainwindowbuf, 0, 1, true))
17+
if messages == nil then
18+
return
19+
end
20+
--f:close()
21+
messages = messages:gsub("%,", "|")
22+
local buf = api.nvim_create_buf(false, true) -- create new emtpy buffer
23+
vim.cmd([[sview]])
24+
api.nvim_win_set_height(0, 1)
25+
local win = vim.api.nvim_get_current_win()
26+
api.nvim_buf_set_lines(buf, 0, -1, false, { messages })
27+
api.nvim_win_set_buf(win, buf)
28+
highlight.highlighttop(buf, messages)
29+
--api.nvim_buf_add_highlight(buf, -1, 'WhidHeader',0,0,1)
30+
--api.nvim_buf_add_highlight(buf, -1, 'WhidSubHeader', 0, 1, 2)
31+
M.winid = win
32+
M.buf = buf
33+
M.add_mappings()
34+
end
3535
end
3636
function M.CloseWindow()
37-
if M.winid ~= nil then
38-
vim.api.nvim_win_close(M.winid, true)
39-
M.winid = nil
40-
M.buf = nil
41-
end
37+
if M.winid ~= nil then
38+
vim.api.nvim_win_close(M.winid, true)
39+
M.winid = nil
40+
M.buf = nil
41+
end
4242
end
4343
local function getrange(line, length)
44-
local start = 1
45-
if line - M.before > 1 then
46-
start = line - M.before
47-
end
48-
local final = length
49-
if line + M.after < length then
50-
final = line + M.after
51-
end
52-
return start, final
44+
local start = 1
45+
if line - M.before > 1 then
46+
start = line - M.before
47+
end
48+
local final = length
49+
if line + M.after < length then
50+
final = line + M.after
51+
end
52+
return start, final
5353
end
5454
function M.Highlight()
55-
if vim.o.filetype == "csv" then
56-
M.mainwindowbuf = vim.api.nvim_get_current_buf()
57-
local line, _ = unpack(vim.api.nvim_win_get_cursor(0))
58-
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf)
59-
local start, final = getrange(line, length)
60-
--print(start)
61-
--print(final)
62-
for i = start, line, 1 do
63-
highlight.highlight(M.mainwindowbuf, i)
64-
end
65-
for i = line, final, 1 do
66-
highlight.highlight(M.mainwindowbuf, i)
67-
end
68-
end
55+
if vim.o.filetype == "csv" then
56+
M.mainwindowbuf = vim.api.nvim_get_current_buf()
57+
local line, _ = unpack(vim.api.nvim_win_get_cursor(0))
58+
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf)
59+
local start, final = getrange(line, length)
60+
--print(start)
61+
--print(final)
62+
for i = start, line, 1 do
63+
highlight.highlight(M.mainwindowbuf, i)
64+
end
65+
for i = line, final, 1 do
66+
highlight.highlight(M.mainwindowbuf, i)
67+
end
68+
end
6969
end
7070
function M.add_mappings()
71-
M.mainwindowbuf = vim.api.nvim_get_current_buf()
72-
--print(M.mainwindowbuf)
73-
local opts = { nowait = true, noremap = true, silent = true }
74-
--vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts)
75-
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>tf", ":lua require'csvtools'.NewWindow()<cr>", opts)
76-
vim.api.nvim_buf_set_keymap(M.buf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts)
77-
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts)
78-
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<up>", ":lua require'csvtools'.Highlight()<cr>:-1<cr>", opts)
79-
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<down>", ":lua require'csvtools'.Highlight()<cr>:+1<cr>", opts)
71+
M.mainwindowbuf = vim.api.nvim_get_current_buf()
72+
--print(M.mainwindowbuf)
73+
local opts = { nowait = true, noremap = true, silent = true }
74+
--vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts)
75+
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>tf", ":lua require'csvtools'.NewWindow()<cr>", opts)
76+
vim.api.nvim_buf_set_keymap(M.buf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts)
77+
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts)
78+
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<up>", ":lua require'csvtools'.Highlight()<cr>:-1<cr>", opts)
79+
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<down>", ":lua require'csvtools'.Highlight()<cr>:+1<cr>", opts)
8080
end
8181
function M.setup(opts)
82-
M = vim.tbl_deep_extend("force", M, opts)
82+
M = vim.tbl_deep_extend("force", M, opts)
8383
end
8484
return M

lua/csvtools/topbarhighlight.lua

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
local api = vim.api
22
local M = {}
33
function M.highlighttop(buf, line)
4-
local cout = 1
5-
for i = 1, #line do
6-
if line:sub(i, i) ~= "|" then
7-
if cout % 2 == 0 then
8-
--print(line:sub(i, i))
9-
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", 0, i - 1, i)
10-
else
11-
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", 0, i - 1, i)
12-
end
13-
else
14-
cout = cout + 1
15-
end
16-
end
4+
local cout = 1
5+
for i = 1, #line do
6+
if line:sub(i, i) ~= "|" then
7+
if cout % 2 == 0 then
8+
--print(line:sub(i, i))
9+
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", 0, i - 1, i)
10+
else
11+
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", 0, i - 1, i)
12+
end
13+
else
14+
cout = cout + 1
15+
end
16+
end
1717
end
1818
function M.highlight(buf, number)
19-
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true))
20-
--print(line)
21-
local cout = 1
22-
for i = 1, #line do
23-
if line:sub(i, i) ~= "," then
24-
if cout % 2 == 0 then
25-
--print(line:sub(i, i))
26-
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", number - 1, i - 1, i)
27-
else
28-
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", number - 1, i - 1, i)
29-
end
30-
else
31-
cout = cout + 1
32-
end
33-
end
19+
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true))
20+
--print(line)
21+
local cout = 1
22+
for i = 1, #line do
23+
if line:sub(i, i) ~= "," then
24+
if cout % 2 == 0 then
25+
--print(line:sub(i, i))
26+
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", number - 1, i - 1, i)
27+
else
28+
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", number - 1, i - 1, i)
29+
end
30+
else
31+
cout = cout + 1
32+
end
33+
end
3434
end
3535
return M

stylua.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
column_width = 120
2+
line_endings = "Unix"
3+
indent_type = "Spaces"
4+
#indent_width = 4
5+
quote_style = "AutoPreferDouble"
6+
no_call_parentheses = false

0 commit comments

Comments
 (0)