mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
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.
This commit is contained in:
@@ -6,6 +6,7 @@ local nvim_prog = helpers.nvim_prog
|
||||
local funcs = helpers.funcs
|
||||
local meths = helpers.meths
|
||||
local command = helpers.command
|
||||
local dedent = helpers.dedent
|
||||
local insert = helpers.insert
|
||||
local clear = helpers.clear
|
||||
local eq = helpers.eq
|
||||
@@ -2269,7 +2270,7 @@ describe('lua stdlib', function()
|
||||
|
||||
describe('vim.region', function()
|
||||
it('charwise', function()
|
||||
insert(helpers.dedent( [[
|
||||
insert(dedent( [[
|
||||
text tααt tααt text
|
||||
text tαxt txtα tex
|
||||
text tαxt tαxt
|
||||
@@ -2923,6 +2924,24 @@ describe('lua stdlib', function()
|
||||
{4:-- Omni completion (^O^N^P) }{5:match 1 of 2} |
|
||||
]]}
|
||||
end)
|
||||
|
||||
it('vim.print', function()
|
||||
-- vim.print() returns its args.
|
||||
eq({42, 'abc', { a = { b = 77 }}},
|
||||
exec_lua[[return {vim.print(42, 'abc', { a = { b = 77 }})}]])
|
||||
|
||||
-- vim.print() pretty-prints the args.
|
||||
eq(dedent[[
|
||||
|
||||
42
|
||||
abc
|
||||
{
|
||||
a = {
|
||||
b = 77
|
||||
}
|
||||
}]],
|
||||
eval[[execute('lua vim.print(42, "abc", { a = { b = 77 }})')]])
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lua: builtin modules', function()
|
||||
|
Reference in New Issue
Block a user