From b102c11e3860985e25b7baf48bba079f5042125a Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 29 Mar 2019 21:54:34 +0100 Subject: gen_vimdoc.py: get Lua docs via lua2dox.lua #9740 --- src/Doxyfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Doxyfile b/src/Doxyfile index de31c8355f..461fafe99d 100644 --- a/src/Doxyfile +++ b/src/Doxyfile @@ -243,7 +243,7 @@ OPTIMIZE_OUTPUT_VHDL = NO # that for custom extensions you also need to set FILE_PATTERNS otherwise the # files are not read by doxygen. -EXTENSION_MAPPING = +EXTENSION_MAPPING = lua=C # If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all # comments according to the Markdown format, which allows for more readable @@ -672,7 +672,7 @@ INPUT_ENCODING = UTF-8 # *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py # *.f90 *.f *.for *.vhd *.vhdl -FILE_PATTERNS = *.h *.c +FILE_PATTERNS = *.h *.c *.lua # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. @@ -758,7 +758,7 @@ INPUT_FILTER = # info on how filters are used. If FILTER_PATTERNS is empty or if # non of the patterns match the file name, INPUT_FILTER is applied. -FILTER_PATTERNS = +FILTER_PATTERNS = *.lua=scripts/lua2dox_filter # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source -- cgit From 53576dfb3598244afba3dbf5b60e6113109bf7c6 Mon Sep 17 00:00:00 2001 From: KillTheMule Date: Fri, 29 Mar 2019 21:56:38 +0100 Subject: Document the vim.lua functions --- src/nvim/lua/vim.lua | 59 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 1a7aec6cc6..9e592e444b 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -154,6 +154,18 @@ local function _update_package_paths() last_nvim_paths = cur_nvim_paths end +---Split a string by a given separator. The separator can be a lua pattern, see [1]. +---Used by |vim.split()|, see there for some examples. See [2] +---for usage of the plain parameter. +--- +--- [1] https://www.lua.org/pil/20.2.html. +--- +--- [2] http://lua-users.org/wiki/StringLibraryTutorial +--@param s String The string to split +--@param sep String The separator to use +--@param plain Boolean If `true`, use the separator literally +---(passed as an argument to String.find) +--@returns An iterator over the split components local function gsplit(s, sep, plain) assert(type(s) == "string") assert(type(sep) == "string") @@ -162,7 +174,7 @@ local function gsplit(s, sep, plain) local start = 1 local done = false - local function pass(i, j, ...) + local function _pass(i, j, ...) if i then assert(j+1 > start, "Infinite loop detected") local seg = s:sub(start, i - 1) @@ -182,26 +194,55 @@ local function gsplit(s, sep, plain) if start == #s then done = true end - return pass(start+1, start) + return _pass(start+1, start) end - return pass(s:find(sep, start, plain)) + return _pass(s:find(sep, start, plain)) end end +--- Split a string by a given separator. +--- +--- Examples: +--- +--- * split(":aa::b:", ":") returns {'','aa','','bb',''} +--- +--- * split("axaby", "ab?") returns {'','x','y'} +--- +--- * split(x*yz*o, "*", true) returns {'x','yz','o'} +--- +--@param s String The string to split +--@param sep String The separator to use (see |vim.gsplit()|) +--@param plain Boolean If `true`, use the separator literally +---(see |vim.gsplit()|) +--@returns An array containing the components of the split. local function split(s,sep,plain) local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end return t end +--- Trim the whitespaces from a string. A whitespace is everything that +--- matches the lua pattern '%%s', see +--- +--- https://www.lua.org/pil/20.2.html +--@param s String The string to trim +--@returns The string with all whitespaces trimmed from its beginning and end local function trim(s) assert(type(s) == "string", "Only strings can be trimmed") local result = s:gsub("^%s+", ""):gsub("%s+$", "") return result end -local deepcopy +--- Performs a deep copy of the given object, and returns that copy. +--- For a non-table object, that just means a usual copy of the object, +--- while for a table all subtables are copied recursively. +--@param orig Table The table to copy +--@returns A new table where the keys and values are deepcopies of the keys +--- and values from the original table. +local function deepcopy(orig) + error() +end -local function id(v) +local function _id(v) return v end @@ -213,10 +254,10 @@ local deepcopy_funcs = { end return copy end, - number = id, - string = id, - ['nil'] = id, - boolean = id, + number = _id, + string = _id, + ['nil'] = _id, + boolean = _id, } deepcopy = function(orig) -- cgit From e628c011bfb58685e4a4ce7da681afda08989a7f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 18 May 2019 22:04:31 +0200 Subject: gen_vimdoc.py: support lua/shared.lua module [ci skip] --- src/nvim/lua/vim.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 9e592e444b..69038f8c89 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -203,12 +203,11 @@ end --- Split a string by a given separator. --- --- Examples: ---- ---- * split(":aa::b:", ":") returns {'','aa','','bb',''} ---- ---- * split("axaby", "ab?") returns {'','x','y'} ---- ---- * split(x*yz*o, "*", true) returns {'x','yz','o'} +---
+---  split(":aa::b:", ":")     --> {'','aa','','bb',''}
+---  split("axaby", "ab?")     --> {'','x','y'}
+---  split(x*yz*o, "*", true)  --> {'x','yz','o'}
+--- 
--- --@param s String The string to split --@param sep String The separator to use (see |vim.gsplit()|) -- cgit From e4c2d85c7729925128746d08883286b75fb097a8 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 19 May 2019 17:58:54 +0200 Subject: lua/shared: share deepcopy() with test/* deepcopy() was duplicated in test/helpers.lua --- src/nvim/lua/vim.lua | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 69038f8c89..3c1a9a86d0 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -1,10 +1,10 @@ -- Nvim-Lua stdlib: the `vim` module (:help lua-stdlib) -- -- Lua code lives in one of three places: --- 1. The runtime (`runtime/lua/vim/`). For "nice to have" features, e.g. --- the `inspect` and `lpeg` modules. --- 2. The `vim.shared` module: code shared between Nvim and its test-suite. --- 3. Compiled-into Nvim itself (`src/nvim/lua/`). +-- 1. runtime/lua/vim/ (the runtime): For "nice to have" features, e.g. the +-- `inspect` and `lpeg` modules. +-- 2. runtime/lua/vim/shared.lua: Code shared between Nvim and tests. +-- 3. src/nvim/lua/: Compiled-into Nvim itself. -- -- Guideline: "If in doubt, put it in the runtime". -- @@ -231,38 +231,6 @@ local function trim(s) return result end ---- Performs a deep copy of the given object, and returns that copy. ---- For a non-table object, that just means a usual copy of the object, ---- while for a table all subtables are copied recursively. ---@param orig Table The table to copy ---@returns A new table where the keys and values are deepcopies of the keys ---- and values from the original table. -local function deepcopy(orig) - error() -end - -local function _id(v) - return v -end - -local deepcopy_funcs = { - table = function(orig) - local copy = {} - for k, v in pairs(orig) do - copy[deepcopy(k)] = deepcopy(v) - end - return copy - end, - number = _id, - string = _id, - ['nil'] = _id, - boolean = _id, -} - -deepcopy = function(orig) - return deepcopy_funcs[type(orig)](orig) -end - local function __index(t, key) if key == 'inspect' then t.inspect = require('vim.inspect') @@ -282,7 +250,6 @@ local module = { trim = trim, split = split, gsplit = gsplit, - deepcopy = deepcopy, } setmetatable(module, { -- cgit From fab81cfb04b345fa7465fa099204d50a496f1819 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 19 May 2019 18:31:40 +0200 Subject: lua/shared: share more stuff Leave trim() in vim.lua, because gen_vimdoc.py needs at least one function in there, else it gets confused... --- src/nvim/lua/vim.lua | 80 ++++------------------------------------------------ 1 file changed, 6 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 3c1a9a86d0..38a8795680 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -154,80 +154,14 @@ local function _update_package_paths() last_nvim_paths = cur_nvim_paths end ----Split a string by a given separator. The separator can be a lua pattern, see [1]. ----Used by |vim.split()|, see there for some examples. See [2] ----for usage of the plain parameter. +--- Trim whitespace (Lua pattern "%%s") from both sides of a string. --- ---- [1] https://www.lua.org/pil/20.2.html. ---- ---- [2] http://lua-users.org/wiki/StringLibraryTutorial ---@param s String The string to split ---@param sep String The separator to use ---@param plain Boolean If `true`, use the separator literally ----(passed as an argument to String.find) ---@returns An iterator over the split components -local function gsplit(s, sep, plain) - assert(type(s) == "string") - assert(type(sep) == "string") - assert(type(plain) == "boolean" or type(plain) == "nil") - - local start = 1 - local done = false - - local function _pass(i, j, ...) - if i then - assert(j+1 > start, "Infinite loop detected") - local seg = s:sub(start, i - 1) - start = j + 1 - return seg, ... - else - done = true - return s:sub(start) - end - end - - return function() - if done then - return - end - if sep == '' then - if start == #s then - done = true - end - return _pass(start+1, start) - end - return _pass(s:find(sep, start, plain)) - end -end - ---- Split a string by a given separator. ---- ---- Examples: ----
----  split(":aa::b:", ":")     --> {'','aa','','bb',''}
----  split("axaby", "ab?")     --> {'','x','y'}
----  split(x*yz*o, "*", true)  --> {'x','yz','o'}
---- 
---- ---@param s String The string to split ---@param sep String The separator to use (see |vim.gsplit()|) ---@param plain Boolean If `true`, use the separator literally ----(see |vim.gsplit()|) ---@returns An array containing the components of the split. -local function split(s,sep,plain) - local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end - return t -end - ---- Trim the whitespaces from a string. A whitespace is everything that ---- matches the lua pattern '%%s', see ---- ---- https://www.lua.org/pil/20.2.html ---@param s String The string to trim ---@returns The string with all whitespaces trimmed from its beginning and end +--@see https://www.lua.org/pil/20.2.html +--@param s String to trim +--@returns String with whitespace removed from its beginning and end local function trim(s) - assert(type(s) == "string", "Only strings can be trimmed") - local result = s:gsub("^%s+", ""):gsub("%s+$", "") + assert(type(s) == 'string', 'Only strings can be trimmed') + local result = s:gsub('^%s+', ''):gsub('%s+$', '') return result end @@ -248,8 +182,6 @@ local module = { _os_proc_info = _os_proc_info, _system = _system, trim = trim, - split = split, - gsplit = gsplit, } setmetatable(module, { -- cgit