+42
-2
lines changedFilter options
+42
-2
lines changed Original file line number Diff line number Diff line change
@@ -1329,6 +1329,18 @@ paste({lines}, {phase}) *vim.paste()*
1329
1329
See also: ~
1330
1330
|paste|
1331
1331
1332
+
pretty_print({...}) *vim.pretty_print()*
1333
+
Prints given arguments in human-readable format. Example: >
1334
+
-- Print highlight group Normal and store it's contents in a variable.
1335
+
local hl_normal = vim.pretty_print(vim.api.nvim_get_hl_by_name("Normal", true))
1336
+
<
1337
+
1338
+
Return: ~
1339
+
given arguments.
1340
+
1341
+
See also: ~
1342
+
|vim.inspect()|
1343
+
1332
1344
region({bufnr}, {pos1}, {pos2}, {regtype}, {inclusive}) *vim.region()*
1333
1345
Get a table of lines with start, end columns for a region
1334
1346
marked by two points
Original file line number Diff line number Diff line change
@@ -1131,12 +1131,12 @@ void ex_lua(exarg_T *const eap)
1131
1131
}
1132
1132
// When =expr is used transform it to print(vim.inspect(expr))
1133
1133
if (code[0] == '=') {
1134
-
len += sizeof("print(vim.inspect())") - sizeof("=");
1134
+
len += sizeof("vim.pretty_print()") - sizeof("=");
1135
1135
// code_buf needs to be 1 char larger then len for null byte in the end.
1136
1136
// lua nlua_typval_exec doesn't expect null terminated string so len
1137
1137
// needs to end before null byte.
1138
1138
char *code_buf = xmallocz(len);
1139
-
vim_snprintf(code_buf, len+1, "print(vim.inspect(%s))", code+1);
1139
+
vim_snprintf(code_buf, len+1, "vim.pretty_print(%s)", code+1);
1140
1140
xfree(code);
1141
1141
code = code_buf;
1142
1142
}
Original file line number Diff line number Diff line change
@@ -689,4 +689,23 @@ vim._expand_pat_get_parts = function(lua_string)
689
689
return parts, search_index
690
690
end
691
691
692
+
---Prints given arguments in human-readable format.
693
+
---Example:
694
+
---<pre>
695
+
--- -- Print highlight group Normal and store it's contents in a variable.
696
+
--- local hl_normal = vim.pretty_print(vim.api.nvim_get_hl_by_name("Normal", true))
697
+
---</pre>
698
+
---@see |vim.inspect()|
699
+
---@return given arguments.
700
+
function vim.pretty_print(...)
701
+
local objects = {}
702
+
for i = 1, select('#', ...) do
703
+
local v = select(i, ...)
704
+
table.insert(objects, vim.inspect(v))
705
+
end
706
+
707
+
print(table.concat(objects, ' '))
708
+
return ...
709
+
end
710
+
692
711
return module
Original file line number Diff line number Diff line change
@@ -149,6 +149,15 @@ describe(':lua command', function()
149
149
eq([["hello"]], helpers.exec_capture(':lua = x()'))
150
150
helpers.exec_lua("x = {a = 1, b = 2}")
151
151
eq("{\n a = 1,\n b = 2\n}", helpers.exec_capture(':lua =x'))
152
+
helpers.exec_lua([[function x(success)
153
+
if success then
154
+
return true, "Return value"
155
+
else
156
+
return false, nil, "Error message"
157
+
end
158
+
end]])
159
+
eq([[true "Return value"]], helpers.exec_capture(':lua =x(true)'))
160
+
eq([[false nil "Error message"]], helpers.exec_capture(':lua =x(false)'))
152
161
end)
153
162
end)
154
163
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4