forked from neovim/neovim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c40ad8
commit 69e63ec
Showing
10 changed files
with
202 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
local function deepcopy(orig) | ||
local copy | ||
if type(orig) == 'table' then | ||
copy = {} | ||
for k, v in pairs(orig) do | ||
copy[deepcopy(k)] = deepcopy(v) | ||
end | ||
setmetatable(copy, deepcopy(getmetatable(orig))) | ||
else -- number, string, boolean, etc | ||
copy = orig | ||
end | ||
return copy | ||
end | ||
|
||
return { | ||
deepcopy = deepcopy, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local nvim_eval = vim.api.nvim_eval | ||
|
||
local osname = require('helpers.os').osname | ||
local gsplit = require('helpers.stringstuff').gsplit | ||
local trim = require('helpers.stringstuff').trim | ||
local split = require('helpers.stringstuff').split | ||
|
||
local inspect = require('helpers.inspect') | ||
|
||
local deepcopy = require('helpers.deepcopy').deepcopy | ||
|
||
local new_plugin = require('helpers.plugin').new_plugin | ||
|
||
if not vim.helpers then vim.helpers = {} end | ||
if not vim.lua_api then vim.lua_api = {} end | ||
|
||
vim.lua_api.osname = osname | ||
vim.helpers.split = split | ||
vim.helpers.gsplit = gsplit | ||
vim.helpers.inspect = inspect | ||
vim.helpers.trim = trim | ||
vim.helpers.deepcopy = deepcopy | ||
vim.helpers.new_plugin = new_plugin | ||
|
||
local module ={ | ||
osname = osname, | ||
split = split, | ||
gsplit = gsplit, | ||
inspect = inspect, | ||
trim = trim, | ||
deepcopy = deepcopy, | ||
new_plugin = new_plugin, | ||
} | ||
|
||
vim.api.nvim_command("let lua = {}") | ||
|
||
vim.api.nvim_command([[ | ||
function lua.osname() dict | ||
return luaeval('require("helpers").osname()', {}) | ||
endfunction | ||
]]) | ||
|
||
return module |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- luacheck: globals unpack vim.api | ||
local nvim = vim.api | ||
local eval = nvim.nvim_eval | ||
|
||
local os_name = nil | ||
local function osname() | ||
if not os_name then | ||
if eval('has("win32")') == 1 then | ||
os_name = 'windows' | ||
elseif eval('has("macunix")') == 1 then | ||
os_name = 'osx' | ||
else | ||
os_name = 'unix' | ||
end | ||
end | ||
return os_name | ||
end | ||
|
||
return { | ||
osname = osname, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- luacheck: globals unpack vim.api | ||
local nvim = vim.api | ||
local map = require('helpers.plugin.map').map | ||
local functions = require('helpers.plugin.map').functions | ||
|
||
local function new_plugin(name) | ||
-- TODO(KillTheMule): This code assumes that subsequent calls with the same | ||
-- name return the same ns. Make sure of that, or adapt | ||
local ns = nvim.nvim_create_namespace(name) | ||
|
||
-- Should be redundant after the comment above has ben ascertained | ||
assert(functions[ns] == nil, "Namspace "..tostring(ns).." already exists") | ||
|
||
functions[ns] = {} | ||
return { ns = ns, name = name, map = map } | ||
end | ||
|
||
return { | ||
new_plugin = new_plugin, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 | ||
|
||
local function split(s,sep,plain) | ||
local t={} for c in gsplit(s, sep, plain) do table.insert(t,c) end | ||
return t | ||
end | ||
|
||
|
||
local function trim(s) | ||
assert(type(s) == "string", "Only strings can be trimmed") | ||
return s:gsub("^%s+", ""):gsub("%s+$", "") | ||
end | ||
|
||
return { | ||
trim = trim, | ||
gsplit = gsplit, | ||
split = split | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters