SOLVED: How to link to a headline in v2?

I just upgraded to v2. Now I don’t know how to link to headlines, just files. (Ironic, because I understand that the mechanism for doing both is the same now.)

The way I used to link to headlinles was with org-store-link and org-insert-link. I used to define them via org-roam-mode-map, but now that appears to have gone away, so instead I define global shortcuts:

(global-set-key (kbd "C-c C-l")
		(lambda () (interactive)
		  (org-insert-link) ) )
(global-set-key (kbd "C-c n l")
		(lambda () (interactive)
		  (org-store-link) ) )
(global-set-key (kbd "C-c n f")
		(lambda () (interactive)
		  (org-roam-node-find) ) )

org-roam-node-find and org-insert-link works as I had hoped. And M-x org-store-link does something, albeit not what I’d like. (I’d like it to insert PROPERTIES and an ID for the node, like it used to.) But when I run the shortcut for org-store-link, I get this error:

Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 2) 0)
  org-store-link()
  (lambda nil (interactive) (org-store-link))()
  funcall-interactively((lambda nil (interactive) (org-store-link)))
  call-interactively((lambda nil (interactive) (org-store-link)) nil nil)
  command-execute((lambda nil (interactive) (org-store-link)))

I can see that it wants more arguments, and I see in the documentation that the second argument indicates whether it was called interactively. but I can’t find anywhere in the documentation what the meaning of the first argument is.

Am I on the right track, or are org-store-link and org-insert-link not even the functions to use any more?

Strange. I have no problem with the two commands.
Any reason why you use lambda for keybinding?

(global-set-key (kbd "C-c n l")  #’org-store-link)

This should work (I use define-key ‘global-map but it should be the same thing).

note: i don’t know if I typed the quotation mark correctly above… But you know what I mean. Please take care of that if you copy and paste

Thanks, @nobiot! Written your way (I did have to change the quotation mark) the keyboard shortcut now does the same as M-x org-store-link, which is an improvement. But neither method creates an ID; instead it creates a link which, when pasted, looks like

[[*foo][foo]]

Can I configure org-store-link to do what it used to do? Namely, to create an ID in a PROPERTIES drawer under the target headline unless such is already present, and when pasted via org-insert-link, insert a link that looks like

 [[id:45a95cbc-1168-41c1-930d-3ecd746f408e][foo]]

You need an ID for a headline first. Run org-id-get-create on a headline to create the ID in a drawer. I have bound it to C-c n o in the Org mode map.

Once you save the file, Org-Roam will add it to the database.

Maybe you can use org-roam-node-insert?

I use org-id-store-link.

If you set variable org-id-link-to-org-use-id to non-nil (there are some options), you could also use org-store-link. I prefer to retain its behaviour for normal links, so I keep this variable nil (default).

I don’t believe these are influenced by Org-roam being V1 or V2, though.

1 Like

That did the trick! Now I can create an ID and store it in one fell swoop with org-store-link, and link to it with org-insert-link, just like before. Thanks again!

2 Likes