Skip to content
This repository was archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
feat: disable input prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
Daxtorim committed Feb 1, 2022
1 parent 3d5ae1e commit 70b7df5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use {
}
```
- `context_offset`: number of lines to look for above and below the current line while searching for nestable pairs. `(default: 100)`
- `prompt`: whether to print a prompt in the command window asking for input. `(default: true)`
- `load_autogroups`: whether to load inbuilt autogroups or not. `(default: false)`
- `mappings_style`: "surround" or "sandwich" `(default: sandwich)`
- `load_keymaps`: whether to load inbuilt keymaps or not. `(default: true)`
Expand Down
1 change: 1 addition & 0 deletions lua/surround/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ function M.setup(opts)
set_default("mappings_style", "sandwich")
set_default("map_insert_mode", true)
set_default("prefix", "s")
set_default("prompt", true)
set_default("load_autogroups", false)
if vim.g.surround_load_autogroups then
M.load_autogroups({
Expand Down
41 changes: 20 additions & 21 deletions lua/surround/utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
local function clear_output_buffer()
vim.api.nvim_call_function("inputsave", {})
vim.api.nvim_feedkeys(":","nx", true)
vim.api.nvim_call_function("inputrestore", {})
end

local function log(string, history)
if vim.g.surround_prompt then
clear_output_buffer()
vim.api.nvim_echo({{string, nil}}, history, {})
end
end

local function get(var, def)
if var == nil then
return def
Expand Down Expand Up @@ -230,12 +243,6 @@ local function has_value(tab, val)
return false
end

local function clear_output_buffer()
vim.api.nvim_call_function("inputsave", {})
vim.api.nvim_feedkeys(':','nx', true)
vim.api.nvim_call_function("inputrestore", {})
end

local function get_char()
local char_raw = vim.fn.getchar()
if type(char_raw) == "number" then
Expand All @@ -248,20 +255,14 @@ end

local function get_surround_chars(surrounding)
if not surrounding then
vim.api.nvim_command(':echo "(Surround) Character: "')
log("(Surround) Character: ", false)
local char_nr
char_nr, surrounding = get_char()

-- 27 is <ESC>
if char_nr == 27 then return nil end

clear_output_buffer()
-- escape characters
if not string.isalnum(surrounding) then
vim.api.nvim_command(':echomsg "(Surround) Character: \\' .. surrounding .. '"')
else
vim.api.nvim_command(':echomsg "(Surround) Character: ' .. surrounding .. '"')
end
log("(Surround) Character: " .. string.escape_dquotes(surrounding), true)
end

for i,v in pairs(vim.g.surround_pairs_flat) do
Expand Down Expand Up @@ -347,8 +348,7 @@ local function get_motion()
local count_complete = false
local o_maps = omaps()
while true do
clear_output_buffer()
vim.api.nvim_command(":echo '(Surround) Motion: " .. msg .. "'")
log("(Surround) Motion: " .. msg, false)
local char_raw, char_string = get_char()

-- 27 is <ESC>
Expand Down Expand Up @@ -398,15 +398,13 @@ local function get_motion()
and not table.contains(MOTIONS_ESC["incomplete"], last_char))
or custom_omap)
then
clear_output_buffer()
vim.api.nvim_command(':echomsg "(Surround) Motion: ' .. msg .. ' ❌ (invalid)"')
log("(Surround) Motion: " .. msg .. " ❌ (invalid)", true)
return nil
end
end
last_char = char_string
end
clear_output_buffer()
vim.api.nvim_command(':echomsg "(Surround) Motion: ' .. msg .. ' ✅"')
log("(Surround) Motion: " .. msg .. "", true)
return count..motion
end

Expand All @@ -432,6 +430,8 @@ local function highlight_motion_selection()
end

return {
clear_output_buffer = clear_output_buffer,
log = log,
tprint = tprint,
has_value = has_value,
user_input = user_input,
Expand All @@ -444,7 +444,6 @@ return {
get_char_pair = get_char_pair,
get_surround_chars = get_surround_chars,
get_char = get_char,
clear_output_buffer = clear_output_buffer,
load_keymaps = load_keymaps,
quote = quote,
get = get,
Expand Down

0 comments on commit 70b7df5

Please sign in to comment.