Skip to content

Error with fzf-lua picker, fzf-tmux profile #775

Description

@franco-ruggeri

🐛 Describe the bug

Using fzf-lua with the fzf-tmux profile as a picker, I get this error when using either :Obsidian backlinks or :Obsidian tags (and selecting a tag):

[Fzf-lua] fn_selected threw an error: ...hare/nvim/lazy/fzf-lua/lua/fzf-lua/profiles/fzf-tmux.lua:15: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ...hare/nvim/lazy/fzf-lua/lua/fzf-lua/profiles/fzf-tmux.lua:15: in function 'border'
        ...local/share/nvim/lazy/fzf-lua/lua/fzf-lua/win/border.lua:79: in function 'normalize_border'
        ...ugfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/win.lua:590: in function 'normalize_winopts'
        ...ugfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/win.lua:791: in function 'attach_previewer'
        ...gfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:355: in function 'fzf'
        ...gfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:280: in function <...gfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:278>
        [C]: in function 'xpcall'
        ...gfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:278: in function <...gfra/.local/share/nvim/lazy/fzf-lua/lua/fzf-lua/core.lua:273>

Config

Configuration of fzf-lua (with lazy.nvim):

return {
	"ibhagwan/fzf-lua",
	version = false,
	dependencies = { "nvim-tree/nvim-web-devicons" },
	opts = {
		"fzf-tmux",
		files = {
			previewer = false,
			fzf_opts = {
				["--tmux"] = "center",
				["--keep-right"] = "",
			},
		},
	},
}

Configuration of obsidian.nvim:

local function to_kebab_case(str)
	str = str:gsub("[^%w]+", " ") -- non-alphanumeric -> space
	str = str:lower():gsub("%s+", "-") -- spaces -> "-"
	return str
end

-- Based on defaults, but adding the "/" prefix to the path for compatibility with GitHub
local function markdown_link_func(opts)
	local util = require("obsidian.util")

	local anchor = ""
	local header = ""
	if opts.anchor then
		anchor = opts.anchor.anchor
		header = util.format_anchor_label(opts.anchor)
	elseif opts.block then
		anchor = "#" .. opts.block.id
		header = "#" .. opts.block.id
	end

	local path = util.urlencode(opts.path, { keep_path_sep = true })
	return ("[%s%s](/%s%s)"):format(opts.label, header, path, anchor)
end

-- Based on defaults, but removing the note ID and title (unnecessary)
local note_frontmatter_func = function(note)
	local out = { aliases = note.aliases, tags = note.tags }
	out.aliases = vim.tbl_filter(function(alias)
		return alias ~= note.title
	end, out.aliases)
	return out
end

-- Use kebab-case title for the filename. By default, the note ID is used.
local function note_path_func(spec)
	spec.title = spec.title or spec.id
	local path = spec.dir / to_kebab_case(tostring(spec.title))
	return path:with_suffix(".md")
end

-- Use kebab-case timestamp. By default, "Pasted image %Y%m%d%H%M%S" is used.
local function img_name_func()
	return ("pasted-image-%s"):format(os.date("%Y%m%d%H%M%S"))
end

-- Use the vault-relative path in the image link.
-- By default, the link is created with only the filename.
local function img_text_func(path)
	local util = require("obsidian.util")
	path = tostring(path:vault_relative_path())
	path = util.urlencode(path, { keep_path_sep = true })
	return ("![pasted image](/%s)"):format(path)
end

