goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.73k stars 101 forks source link

[Questions] Error when using "AlphaClosed" #253

Closed Crowds21 closed 6 months ago

Crowds21 commented 6 months ago

Situration

image I am using the AstroNvim, and when I click Last Session. It shows:

image

"Error occurred while handling BufUnload autocmd '<buffer=1>'..User autocmd 'AlphaClosed':"
stack traceback:                                                                                                              
        [C]: in function 'nvim_buf_delete'                                                                                    
        ...wds/.local/share/nvim/lazy/alpha-nvim/lua/alpha/term.lua:43: in function <...wds/.local/share/nvim/lazy/alpha-nvim/
lua/alpha/term.lua:42>                                                                                                        
        [C]: in function 'nvim_exec_autocmds'                                                                                 
        ...s/crowds/.local/share/nvim/lazy/alpha-nvim/lua/alpha.lua:670: in function <...s/crowds/.local/share/nvim/lazy/alpha
-nvim/lua/alpha.lua:665>                                                                                                      
        [C]: in function 'nvim_buf_delete'                                                                                    
        ...azy/neovim-session-manager/lua/session_manager/utils.lua:59: in function <...azy/neovim-session-manager/lua/session
_manager/utils.lua:51>  

Configuration

return { "goolord/alpha-nvim", cmd = "Alpha", opts = function() local dashboard = require "alpha.themes.dashboard" -- require "alpha.term" dashboard.section.terminal = { type = "terminal", command = "cat | " .. os.getenv "HOME" .. "/.config/nvim/lua/user/alpha/yin.sh", width = 50, height = 14, opts = { position = "center", hl = "String", }, } dashboard.section.footer.opts.hl = "DashboardFooter" -- button local button, get_icon = require("astronvim.utils").alpha_button, require("astronvim.utils").get_icon dashboard.section.buttons.val = { button("LDR n ", get_icon("FileNew", 2, true) .. "New File "), button("LDR f f", get_icon("Search", 2, true) .. "Find File "), button("LDR f o", get_icon("DefaultFile", 2, true) .. "Recents "), button("LDR f w", get_icon("WordFile", 2, true) .. "Find Word "), button("LDR f '", get_icon("Bookmarks", 2, true) .. "Bookmarks "), button("LDR S l", get_icon("Refresh", 2, true) .. "Last Session "), }

dashboard.config.layout = {
  { type = "padding", val = vim.fn.max { 2, vim.fn.floor(vim.fn.winheight(0) * 0.2) } },
  dashboard.section.terminal,
  { type = "padding", val = 5 },
  dashboard.section.buttons,
  { type = "padding", val = 3 },
  dashboard.section.footer,
}
-- dashboard.config.opts.noautocmd = true
return dashboard

end, config = require "plugins.configs.alpha", }

###  `lua/plugin/configs/alpha.lua`
```lua
return function(_, opts)
  local alpha = require "alpha"
  require "alpha.term"
  alpha.setup(opts.config)

  vim.api.nvim_create_autocmd("User", {
    pattern = "LazyVimStarted",
    desc = "Add Alpha dashboard footer",
    once = true,
    callback = function()
      local stats = require("lazy").stats()
      local ms = math.floor(stats.startuptime * 100 + 0.5) / 100
      opts.section.footer.val = { "AstroNvim loaded " .. stats.count .. " plugins  in " .. ms .. "ms" }
      pcall(vim.cmd.AlphaRedraw)
    end,
  })
end

I have read the document. I am not good at lua, is this a configuration issue? Thanks!

goolord commented 6 months ago

the session management plugin is probably wiping the existing buffers and windows before alpha can, i suppose the hotfix is just pcalling those functions for special cases like this

Crowds21 commented 6 months ago

the session management plugin is probably wiping the existing buffers and windows before alpha can, i suppose the hotfix is just pcalling those functions for special cases like this

I originally thought it might be a very simple configuration error, but it sounds like it might be too complicated for me, so I'll just use the default style. Thank you for your reply.