Skip to content

Commit 7727353

Browse files
author
Andrew Ferrier
committed
feat: First commit
0 parents  commit 7727353

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# debugprint.nvim

lua/debugprint/init.lua

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
local M = {}
2+
3+
local opts
4+
5+
-- TODO:
6+
-- * Implement debugprintvar()
7+
-- * Implement if on top of a variable using treesitter, then debugprintvar() is one-click
8+
-- * Make dot-repeatable
9+
-- * Make debuginfo() overridable
10+
-- * Support callbacks for different filetype surroundings, with example for NeoVim lua
11+
-- * Indent correctly (look at how nvim-surround does it)
12+
-- * Use treesitter to get location
13+
14+
OPTION_DEFAULTS = {
15+
create_keymaps = true,
16+
filetypes = {
17+
["lua"] = { "print('", "')" },
18+
},
19+
}
20+
21+
local counter = 0
22+
23+
local debuginfo = function()
24+
local current_line = vim.api.nvim_win_get_cursor(0)[1]
25+
counter = counter + 1
26+
27+
return "DEBUG: " .. vim.fn.expand("%:t") .. ":" .. current_line .. " [" .. counter .. "]"
28+
end
29+
30+
M.debugprint = function(above)
31+
local current_line = vim.api.nvim_win_get_cursor(0)[1]
32+
local filetype = vim.api.nvim_get_option_value("filetype", {})
33+
local indent = string.rep(" ", vim.fn.indent(current_line))
34+
35+
local line_to_insert = indent
36+
.. opts.filetypes[filetype][1]
37+
.. debuginfo()
38+
.. opts.filetypes[filetype][2]
39+
40+
local line_to_insert_on
41+
42+
if above then
43+
line_to_insert_on = current_line - 1
44+
else
45+
line_to_insert_on = current_line
46+
end
47+
48+
vim.api.nvim_buf_set_lines(
49+
0,
50+
line_to_insert_on,
51+
line_to_insert_on,
52+
true,
53+
{ line_to_insert }
54+
)
55+
end
56+
57+
M.debugprintvar = function(above)
58+
end
59+
60+
M.setup = function(o)
61+
opts = vim.tbl_deep_extend("force", OPTION_DEFAULTS, o or {})
62+
63+
vim.validate({
64+
create_keymaps = { opts.create_keymaps, "boolean" },
65+
})
66+
67+
if opts.create_keymaps then
68+
vim.keymap.set("n", "dqp", function()
69+
M.debugprint(false)
70+
end)
71+
vim.keymap.set("n", "dqP", function()
72+
M.debugprint(true)
73+
end)
74+
vim.keymap.set("n", "dQp", function()
75+
M.debugprintvar(false)
76+
end)
77+
vim.keymap.set("n", "dQP", function()
78+
M.debugprintvar(true)
79+
end)
80+
end
81+
end
82+
83+
return M

0 commit comments

Comments
 (0)