functions.lua 628 B

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