Function: org-id-open

org-id-open is a byte-compiled function defined in org-id.el.gz.

Signature

(org-id-open LINK _)

Documentation

Go to the entry indicated by id link LINK.

The link can include a search string after "::", which is passed to org-link-search.

For backwards compatibility with IDs that contain "::", if no match is found for the ID, the full link string including "::" will be tried as an ID.

Aliases

org-roam-id-open

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-id.el.gz
(defun org-id-open (link _)
  "Go to the entry indicated by id link LINK.

The link can include a search string after \"::\", which is
passed to `org-link-search'.

For backwards compatibility with IDs that contain \"::\", if no
match is found for the ID, the full link string including \"::\"
will be tried as an ID."
  (let* ((option (and (string-match "::\\(.*\\)\\'" link)
		      (match-string 1 link)))
	 (id (if (not option) link
               (substring link 0 (match-beginning 0))))
         m cmd)
    (org-mark-ring-push)
    (setq m (org-id-find id 'marker))
    (when (and (not m) option)
      ;; Backwards compatibility: if id is not found, try treating
      ;; whole link as an id.
      (setq m (org-id-find link 'marker))
      (when m
        (setq option nil)))
    (unless m
      (error "Cannot find entry with ID \"%s\"" id))
    ;; Use a buffer-switching command in analogy to finding files
    (setq cmd
	  (or
	   (cdr
	    (assq
	     (cdr (assq 'file org-link-frame-setup))
	     '((find-file . switch-to-buffer)
	       (find-file-other-window . switch-to-buffer-other-window)
	       (find-file-other-frame . switch-to-buffer-other-frame))))
	   'switch-to-buffer-other-window))
    (if (not (equal (current-buffer) (marker-buffer m)))
	(funcall cmd (marker-buffer m)))
    (goto-char m)
    (move-marker m nil)
    (when option
      (save-restriction
        (unless (org-before-first-heading-p)
          (org-narrow-to-subtree))
        (org-link-search option nil nil
                         (org-element-lineage (org-element-at-point) 'headline t))))
    (org-fold-show-context)))