aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/lua.txt12
-rw-r--r--runtime/doc/news.txt4
-rw-r--r--runtime/lua/vim/shared.lua27
3 files changed, 43 insertions, 0 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index 49b5c9da70..f325c58efb 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1694,6 +1694,18 @@ pesc({s}) *vim.pesc()*
See also: ~
https://github.com/rxi/lume
+spairs({t}) *vim.spairs()*
+ Enumerate a table sorted by its keys.
+
+ Parameters: ~
+ • {t} (table) List-like table
+
+ Return: ~
+ iterator over sorted keys and their values
+
+ See also: ~
+ Based on https://github.com/premake/premake-core/blob/master/src/base/table.lua
+
split({s}, {sep}, {kwargs}) *vim.split()*
Splits a string at each instance of a separator.
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 8a9736e1c2..83272a0d87 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -143,6 +143,10 @@ The following new APIs or features were added.
instance in the background and display its UI on demand, which previously
only was possible using an external UI implementation.
+• Several improvements were made to make the code generation scripts more
+ deterministic, and a `LUA_GEN_PRG` build parameter has been introduced to
+ allow for a workaround for some remaining reproducibility problems.
+
==============================================================================
CHANGED FEATURES *news-changes*
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 7967d13943..cc48e3f193 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -458,6 +458,33 @@ function vim.tbl_flatten(t)
return result
end
+--- Enumerate a table sorted by its keys.
+---
+---@see Based on https://github.com/premake/premake-core/blob/master/src/base/table.lua
+---
+---@param t table List-like table
+---@return iterator over sorted keys and their values
+function vim.spairs(t)
+ assert(type(t) == 'table', string.format('Expected table, got %s', type(t)))
+
+ -- collect the keys
+ local keys = {}
+ for k in pairs(t) do
+ table.insert(keys, k)
+ end
+ table.sort(keys)
+
+ -- Return the iterator function.
+ -- TODO(justinmk): Return "iterator function, table {t}, and nil", like pairs()?
+ local i = 0
+ return function()
+ i = i + 1
+ if keys[i] then
+ return keys[i], t[keys[i]]
+ end
+ end
+end
+
--- Tests if a Lua table can be treated as an array.
---
--- Empty table `{}` is assumed to be an array, unless it was created by