functions.lua 703 B

123456789101112131415161718192021222324252627282930313233
  1. local M = {}
  2. function M.smart_quit()
  3. local bufnr = vim.api.nvim_get_current_buf()
  4. local buf_windows = vim.call("win_findbuf", bufnr)
  5. local modified = vim.api.nvim_buf_get_option(bufnr, "modified")
  6. if modified and #buf_windows == 1 then
  7. vim.ui.input({
  8. prompt = "You have unsaved changes. Quit anyway? (y/n) ",
  9. }, function(input)
  10. if input == "y" then
  11. vim.cmd "q!"
  12. end
  13. end)
  14. else
  15. vim.cmd "q!"
  16. end
  17. end
  18. function M.isempty(s)
  19. return s == nil or s == ""
  20. end
  21. function M.get_buf_option(opt)
  22. local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt)
  23. if not status_ok then
  24. return nil
  25. else
  26. return buf_option
  27. end
  28. end
  29. return M