Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(init): TelescopePreviewerLoaded allow empty bufname #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

YodaEmbedding
Copy link

@YodaEmbedding YodaEmbedding commented Oct 7, 2023

Fixes #12

actions-preview.nvim triggers TelescopePreviewerLoaded autocmd, but with a nil args.data.bufname. This causes an error when args.data.bufname is parsed.

Proposed fix:

 	vim.api.nvim_create_autocmd("User", {
 		pattern = "TelescopePreviewerLoaded",
 		callback = function(args)
 			---@type string
+			if args.data.bufname == nil then
+				return
+			end
 			local extension = args.data.bufname:match("%.(%w+)$")
 			if extension == "md" or extension == "tex" then
 				vim.wo.number = Config.rule_ui.previewer_line_number
 				vim.wo.wrap = Config.rule_ui.previewer_wrap
 			end
 		end,
 	})

Fixes the error message:

Error executing vim.schedule lua callback: ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460: User Autocommands for "TelescopePreviewerLoaded": Vim(append):Error executing lua callback: .../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:66: attempt to index field 'bufname' (a nil value)
stack traceback:
        .../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:66: in function <.../share/nvim/lazy/ltex-utils.nvim/lua/ltex-utils/init.lua:64>
        [C]: in function 'nvim_exec_autocmds'
        ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:461: in function <...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460>
        [C]: in function 'nvim_buf_call'
        ...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:460: in function <...scope.nvim/lua/telescope/previewers/buffer_previewer.lua:454>

@bastian-src
Copy link

Fix works for me, thanks! @YodaEmbedding

LGTM @jhofscheier (& thanks for the extension!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TelescopePreviewerLoaded Error executing vim.schedule lua callback
2 participants