2022-12-14 02:46:54 -07:00
|
|
|
vim.api.nvim_create_user_command('Inspect', function(cmd)
|
|
|
|
if cmd.bang then
|
refactor!: rename vim.pretty_print => vim.print
Problem:
The function name `vim.pretty_print`:
1. is verbose, which partially defeats its purpose as sugar
2. does not draw from existing precedent or any sort of convention
(except external projects like penlight or python?), which reduces
discoverability, and degrades signaling about best practices.
Solution:
- Rename to `vim.print`.
- Change the behavior so that
1. strings are printed without quotes
2. each arg is printed on its own line
3. tables are indented with 2 instead of 4 spaces
- Example:
:lua ='a', 'b', 42, {a=3}
a
b
42
{
a = 3
}
Comparison of alternatives:
- `vim.print`:
- pro: consistent with Lua's `print()`
- pro: aligns with potential `nvim_print` API function which will
replace nvim_echo, nvim_notify, etc.
- con: behaves differently than Lua's `print()`, slightly misleading?
- `vim.echo`:
- pro: `:echo` has similar "pretty print" behavior.
- con: inconsistent with Lua idioms.
- `vim.p`:
- pro: very short, fits with `vim.o`, etc.
- con: not as discoverable as "echo"
- con: less opportunity for `local p = vim.p` because of potential shadowing.
2023-03-07 08:04:57 -07:00
|
|
|
vim.print(vim.inspect_pos())
|
2022-12-14 02:46:54 -07:00
|
|
|
else
|
|
|
|
vim.show_pos()
|
|
|
|
end
|
|
|
|
end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })
|
2023-03-02 10:03:11 -07:00
|
|
|
|
2023-03-17 04:41:57 -07:00
|
|
|
vim.api.nvim_create_user_command('InspectTree', function(cmd)
|
|
|
|
if cmd.mods ~= '' or cmd.count ~= 0 then
|
|
|
|
local count = cmd.count ~= 0 and cmd.count or ''
|
|
|
|
local new = cmd.mods ~= '' and 'new' or 'vnew'
|
|
|
|
|
|
|
|
vim.treesitter.inspect_tree({
|
|
|
|
command = ('%s %s%s'):format(cmd.mods, count, new),
|
|
|
|
})
|
|
|
|
else
|
|
|
|
vim.treesitter.inspect_tree()
|
|
|
|
end
|
|
|
|
end, { desc = 'Inspect treesitter language tree for buffer', count = true })
|