Added init.lua
First initial commit of file as a backup to refactor.
This commit is contained in:
commit
ceb8576281
100
init.lua
Normal file
100
init.lua
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
local plenary = require'plenary'
|
||||
local popup = plenary.popup
|
||||
|
||||
local presser = {}
|
||||
windows = {}
|
||||
|
||||
local api = vim.api
|
||||
|
||||
local function _iter_table_dump( arr )
|
||||
for k, v in pairs(arr) do
|
||||
print("Table:", k, v)
|
||||
end
|
||||
end
|
||||
|
||||
local escape_chars = function ( text )
|
||||
return string.gsub(text, "[%(|%)|\\|%[|%]|%-|%{%}|%?|%+|%*|%^|%$|%.]", {
|
||||
["\\"] = "\\\\",
|
||||
["-"] = "\\-",
|
||||
["("] = "\\(",
|
||||
[")"] = "\\)",
|
||||
["["] = "\\[",
|
||||
["]"] = "\\]",
|
||||
["{"] = "\\{",
|
||||
["}"] = "\\}",
|
||||
["?"] = "\\?",
|
||||
["+"] = "\\+",
|
||||
["*"] = "\\*",
|
||||
["^"] = "\\^",
|
||||
["$"] = "\\$",
|
||||
["."] = "\\.",
|
||||
})
|
||||
end
|
||||
|
||||
-- :@dev: clean the text once it has been fetched from buffer
|
||||
local function _clean_buf ( text )
|
||||
if not type(text) == "string" or text == nil then
|
||||
print("[DEBUG - _clean_buf] Given input is not of type string.")
|
||||
return
|
||||
end
|
||||
|
||||
return escape_chars( text )
|
||||
:match( "^%s*(.-)%s*$" )
|
||||
end
|
||||
|
||||
function presser.destroy_windows()
|
||||
-- api.nvim_win_close(0, true)
|
||||
|
||||
for k,v in pairs(windows) do
|
||||
-- api.nvim_win_close(v, true)
|
||||
print(k, v)
|
||||
table.remove(windows, k)
|
||||
end
|
||||
end
|
||||
|
||||
function presser.find_replace()
|
||||
local padding = 128
|
||||
local buf_width = api.nvim_win_get_width(0) - padding
|
||||
|
||||
local opts = {
|
||||
minwidth = buf_width,
|
||||
borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" },
|
||||
}
|
||||
|
||||
local win_title_opts = {
|
||||
height = 3,
|
||||
minwidth = buf_width + 2,
|
||||
line = 9,
|
||||
padding = { 1, 1, 1, 1 },
|
||||
}
|
||||
|
||||
if not placeholder == nil then
|
||||
vim.tbl_extend( "force", opts, { padding = { 0, buf_padding, 0, } } )
|
||||
end
|
||||
|
||||
local win_title = popup.create( { "Find & Replace" }, win_title_opts )
|
||||
local win_b = popup.create({ "" }, vim.tbl_extend("force", opts, { title = "Replace", line = 16 }))
|
||||
local win_t = popup.create({ "" }, vim.tbl_extend("force", opts, { title = "Find", line = 13 }))
|
||||
print(win_t, win_b)
|
||||
|
||||
table.insert(windows, win_t)
|
||||
table.insert(windows, win_b)
|
||||
table.insert(windows, win_title)
|
||||
|
||||
--api.nvim_feedkeys(api.nvim_replace_termcodes("<ESC>A", true, false, true), 'n', true)
|
||||
|
||||
local win_t_buf = api.nvim_win_get_buf(win_t)
|
||||
local win_b_buf = api.nvim_win_get_buf(win_b)
|
||||
-- :lua require('presser').destroy_windows()<CR>
|
||||
api.nvim_buf_set_keymap(win_t_buf, "n", "<ESC>", ":lua require('presser').destroy_windows()<CR>", { noremap = true, silent = true })
|
||||
api.nvim_buf_set_keymap(win_b_buf, "n", "<ESC>", ":close!<CR>", { noremap = true, silent = true })
|
||||
print(win_t_buf)
|
||||
|
||||
local text = api.nvim_buf_get_lines(win_t_buf, 0, -1, false)
|
||||
print(_clean_buf(text[1]))
|
||||
|
||||
end
|
||||
|
||||
presser.find_replace()
|
||||
|
||||
return presser
|
||||
Loading…
Reference in New Issue
Block a user