Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
feat: add FormatToggle keymap (ayamir#750) (ayamir#751)
Browse files Browse the repository at this point in the history
* feat: add `FormatToggle` keymap (ayamir#750)

* remove reduntant note.

---------

Co-authored-by: ayamir <[email protected]>
  • Loading branch information
Groveer and ayamir authored May 18, 2023
1 parent 0f79d01 commit 41262de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit 41262de

Please sign in to comment.