mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-24 19:32:52 +00:00
org-id-find-id-in-file: Prefer using temporary buffer
* lisp/org-id.el (org-id-find-id-in-file): Use a temporary throwaway Org buffer to lookup IDs when we do not need to keep the buffer. This speeds up updating IDs.
This commit is contained in:
parent
cc435cba71
commit
4cf0b0433d
|
@ -675,16 +675,23 @@ optional argument MARKERP, return the position as a new marker."
|
|||
((not (file-exists-p file)) nil)
|
||||
(t
|
||||
(let* ((visiting (find-buffer-visiting file))
|
||||
(buffer (or visiting (find-file-noselect file))))
|
||||
(buffer (or visiting
|
||||
(if markerp (find-file-noselect file)
|
||||
(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)
|
||||
(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)))))
|
||||
;; Remove opened buffer in the process.
|
||||
(unless (or visiting markerp) (kill-buffer buffer)))))))
|
||||
;; Clean temporarily buffer if we don't need to keep it.
|
||||
(unless (or visiting markerp)
|
||||
(with-current-buffer buffer (erase-buffer))))))))
|
||||
|
||||
;; id link type
|
||||
|
||||
|
|
Loading…
Reference in a new issue