summaryrefslogtreecommitdiff
path: root/lua/lvim/utils/functions.lua
diff options
context:
space:
mode:
authorAbouzar Parvan <[email protected]>2022-05-03 19:01:53 +0430
committerGitHub <[email protected]>2022-05-03 19:01:53 +0430
commite1d32ca42ee6fdef8c724e3f391e548895f0bdcf (patch)
tree3dd52f16dc043e7e2db92b6b98f0ed58b8689898 /lua/lvim/utils/functions.lua
parent5566076ebb539a7d72dd64af257413fd4dde6157 (diff)
feat(quit): make sure to ask before discarding changes (#2554)
Diffstat (limited to 'lua/lvim/utils/functions.lua')
-rw-r--r--lua/lvim/utils/functions.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/lua/lvim/utils/functions.lua b/lua/lvim/utils/functions.lua
new file mode 100644
index 00000000..de46bc8a
--- /dev/null
+++ b/lua/lvim/utils/functions.lua
@@ -0,0 +1,19 @@
+local M = {}
+
+function M.smart_quit()
+ local bufnr = vim.api.nvim_get_current_buf()
+ local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
+ if modified then
+ vim.ui.input({
+ prompt = "You have unsaved changes. Quit anyway? (y/n) ",
+ }, function(input)
+ if input == "y" then
+ vim.cmd "q!"
+ end
+ end)
+ else
+ vim.cmd "q!"
+ end
+end
+
+return M