Function: org-id-store-link

org-id-store-link is an autoloaded, interactive and byte-compiled function defined in org-id.el.gz.

Signature

(org-id-store-link)

Documentation

Store a link to the current entry, using its ID.

The link description is based on the heading, or if before the first heading, the title keyword if available, or else the filename.

When org-link-context-for-files and org-id-link-use-context are non-nil, add a search string to the link. The link description is then based on the search string target.

When in addition org-id-link-consider-parent-id is non-nil, the ID can be inherited from a parent entry, with the search string used to still link to the current location.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-id.el.gz
;;;###autoload
(defun org-id-store-link ()
  "Store a link to the current entry, using its ID.

The link description is based on the heading, or if before the
first heading, the title keyword if available, or else the
filename.

When `org-link-context-for-files' and `org-id-link-use-context'
are non-nil, add a search string to the link.  The link
description is then based on the search string target.

When in addition `org-id-link-consider-parent-id' is non-nil, the
ID can be inherited from a parent entry, with the search string
used to still link to the current location."
  (interactive)
  (when (and (buffer-file-name (buffer-base-buffer))
             (derived-mode-p 'org-mode))
    ;; Get the precise target first, in case looking for an id causes
    ;; a properties drawer to be added at the current location.
    (let* ((precise-target (and org-link-context-for-files
                                org-id-link-use-context
                                (org-link-precise-link-target)))
           (link (concat "id:" (org-id--get-id-to-store-link 'create)))
           (id-location (or (and org-entry-property-inherited-from
                                 (marker-position org-entry-property-inherited-from))
                            (save-excursion (org-back-to-heading-or-point-min t) (point))))
	   (case-fold-search nil)
	   (desc (save-excursion
                   (goto-char id-location)
                   (cond ((org-before-first-heading-p)
                          (let ((keywords (org-collect-keywords '("TITLE"))))
                            (if keywords
                                (cadr (assoc "TITLE" keywords))
                              (file-name-nondirectory
			       (buffer-file-name (buffer-base-buffer))))))
                         ((looking-at org-complex-heading-regexp)
			  (if (match-end 4)
			      (match-string 4)
			    (match-string 0)))
                         (t link)))))
      ;; Precise targets should be after id-location to avoid
      ;; duplicating the current headline as a search string
      (when (and precise-target
                 (> (nth 2 precise-target) id-location))
         (setq link (concat link "::" (nth 0 precise-target)))
         (setq desc (nth 1 precise-target)))
      (org-link-store-props :link link :description desc :type "id")
      link)))