return {
	"obsidian-nvim/obsidian.nvim",
	version = false,
	dependencies = {
		"nvim-lua/plenary.nvim", -- required
		"MeanderingProgrammer/render-markdown.nvim", -- for better rendering
		"ibhagwan/fzf-lua", -- for pickers
	},
	opts = {
		workspaces = { { name = "notes", path = vim.fn.getcwd } },
		new_notes_location = "notes_subdir",
		notes_subdir = "0-inbox",
		completion = {
			nvim_cmp = false,
			blink = true,
		},
		backlinks = { parse_headers = false },
		link = { style = markdown_link_func },
		frontmatter = { func = note_frontmatter_func },
		note_path_func = note_path_func,
		attachments = {
			folder = "_assets/attachments",
			img_name_func = img_name_func,
			img_text_func = img_text_func,
			confirm_img_paste = false,
		},
		templates = { folder = "_assets/templates" },
		search = { sort = false }, -- avoid rg sorting, which is slow for large vaults
		ui = { enable = false }, -- render-markdown takes care of nice rendering
		footer = { enabled = false }, -- reduce rg calls, which are slow for large vaults
		-- Get rid of the warning. I can remove it from version 4.
		-- See https://github.com/obsidian-nvim/obsidian.nvim/wiki/Commands
		legacy_commands = false,
	},
	config = function(_, opts)
		require("obsidian").setup(opts)

		vim.api.nvim_create_autocmd("User", {
			desc = "Remove Obisian smart action (<CR>)",
			pattern = "ObsidianNoteEnter",
			callback = function(ev)
				vim.keymap.del("n", "<CR>", { buffer = ev.buf })
			end,
		})

		-- Find operations (with picker)
		vim.keymap.set("n", "<Leader>of", "<Cmd>Obsidian quick_switch<CR>", { desc = "[o]bsidian [f]ind note" })
		vim.keymap.set("n", "<Leader>os", "<Cmd>Obsidian search<CR>", { desc = "[o]bsidian [s]earch" })
		vim.keymap.set("n", "<Leader>ot", "<Cmd>Obsidian tags<CR>", { desc = "[o]bsidian [t]ag" })
		vim.keymap.set("n", "<Leader>ol", "<Cmd>Obsidian links<CR>", { desc = "[o]bsidian [l]inks" })
		vim.keymap.set("n", "<Leader>ob", "<Cmd>Obsidian backlinks<CR>", { desc = "[o]bsidian [b]acklinks" })

		-- Edit operations
		vim.keymap.set("x", "<Leader>ol", "<Cmd>Obsidian link<CR>", { desc = "[o]bsidian add [l]ink" })
		vim.keymap.set("n", "<Leader>op", "<Cmd>Obsidian paste_img <CR>", { desc = "[o]bsidian [p]aste image" })
		vim.keymap.set("n", "<Leader>or", "<Cmd>Obsidian rename<CR>", { desc = "[o]bsidian [r]ename" })
		vim.keymap.set("n", "<Leader>on", "<Cmd>Obsidian new<CR>", { desc = "[o]bsidian new [n]ote" })
		vim.keymap.set("x", "<Leader>on", ":Obsidian extract_note<CR>", { desc = "[o]bsidian extract [n]ote" })
		vim.keymap.set(
			"n",
			"<Leader>oN",
			"<Cmd>Obsidian new_from_template<CR>",
			{ desc = "[o]bsidian new [n]ote from template" }
		)
	end,
}

Environment

==============================================================================
obsidian:                                                                   ✅

- ✅ OK neovim >= 0.11 (0.11.5)

[Version] ~
- ✅ OK obsidian.nvim v3.16.0 (5d311f3f8db69769515b6d3d0207bac6ee51668c)

[Environment] ~
- ✅ OK operating system: Darwin

[Config] ~
- ✅ OK dir: /Users/erugfra/Library/CloudStorage/Nextcloud-franco-ruggeri@www.nextcloud.ruggeri.ddnsfree.com

[Pickers] ~
- ✅ OK fzf-lua: 8a79ee54d6216d10b2f153921a12b152be0c1a20
- ✅ OK snacks.nvim: a4e46becca45eb65c73a388634b1ce8aad629ae0

[Completion] ~
- ✅ OK blink.cmp: b19413d214068f316c78978b08264ed1c41830ec

[Dependencies] ~
- ✅ OK rg: 14.1.1
- ✅ OK pngpaste: found

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions