Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Features: Change variable values as buffers #158

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,12 @@ function M.setup()
"Press 'q' to close, 'e' to edit, or 'n' to create a variable."
)

-- Add e key binding to edit the variable
-- Add e key binding to edit the variable inline in the buffer
text_popup:map('n', 'e', function()
local line = vim.api.nvim_get_current_line()
local var_name = line:match('^(.-) =')
if var_name then
local new_value = vim.fn.input('Enter new value for ' .. var_name .. ': ')
_HURL_GLOBAL_CONFIG.global_vars[var_name] = new_value
vim.api.nvim_set_current_line(var_name .. ' = ' .. new_value)
vim.api.nvim_input('A')
end
end)

Expand Down Expand Up @@ -520,10 +518,30 @@ function M.setup()
vim.cmd('HurlSetVariable ' .. var_name .. ' ' .. var_value)
-- Append to the last line
vim.api.nvim_buf_set_lines(0, line_position, -1, false, { var_name .. ' = ' .. var_value })

-- Refresh the buffer display
vim.api.nvim_buf_set_lines(
0,
0,
-1,
false,
vim.tbl_map(function(key)
return key .. ' = ' .. _HURL_GLOBAL_CONFIG.global_vars[key]
end, vim.tbl_keys(_HURL_GLOBAL_CONFIG.global_vars))
)
end)
end, {
nargs = '*',
range = true,
on_write = function()
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, line in ipairs(lines) do
local var_name, var_value = line:match('^(.-) = (.+)$')
if var_name and var_value then
_HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value
end
end
end,
})

-- Show debug info
Expand All @@ -536,6 +554,15 @@ function M.setup()
end, {
nargs = '*',
range = true,
on_write = function()
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, line in ipairs(lines) do
local var_name, var_value = line:match('^(.-) = (.+)$')
if var_name and var_value then
_HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value
end
end
end,
})

-- TODO: Keep last 10 requests and add key binding to navigate through them
Expand All @@ -546,6 +573,15 @@ function M.setup()
end, {
nargs = '*',
range = true,
on_write = function()
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for _, line in ipairs(lines) do
local var_name, var_value = line:match('^(.-) = (.+)$')
if var_name and var_value then
_HURL_GLOBAL_CONFIG.global_vars[var_name] = var_value
end
end
end,
})
end

Expand Down
Loading