Skip to content

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
2 people authored and singlemancombat committed May 19, 2023
1 parent 30eecf2 commit 7dc7a93
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
24 changes: 12 additions & 12 deletions lazy-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"accelerated-jk.nvim": { "branch": "main", "commit": "8fb5dad4ccc1811766cebf16b544038aeeb7806f" },
"alpha-nvim": { "branch": "main", "commit": "1838ae926e8d49fe5330d1498ee8289ae2c340bc" },
"ascii.nvim": { "branch": "master", "commit": "f4d165c7384aade71d828fb08502d8ceda7dca89" },
"auto-session": { "branch": "main", "commit": "571ecb873654554109f63eac3193b133aec2f90c" },
"auto-session": { "branch": "main", "commit": "ac22fb5a0d10d206d2ea8b347a76152c0f184640" },
"autoclose.nvim": { "branch": "main", "commit": "c4db42ffc0edbd244502be951c142df0c8a7e582" },
"ayu": { "branch": "master", "commit": "762ff24bd429fbb1c1e20b13043b4c8f0266bcf1" },
"better-escape.nvim": { "branch": "master", "commit": "7031dc734add47bb71c010e0551829fa5799375f" },
Expand All @@ -27,7 +27,7 @@
"copilot.vim": { "branch": "release", "commit": "1358e8e45ecedc53daf971924a0541ddf6224faf" },
"crates.nvim": { "branch": "main", "commit": "dca1949b0405c6ee5173d0627a523a10a63eca3c" },
"csv.vim": { "branch": "master", "commit": "15ff93edf5b26c466affbb356e0696b7d6a3b499" },
"diffview.nvim": { "branch": "main", "commit": "1d6ea6ced1c3ec0f6464761a138bb35afd79ef63" },
"diffview.nvim": { "branch": "main", "commit": "1fc42e67dfb2da7946edbc9a30cb98ed371b8dde" },
"edge": { "branch": "master", "commit": "358cb6688ac577470a4eafcb53bdd63899dfc937" },
"fidget.nvim": { "branch": "main", "commit": "0ba1e16d07627532b6cae915cc992ecac249fb97" },
"friendly-snippets": { "branch": "main", "commit": "1d0dac346de7c6895ac72528df3276386c6b149b" },
Expand All @@ -38,35 +38,35 @@
"hop.nvim": { "branch": "v2", "commit": "90db1b2c61b820e230599a04fedcd2679e64bd07" },
"indent-blankline.nvim": { "branch": "master", "commit": "018bd04d80c9a73d399c1061fa0c3b14a7614399" },
"kanagawa": { "branch": "master", "commit": "42c33239b0460cbbcdb67bc9c7f0c420a95208e6" },
"lazy.nvim": { "branch": "main", "commit": "aba872ec78ffe7f7367764ab0fff6f0170421fde" },
"lazy.nvim": { "branch": "main", "commit": "53e1c49baed4009eccf103dbc77fcb06255019d8" },
"lsp_signature.nvim": { "branch": "master", "commit": "7a26ebaa7e36aa2aefa6c1994b2b866c96de32e6" },
"lspsaga.nvim": { "branch": "main", "commit": "98bcbc49ba62a96ce4e2072f2e5e7d2e4d454361" },
"lspsaga.nvim": { "branch": "main", "commit": "426df9972053422c24d38c6fc23f90e423091a79" },
"lualine.nvim": { "branch": "master", "commit": "05d78e9fd0cdfb4545974a5aa14b1be95a86e9c9" },
"markdown-preview.nvim": { "branch": "master", "commit": "02cc3874738bc0f86e4b91f09b8a0ac88aef8e96" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "90a8bbf106b85b76951a34c542058ffa807de2b1" },
"mason-null-ls.nvim": { "branch": "main", "commit": "54d702020bf94e4eefd357f0b738317af30217eb" },
"mason.nvim": { "branch": "main", "commit": "e634134312bb936f472468a401c9cae6485ab54b" },
"mason.nvim": { "branch": "main", "commit": "e60b855bfa8c7d34387200daa6e54a5e22d3da05" },
"neodim": { "branch": "master", "commit": "89c16fccccfdb5b7e6ad3a6e8286736debc11705" },
"neoscroll.nvim": { "branch": "master", "commit": "d7601c26c8a183fa8994ed339e70c2d841253e93" },
"nightfox": { "branch": "main", "commit": "77aa7458d2b725c2d9ff55a18befe1b891ac473e" },
"nord.nvim": { "branch": "master", "commit": "fab04b2dd4b64f4b1763b9250a8824d0b5194b8f" },
"nordic.nvim": { "branch": "main", "commit": "bd4cf4e4ca8b6a8b63e2e6e38d2112a59be45494" },
"nui.nvim": { "branch": "main", "commit": "698e75814cd7c56b0dd8af4936bcef2d13807f3c" },
"null-ls.nvim": { "branch": "main", "commit": "08bb00c7c2cd58c72e02cf54e4b9cbfe14b03e09" },
"null-ls.nvim": { "branch": "main", "commit": "77e53bc3bac34cc273be8ed9eb9ab78bcf67fa48" },
"nvim-bufdel": { "branch": "main", "commit": "96c4f7ab053ddab0025bebe5f7c71e4795430e47" },
"nvim-cmp": { "branch": "main", "commit": "d153771162bd9795d9f7142df5c674b61066a585" },
"nvim-cmp": { "branch": "main", "commit": "3ac8d6cd29c74ff482d8ea47d45e5081bfc3f5ad" },
"nvim-colorizer.lua": { "branch": "master", "commit": "dde3084106a70b9a79d48f426f6d6fec6fd203f7" },
"nvim-dap": { "branch": "master", "commit": "6cedcb527e264c8f25e86afa8dae74c6692dee51" },
"nvim-dap": { "branch": "master", "commit": "56118cee6af15cb9ddba9d080880949d8eeb0c9f" },
"nvim-dap-ui": { "branch": "master", "commit": "4ce7b97dd8f50b4f672948a34bf8f3a56214fdb8" },
"nvim-dap-virtual-text": { "branch": "master", "commit": "ab988dbb7d20cdaebf9b3ef7554a89f6895de042" },
"nvim-jdtls": { "branch": "master", "commit": "355de7458fd63ccef9c6485d952ea118ba2cb46a" },
"nvim-lspconfig": { "branch": "master", "commit": "df58d91c9351a9dc5be6cf8d54f49ab0d9a64e73" },
"nvim-lspconfig": { "branch": "master", "commit": "8dc45a5c142f0b5a5dd34e5cdba33217d5dc6a86" },
"nvim-notify": { "branch": "master", "commit": "f3024b912073774111202f5fa6518b0cd2a74432" },
"nvim-scrollview": { "branch": "main", "commit": "4a04039b80c270f6bd2075935cd3c7943f6ad140" },
"nvim-tree.lua": { "branch": "master", "commit": "736c7ff59065275f0483af4b7f07a9bc41449ad0" },
"nvim-treehopper": { "branch": "master", "commit": "5a28bff46c05d28bdb4bcaef67e046eb915a9390" },
"nvim-treesitter": { "branch": "master", "commit": "680807fa6a482c639119098bc48ca3831c66db13" },
"nvim-treesitter-context": { "branch": "master", "commit": "f24a86c32238867f24fbff49913db0068f8488d2" },
"nvim-treesitter": { "branch": "master", "commit": "102f1b2f55575f0a2f18be92eafc0e7142024ad1" },
"nvim-treesitter-context": { "branch": "master", "commit": "c8f3a62c64bf6f9fed11260a424207f780505f83" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "35a60f093fa15a303874975f963428a5cd24e4a0" },
"nvim-ts-autotag": { "branch": "main", "commit": "40615e96075c743ef47aaf9de966dc348bec6459" },
"nvim-ts-context-commentstring": { "branch": "main", "commit": "0bf8fbc2ca8f8cdb6efbd0a9e32740d7a991e4c3" },
Expand All @@ -90,7 +90,7 @@
"telescope-live-grep-args.nvim": { "branch": "master", "commit": "0f75ea809c46af8997c64f49c52e3c641d887885" },
"telescope-undo.nvim": { "branch": "main", "commit": "231b5ebb4328d2768c830c9a8d1b9c696116848d" },
"telescope-zoxide": { "branch": "main", "commit": "68966349aa1b8e9ade403e18479ecf79447389a7" },
"telescope.nvim": { "branch": "master", "commit": "ebf93395e79e5d026e3867d9e5e158b2bbe1499c" },
"telescope.nvim": { "branch": "master", "commit": "40c31fdde93bcd85aeb3447bb3e2a3208395a868" },
"toggleterm.nvim": { "branch": "main", "commit": "68fdf851c2b7901a7065ff129b77d3483419ddce" },
"tokyonight": { "branch": "main", "commit": "df13e3268a44f142999fa166572fe95a650a0b37" },
"trouble.nvim": { "branch": "main", "commit": "d56bfc0c501ced4002a57cb60433362fb2ce9c4d" },
Expand Down
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
42 changes: 23 additions & 19 deletions lua/modules/configs/completion/formatting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,35 @@ function M.enable_format_on_save(is_configured)
end
end

