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

Using :ObsidianLinkNew create file but not wiki-link #814

Open
Zachmd14 opened this issue Jan 13, 2025 · 0 comments
Open

Using :ObsidianLinkNew create file but not wiki-link #814

Zachmd14 opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Zachmd14
Copy link

Zachmd14 commented Jan 13, 2025

🐛 Describe the bug

When I select a word or even multiples words and use the :ObsidianLinkNew command, it successfully create a new file with the name rightly formated, but throw a lua error and dont create the link, leaving the visual selection the same as before, plain text.

Config

return {
	"epwalsh/obsidian.nvim",
	version = "*", -- recommended, use latest release instead of latest commit
	lazy = false,
	ft = "markdown",
	-- Replace the above line with this if you only want to load obsidian.nvim for markdown files in your vault:
	-- event = {
	--   -- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand'.
	--   -- E.g. "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/**.md"
	--   "BufReadPre path/to/my-vault/**.md",
	--   "BufNewFile path/to/my-vault/**.md",
	-- },
	dependencies = {
		-- Required.
		"nvim-lua/plenary.nvim",

	},
	opts = {
		disable_frontmatter = true,
		sort_by = "accessed",
		picker = {
			name = "fzf-lua",
			sort_reversed = true,
		},
		workspaces = {
			{
				name = "personal",
				path = "~/Documents/Obsidian/mainVault/",
			},

			vim.keymap.set('n', '<leader>of', ':ObsidianFollowLink<CR>', {}),
			vim.keymap.set('n', '<leader>oq', ':ObsidianQuickSwitch<CR>', {}),
			vim.keymap.set('n', '<leader>oo', ':ObsidianTOC<CR>', {}),
			vim.keymap.set('n', '<leader>og', ':ObsidianTags<CR>', {}),
			vim.keymap.set('n', '<leader>od', ':ObsidianToday<CR>', {}),
			vim.keymap.set('n', '<leader>op', ':ObsidianPasteImg<CR>', {}),
			vim.keymap.set('n', '<leader>ob', ':ObsidianBacklinks<CR>', {}),
			vim.keymap.set('v', '<C-l>', [[:'<,'>ObsidianLinkNew<CR>]], { noremap = true, silent = true }),
			vim.keymap.set('n', '<leader>ot', ':ObsidianTemplate<CR>', {}),
			-- vim.keymap.set('n', '<leader>or',
			-- ':call system("find ~/Documents/Obsidian/mainVault/ -type f | awk -v var=$(($RANDOM)) "NR==var {print $0}" | xargs nvim")<CR>',
			-- {}),
			vim.keymap.set('n', '<leader>on',
				function()
					local title = vim.fn.input('Enter note title: ')
					if title ~= '' then
						vim.cmd('ObsidianNew ' .. title)
					else
						print('Title cannot be empty')
					end
				end, {})

		},

		-- Optional, customize how note IDs are generated given an optional title.
		---@param title string|?
		---@return string

		note_id_func = function(title)
			if title ~= nil then
				-- If title is given, transform it into a valid file name and return it as the ID.
				return title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower()
			else
				-- If no title is given, fall back to generating an ID with 4 random letters or a timestamp.
				local suffix = ""
				for _ = 1, 4 do
					suffix = suffix .. string.char(math.random(65, 90))
				end
				return tostring(os.time()) .. "-" .. suffix
			end
		end,


		attachments = {
			img_folder = "~/Documents/Obsidian/mainVault/files/",
		},

		daily_notes = {
			-- Optional, if you keep daily notes in a separate directory.
			folder = "Daily",
			-- Optional, if you want to change the date format for the ID of daily notes.
			date_format = "%Y-%m-%d",
			-- Optional, if you want to change the date format of the default alias of daily notes.
			alias_format = "%B %-d, %Y",
			-- Optional, default tags to add to each new daily note created.
			default_tags = { "daily-notes" },
			-- Optional, if you want to automatically insert a template from your template directory like 'daily.md'
			template = "Daily template"
		},

		templates = {
			folder = "~/Documents/Obsidian/mainVault/templates",
			date_format = "%Y-%m-%d",
			time_format = "%H:%M",
			-- A map for custom variables, the key should be the variable and the value a function
			substitutions = {},
		},

		wiki_link_func = function(opts)
			return require("obsidian.util").wiki_link_path(opts)
		end,

		ui = {
			enable = false, -- set to false to disable all additional syntax features
		},
	}

}
{{{

### Environment
```text
NVIM v0.10.3
Build type: RelWithDebInfo
LuaJIT 2.1.1731601260
Run "nvim -V1 -v" for more info
Obsidian.nvim v3.9.0 (ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b)
Status:
  • buffer directory: nilworking directory: /home/zach
Workspaces:
  ✓ active workspace: Workspace(name='personal', path='/home/zach/Documents/Obsidian/mainVault', root='/home/zach/Documents/Obsidian/mainVault')
Dependencies:
  ✓ plenary.nvim: 2d9b06177a975543726ce5c73fca176cedbffe9d
  ✓ telescope.nvim: a0bbec21143c7bc5f8bb02e0005fa0b982edc026fzf-lua: 21849312a3eae7d8115a83b7a3f9c54a4e29c611
Integrations:
  ✓ picker: FzfPicker()
  ✗ completion: disabled
Tools:
  ✓ rg: ripgrep 14.1.1
Environment:
  • operating system: Linux
Config:
  • notes_subdir: nil

Error

Error executing Lua callback: /home/zach/.config/nvim/lua/zach/plugins/obsidian.lua:100: attempt to call field 'wiki_link_path' (a nil value)
stack traceback:
	/home/zach/.config/nvim/lua/zach/plugins/obsidian.lua:100: in function 'format_link'
	...im/lazy/obsidian.nvim/lua/obsidian/commands/link_new.lua:27: in function 'func'
	...e/nvim/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:70: in function <...e/nvim/lazy/obsidian.nvim/lua/obsidian/commands/init.lua:69>
@Zachmd14 Zachmd14 added the bug Something isn't working label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant