1

I am using ids with org-mode by setting:

(setq org-id-link-to-org-use-id 'create-if-interactive)

However, there are instances where I want to link to another heading without using ids. I want to use the [[target][file:~/org/test.org::target]] syntax instead. Is there a way to generate links like that without creating a custom function?

I tried looking at org-mode's source code, and as far as I can tell, the org-store-link function generates this kind of link manually here.

New contributor
hll02 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

It looks like org-id-link-to-org-use-id is set to nil by default, it will "Never use an ID to make a link, instead link using a text search for the headline text." So TL;DR, set it to nil. If that doesn't work, I've included more info below.

It would be nice if there was an easy way to toggle which you prefer without setting the var, but you could make a separate function or keybinding for it.

If it is set to nil and org-link-context-for-files (formerly org-context-in-file-links) is non-nil (which is the default), quoting from Emacs' help:org-link-context-for-files

Non-nil means file links from org-store-link contain context.

A search string is added to the file name with "::" as separator and used to find the context when the link is activated by the command org-open-at-point. When this option is t, the entire active region is be placed in the search string of the file link. If set to a positive integer N, only the first N lines of context are stored.

Using a prefix argument to the command org-store-link (C-u C-c l) negates this setting for the duration of the command. it instead saves some text to search for. I have almost always used it on an org-headline. It copies the asterisks and the text of the headline, which is usually enough to be unique.

It also automatically uses the headline for the description when you call org-insert-link. If you have a region selected, it will store all of that text as well.

If you look up the variable through Emacs' help (help:org-id-link-to-org-use-id), C-h v, or if you use M-x customize, it gives you all the possible options:

The variable can have the following values:

t     Create an ID if needed to make a link to the current entry.

create-if-interactive
      If org-store-link is called directly (interactively, as a user
      command), do create an ID to support the link.  But when doing the
      job for capture, only use the ID if it already exists.  The
      purpose of this setting is to avoid proliferation of unwanted
      IDs, just because you happen to be in an Org file when you
      call org-capture that automatically and preemptively creates a
      link.  If you do want to get an ID link in a capture template to
      an entry not having an ID, create it first by explicitly creating
      a link to it, using C-c l first.

create-if-interactive-and-no-custom-id
      Like create-if-interactive, but do not create an ID if there is
      a CUSTOM_ID property defined in the entry.

use-existing
      Use existing ID, do not create one.

nil   Never use an ID to make a link, instead link using a text search for
      the headline text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.