function M.disable_format_on_save()
pcall(vim.api.nvim_del_augroup_by_name, "format_on_save")
if format_on_save then
vim.notify("Successfully disabled format-on-save", vim.log.levels.INFO, { title = "Settings modification success" })
end
function M.disable_format_on_save(is_configured)
pcall(vim.api.nvim_del_augroup_by_name, "format_on_save")
if not is_configured then
vim.notify(
"Successfully disabled format-on-save",
vim.log.levels.INFO,
{ title = "Settings modification success" }
)
end
end

function M.configure_format_on_save()
if format_on_save then
M.enable_format_on_save(true)
else
M.disable_format_on_save()
end
if format_on_save then
M.enable_format_on_save(true)
else
M.disable_format_on_save(true)
end
end

function M.toggle_format_on_save()
local status = pcall(vim.api.nvim_get_autocmds, {
group = "format_on_save",
event = "BufWritePre",
})
if not status then
M.enable_format_on_save(false)
else
M.disable_format_on_save()
end
local status = pcall(vim.api.nvim_get_autocmds, {
group = "format_on_save",
event = "BufWritePre",
})
if not status then
M.enable_format_on_save(false)
else
M.disable_format_on_save(false)
end
end

function M.format_filter(clients)
Expand Down

0 comments on commit 7dc7a93

Please sign in to comment.