new ftkeybinds scheme working for arduino
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
local function markdown(options)
|
local function options2list(options)
|
||||||
local options_list = {}
|
local options_list = {}
|
||||||
for opt in options:gmatch("%S+") do
|
for opt in options:gmatch("%S+") do
|
||||||
table.insert(options_list, opt)
|
table.insert(options_list, opt)
|
||||||
end
|
end
|
||||||
|
return options_list
|
||||||
|
end
|
||||||
|
|
||||||
|
local function markdown(options)
|
||||||
|
local options_list = options2list(options or "")
|
||||||
local cmd = vim.list_extend(
|
local cmd = vim.list_extend(
|
||||||
{ "pandoc" },
|
{ "pandoc" },
|
||||||
options_list
|
options_list
|
||||||
@@ -25,49 +30,71 @@ local function markdown(options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function arduino(options)
|
local function arduino(options)
|
||||||
local arduino_process = vim.system({
|
local options_list = options2list(options or "")
|
||||||
"arduino-cli",
|
local options_string = ""
|
||||||
"board",
|
for _, opt in pairs(options_list) do
|
||||||
"listall",
|
options_string = options_string .. " -D" .. opt
|
||||||
"--json"
|
|
||||||
})
|
|
||||||
local boards_json = arduino_process:wait()
|
|
||||||
|
|
||||||
local jq_process = vim.system({
|
|
||||||
"jq",
|
|
||||||
"[.boards.[] | {(.name): .fqbn}] | add",
|
|
||||||
}, { stdin = boards_json.stdout })
|
|
||||||
local boards_jq = jq_process:wait().stdout or {}
|
|
||||||
local boards_table = vim.json.decode(boards_jq)
|
|
||||||
|
|
||||||
local function table_keys(t)
|
|
||||||
local keys = {}
|
|
||||||
for k in pairs(t) do keys[#keys + 1] = k end
|
|
||||||
return keys
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local keys = table_keys(boards_table)
|
local process = vim.system({
|
||||||
table.sort(keys)
|
"arduino-cli",
|
||||||
require("fzf-lua").fzf_exec(keys, {
|
"compile",
|
||||||
actions = {
|
"-e",
|
||||||
['default'] = function(selected, opts)
|
"--build-property",
|
||||||
local process = vim.system({
|
"compiler.cpp.extra_flags=" .. options_string,
|
||||||
"arduino-cli",
|
vim.fn.expand("%:p:h")
|
||||||
"compile",
|
|
||||||
"--fqbn",
|
|
||||||
boards_table[selected[1]],
|
|
||||||
vim.fn.expand("%:p:h")
|
|
||||||
})
|
|
||||||
local result = process:wait()
|
|
||||||
|
|
||||||
vim.notify(result.stdout, vim.log.levels.INFO)
|
|
||||||
vim.notify(result.stderr, vim.log.levels.ERROR)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
local result = process:wait()
|
||||||
|
|
||||||
|
vim.notify(result.stdout, vim.log.levels.INFO)
|
||||||
|
vim.notify(result.stderr, vim.log.levels.ERROR)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tex(options)
|
--local function arduino2()
|
||||||
|
-- local arduino_process = vim.system({
|
||||||
|
-- "arduino-cli",
|
||||||
|
-- "board",
|
||||||
|
-- "listall",
|
||||||
|
-- "--json"
|
||||||
|
-- })
|
||||||
|
-- local boards_json = arduino_process:wait()
|
||||||
|
--
|
||||||
|
-- local jq_process = vim.system({
|
||||||
|
-- "jq",
|
||||||
|
-- "[.boards.[] | {(.name): .fqbn}] | add",
|
||||||
|
-- }, { stdin = boards_json.stdout })
|
||||||
|
-- local boards_jq = jq_process:wait().stdout or {}
|
||||||
|
-- local boards_table = vim.json.decode(boards_jq)
|
||||||
|
--
|
||||||
|
-- local function table_keys(t)
|
||||||
|
-- local keys = {}
|
||||||
|
-- for k in pairs(t) do keys[#keys + 1] = k end
|
||||||
|
-- return keys
|
||||||
|
-- end
|
||||||
|
--
|
||||||
|
-- local keys = table_keys(boards_table)
|
||||||
|
-- table.sort(keys)
|
||||||
|
-- require("fzf-lua").fzf_exec(keys, {
|
||||||
|
-- actions = {
|
||||||
|
-- ['default'] = function(selected, opts)
|
||||||
|
-- local process = vim.system({
|
||||||
|
-- "arduino-cli",
|
||||||
|
-- "compile",
|
||||||
|
-- "-e",
|
||||||
|
-- "--fqbn",
|
||||||
|
-- boards_table[selected[1]],
|
||||||
|
-- vim.fn.expand("%:p:h")
|
||||||
|
-- })
|
||||||
|
-- local result = process:wait()
|
||||||
|
--
|
||||||
|
-- vim.notify(result.stdout, vim.log.levels.INFO)
|
||||||
|
-- vim.notify(result.stderr, vim.log.levels.ERROR)
|
||||||
|
-- end,
|
||||||
|
-- }
|
||||||
|
-- })
|
||||||
|
--end
|
||||||
|
|
||||||
|
local function tex()
|
||||||
local pdflatex_process = vim.system({
|
local pdflatex_process = vim.system({
|
||||||
"pdflatex",
|
"pdflatex",
|
||||||
vim.fn.expand("%:p"),
|
vim.fn.expand("%:p"),
|
||||||
@@ -78,25 +105,25 @@ local function tex(options)
|
|||||||
vim.notify(pdflatex_result.stderr, vim.log.levels.ERROR);
|
vim.notify(pdflatex_result.stderr, vim.log.levels.ERROR);
|
||||||
end
|
end
|
||||||
|
|
||||||
local function run_ft_action(options)
|
local default = {
|
||||||
local default = {
|
__index = function()
|
||||||
__index = function()
|
return function() end
|
||||||
return function() end
|
end,
|
||||||
end,
|
}
|
||||||
}
|
|
||||||
local fttable = {
|
|
||||||
["markdown"] = markdown,
|
|
||||||
["arduino"] = arduino,
|
|
||||||
["tex"] = tex,
|
|
||||||
}
|
|
||||||
setmetatable(fttable, default)
|
|
||||||
|
|
||||||
fttable[vim.bo.filetype](options)
|
local fttable = {
|
||||||
end
|
["markdown"] = markdown,
|
||||||
|
["arduino"] = arduino,
|
||||||
|
["tex"] = tex,
|
||||||
|
}
|
||||||
|
setmetatable(fttable, default)
|
||||||
|
|
||||||
vim.keymap.set("n", "<F5>", function () run_ft_action("") end)
|
local fttable2 = {
|
||||||
|
["markdown"] = function() markdown(vim.fn.input("enter additional options")) end,
|
||||||
|
["arduino"] = function() arduino(vim.fn.input("enter preprocessor defines")) end,
|
||||||
|
}
|
||||||
|
setmetatable(fttable2, fttable)
|
||||||
|
|
||||||
vim.keymap.set("n", "<F6>", function()
|
vim.keymap.set("n", "<F5>", function() fttable[vim.bo.filetype]() end)
|
||||||
run_ft_action(vim.fn.input("enter additional options"))
|
vim.keymap.set("n", "<F6>", function() fttable2[vim.bo.filetype]() end)
|
||||||
end)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user