Function: org-id-find-id-in-file

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

Signature

(org-id-find-id-in-file ID FILE &optional MARKERP)

Documentation

Return the position of the entry ID in FILE.

If that files does not exist, or if it does not contain this ID, return nil.

The position is returned as a cons cell (file-name . position). With optional argument MARKERP, return the position as a new marker.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-id.el.gz
(defun org-id-find-id-in-file (id file &optional markerp)
  "Return the position of the entry ID in FILE.

If that files does not exist, or if it does not contain this ID,
return nil.

The position is returned as a cons cell (file-name . position).  With
optional argument MARKERP, return the position as a new marker."
  (cond
   ((not file) nil)
   ((not (file-exists-p file)) nil)
   (t
    (let* ((visiting (find-buffer-visiting file))
	   (buffer (or visiting
                       (if markerp (find-file-noselect file)
                         (org-get-buffer-create " *Org ID temp*" t)))))
      (unwind-protect
	  (with-current-buffer buffer
            (unless (derived-mode-p 'org-mode) (org-mode))
            (unless (or visiting markerp)
              (buffer-disable-undo)
              ;; FIXME: In Emacs 27, `insert-file-contents' seemingly
              ;; does not trigger modification hooks in some
              ;; scenarios.  This is manifested in test failures due
              ;; to element cache losing track of the modifications.
              (org-element-cache-reset)
              (insert-file-contents file nil nil nil 'replace))
	    (let ((pos (org-find-entry-with-id id)))
	      (cond
	       ((null pos) nil)
	       (markerp (move-marker (make-marker) pos buffer))
	       (t (cons file pos)))))
	;; Clean temporarily buffer if we don't need to keep it.
	(unless (or visiting markerp)
          (with-current-buffer buffer (erase-buffer))))))))