fixup! org-id-find-id-in-file: Prefer using temporary buffer

* lisp/org-id.el (org-id-find-id-in-file): Fix Emacs 27 compatibility.
Avoid modifications not captured by element cache.
This commit is contained in:
Ihor Radchenko 2023-08-17 15:45:10 +03:00
parent d1e4b93519
commit 1ae611c7e3
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 6 additions and 2 deletions

View File

@ -677,13 +677,17 @@ optional argument MARKERP, return the position as a new marker."
(let* ((visiting (find-buffer-visiting file))
(buffer (or visiting
(if markerp (find-file-noselect file)
(get-buffer-create " *Org ID temp*" t)))))
(if (<= 2 (cdr (func-arity #'get-buffer-create)))
(get-buffer-create " *Org ID temp*" t)
;; Emacs 27 does not yet have second argument.
(get-buffer-create " *Org ID temp*"))))))
(unwind-protect
(with-current-buffer buffer
(unless (derived-mode-p 'org-mode) (org-mode))
(unless (or visiting markerp)
(buffer-disable-undo)
(insert-file-contents file nil nil nil 'replace))
(erase-buffer)
(insert-file-contents file))
(let ((pos (org-find-entry-with-id id)))
(cond
((null pos) nil)