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

feat: add FormatToggle keymap (#750) #751

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion lua/keymap/completion.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
local bind = require("keymap.bind")
local map_cr = bind.map_cr
local map_cu = bind.map_cu
-- local map_cmd = bind.map_cmd
local map_cmd = bind.map_cmd
local map_callback = bind.map_callback

local plug_map = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("Formater: Toggle format on save"),
}
bind.nvim_load_mapping(plug_map)

local mapping = {}

function mapping.lsp(buf)
Expand Down
8 changes: 4 additions & 4 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ function M.enable_format_on_save(is_configured)
end
end

function M.disable_format_on_save()
function M.disable_format_on_save(is_configured)
pcall(vim.api.nvim_del_augroup_by_name, "format_on_save")
if format_on_save then
if not is_configured then
vim.notify(
"Successfully disabled format-on-save",
vim.log.levels.INFO,
Expand All @@ -69,7 +69,7 @@ function M.configure_format_on_save()
if format_on_save then
M.enable_format_on_save(true)
else
M.disable_format_on_save()
M.disable_format_on_save(true)
end
end

Expand All @@ -81,7 +81,7 @@ function M.toggle_format_on_save()
if not status then
M.enable_format_on_save(false)
else
M.disable_format_on_save()
M.disable_format_on_save(false)
end
end

Expand Down