-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cht
committed
Feb 16, 2022
1 parent
b64947c
commit afce27d
Showing
4 changed files
with
110 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
self = false | ||
|
||
ignore = { | ||
"631", -- max_line_length | ||
} | ||
|
||
-- Global objects defined by the C code | ||
globals = { | ||
"vim", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,84 @@ | ||
local api = vim.api | ||
|
||
local M = { | ||
winid = nil, | ||
buf = nil, | ||
mainwindowbuf = nil, | ||
before = 5, | ||
after = 5, | ||
winid = nil, | ||
buf = nil, | ||
mainwindowbuf = nil, | ||
before = 5, | ||
after = 5, | ||
} | ||
local highlight = require("csvtools.topbarhighlight") | ||
function M.NewWindow() | ||
if M.winid == nil then | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
--local file = vim.api.nvim_buf_get_name(0) | ||
--local f = io.open(file, "r") | ||
local messages = unpack(api.nvim_buf_get_lines(M.mainwindowbuf, 0, 1, true)) | ||
if messages == nil then | ||
return | ||
end | ||
--f:close() | ||
messages = messages:gsub("%,", "|") | ||
local buf = api.nvim_create_buf(false, true) -- create new emtpy buffer | ||
vim.cmd([[sview]]) | ||
api.nvim_win_set_height(0, 1) | ||
local win = vim.api.nvim_get_current_win() | ||
api.nvim_buf_set_lines(buf, 0, -1, false, { messages }) | ||
api.nvim_win_set_buf(win, buf) | ||
highlight.highlighttop(buf, messages) | ||
--api.nvim_buf_add_highlight(buf, -1, 'WhidHeader',0,0,1) | ||
--api.nvim_buf_add_highlight(buf, -1, 'WhidSubHeader', 0, 1, 2) | ||
M.winid = win | ||
M.buf = buf | ||
M.add_mappings() | ||
end | ||
if M.winid == nil then | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
--local file = vim.api.nvim_buf_get_name(0) | ||
--local f = io.open(file, "r") | ||
local messages = unpack(api.nvim_buf_get_lines(M.mainwindowbuf, 0, 1, true)) | ||
if messages == nil then | ||
return | ||
end | ||
--f:close() | ||
messages = messages:gsub("%,", "|") | ||
local buf = api.nvim_create_buf(false, true) -- create new emtpy buffer | ||
vim.cmd([[sview]]) | ||
api.nvim_win_set_height(0, 1) | ||
local win = vim.api.nvim_get_current_win() | ||
api.nvim_buf_set_lines(buf, 0, -1, false, { messages }) | ||
api.nvim_win_set_buf(win, buf) | ||
highlight.highlighttop(buf, messages) | ||
--api.nvim_buf_add_highlight(buf, -1, 'WhidHeader',0,0,1) | ||
--api.nvim_buf_add_highlight(buf, -1, 'WhidSubHeader', 0, 1, 2) | ||
M.winid = win | ||
M.buf = buf | ||
M.add_mappings() | ||
end | ||
end | ||
function M.CloseWindow() | ||
if M.winid ~= nil then | ||
vim.api.nvim_win_close(M.winid, true) | ||
M.winid = nil | ||
M.buf = nil | ||
end | ||
if M.winid ~= nil then | ||
vim.api.nvim_win_close(M.winid, true) | ||
M.winid = nil | ||
M.buf = nil | ||
end | ||
end | ||
local function getrange(line, length) | ||
local start = 1 | ||
if line - M.before > 1 then | ||
start = line - M.before | ||
end | ||
local final = length | ||
if line + M.after < length then | ||
final = line + M.after | ||
end | ||
return start, final | ||
local start = 1 | ||
if line - M.before > 1 then | ||
start = line - M.before | ||
end | ||
local final = length | ||
if line + M.after < length then | ||
final = line + M.after | ||
end | ||
return start, final | ||
end | ||
function M.Highlight() | ||
if vim.o.filetype == "csv" then | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
local line, _ = unpack(vim.api.nvim_win_get_cursor(0)) | ||
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf) | ||
local start, final = getrange(line, length) | ||
--print(start) | ||
--print(final) | ||
for i = start, line, 1 do | ||
highlight.highlight(M.mainwindowbuf, i) | ||
end | ||
for i = line, final, 1 do | ||
highlight.highlight(M.mainwindowbuf, i) | ||
end | ||
end | ||
if vim.o.filetype == "csv" then | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
local line, _ = unpack(vim.api.nvim_win_get_cursor(0)) | ||
local length = vim.api.nvim_buf_line_count(M.mainwindowbuf) | ||
local start, final = getrange(line, length) | ||
--print(start) | ||
--print(final) | ||
for i = start, line, 1 do | ||
highlight.highlight(M.mainwindowbuf, i) | ||
end | ||
for i = line, final, 1 do | ||
highlight.highlight(M.mainwindowbuf, i) | ||
end | ||
end | ||
end | ||
function M.add_mappings() | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
--print(M.mainwindowbuf) | ||
local opts = { nowait = true, noremap = true, silent = true } | ||
--vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>tf", ":lua require'csvtools'.NewWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.buf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<up>", ":lua require'csvtools'.Highlight()<cr>:-1<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<down>", ":lua require'csvtools'.Highlight()<cr>:+1<cr>", opts) | ||
M.mainwindowbuf = vim.api.nvim_get_current_buf() | ||
--print(M.mainwindowbuf) | ||
local opts = { nowait = true, noremap = true, silent = true } | ||
--vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>tf", ":lua require'csvtools'.NewWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.buf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<leader>td", ":lua require'csvtools'.CloseWindow()<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<up>", ":lua require'csvtools'.Highlight()<cr>:-1<cr>", opts) | ||
vim.api.nvim_buf_set_keymap(M.mainwindowbuf, "n", "<down>", ":lua require'csvtools'.Highlight()<cr>:+1<cr>", opts) | ||
end | ||
function M.setup(opts) | ||
M = vim.tbl_deep_extend("force", M, opts) | ||
M = vim.tbl_deep_extend("force", M, opts) | ||
end | ||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
local api = vim.api | ||
local M = {} | ||
function M.highlighttop(buf, line) | ||
local cout = 1 | ||
for i = 1, #line do | ||
if line:sub(i, i) ~= "|" then | ||
if cout % 2 == 0 then | ||
--print(line:sub(i, i)) | ||
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", 0, i - 1, i) | ||
else | ||
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", 0, i - 1, i) | ||
end | ||
else | ||
cout = cout + 1 | ||
end | ||
end | ||
local cout = 1 | ||
for i = 1, #line do | ||
if line:sub(i, i) ~= "|" then | ||
if cout % 2 == 0 then | ||
--print(line:sub(i, i)) | ||
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", 0, i - 1, i) | ||
else | ||
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", 0, i - 1, i) | ||
end | ||
else | ||
cout = cout + 1 | ||
end | ||
end | ||
end | ||
function M.highlight(buf, number) | ||
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true)) | ||
--print(line) | ||
local cout = 1 | ||
for i = 1, #line do | ||
if line:sub(i, i) ~= "," then | ||
if cout % 2 == 0 then | ||
--print(line:sub(i, i)) | ||
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", number - 1, i - 1, i) | ||
else | ||
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", number - 1, i - 1, i) | ||
end | ||
else | ||
cout = cout + 1 | ||
end | ||
end | ||
local line = unpack(vim.api.nvim_buf_get_lines(buf, number - 1, number, true)) | ||
--print(line) | ||
local cout = 1 | ||
for i = 1, #line do | ||
if line:sub(i, i) ~= "," then | ||
if cout % 2 == 0 then | ||
--print(line:sub(i, i)) | ||
api.nvim_buf_add_highlight(buf, -1, "WhidHeader", number - 1, i - 1, i) | ||
else | ||
api.nvim_buf_add_highlight(buf, -1, "WhidSubHeader", number - 1, i - 1, i) | ||
end | ||
else | ||
cout = cout + 1 | ||
end | ||
end | ||
end | ||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
column_width = 120 | ||
line_endings = "Unix" | ||
indent_type = "Spaces" | ||
#indent_width = 4 | ||
quote_style = "AutoPreferDouble" | ||
no_call_parentheses = false |