summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhor Radchenko <yantar92@posteo.net>2026-05-01 09:08:33 +0200
committerIhor Radchenko <yantar92@posteo.net>2026-05-01 17:04:17 +0200
commit95d6f219995ea93937c26d7744386c21956b8cc0 (patch)
tree3c0d59601663aad2bd8e13d80e3c964a02e889b2
parent7522e2850a6c72593fd683e1b0f3900fa5beb3e7 (diff)
org-id-update-id-locations: Prefer using file buffer in Emacs over fileexternals/org
* lisp/org-id.el (org-id-update-id-locations): If Org buffer is already open, prefer reading text from that buffer over what is saved on the disk.
-rw-r--r--lisp/org-id.el40
1 files changed, 21 insertions, 19 deletions
diff --git a/lisp/org-id.el b/lisp/org-id.el
index ff8024a..9f4d68c 100644
--- a/lisp/org-id.el
+++ b/lisp/org-id.el
@@ -576,25 +576,27 @@ If SILENT is non-nil, messages are suppressed."
(unless silent
(cl-incf i)
(message "Finding ID locations (%d/%d files): %s" i nfiles file))
- (insert-file-contents file nil nil nil 'replace)
- (let ((ids nil)
- node
- (case-fold-search t))
- (org-with-point-at 1
- (while (re-search-forward id-regexp nil t)
- (setq node (org-element-at-point))
- (when (org-element-type-p node 'node-property)
- (push (org-element-property :value node) ids)))
- (when ids
- (push (cons (abbreviate-file-name file) ids)
- org-id-locations)
- (dolist (id ids)
- (cond
- ((not (gethash id seen-ids)) (puthash id t seen-ids))
- (silent nil)
- (t
- (message "Duplicate ID %S" id)
- (cl-incf ndup)))))))))))
+ (let ((buf (or (get-file-buffer file) nil)))
+ (with-current-buffer (or buf (current-buffer))
+ (unless buf (insert-file-contents file nil nil nil 'replace))
+ (let ((ids nil)
+ node
+ (case-fold-search t))
+ (org-with-point-at 1
+ (while (re-search-forward id-regexp nil t)
+ (setq node (org-element-at-point))
+ (when (org-element-type-p node 'node-property)
+ (push (org-element-property :value node) ids)))
+ (when ids
+ (push (cons (abbreviate-file-name file) ids)
+ org-id-locations)
+ (dolist (id ids)
+ (cond
+ ((not (gethash id seen-ids)) (puthash id t seen-ids))
+ (silent nil)
+ (t
+ (message "Duplicate ID %S" id)
+ (cl-incf ndup)))))))))))))
(setq org-id-files (mapcar #'car org-id-locations))
(org-id-locations-save)
;; Now convert to a hash table.