Browse Source

org-id-update-id-locations: Disable cache in throwaway buffers

* lisp/org-macs.el (org-element-with-disabled-cache): Move from
org-element.el to org-macs.el
Ihor Radchenko 3 years ago
parent
commit
2b49d6fd9c
3 changed files with 33 additions and 30 deletions
  1. 0 6
      lisp/org-element.el
  2. 27 24
      lisp/org-id.el
  3. 6 0
      lisp/org-macs.el

+ 0 - 6
lisp/org-element.el

@@ -265,12 +265,6 @@ specially in `org-element--object-lex'.")
 
 (org-element--set-regexps)
 
-(defmacro org-element-with-disabled-cache (&rest body)
-  "Run BODY without active org-element-cache."
-  (declare (debug (form body)) (indent 1))
-  `(cl-letf (((symbol-function #'org-element--cache-active-p) (lambda (&rest _) nil)))
-     ,@body))
-
 ;;;###autoload
 (defun org-element-update-syntax ()
   "Update parser internals."

+ 27 - 24
lisp/org-id.el

@@ -76,6 +76,8 @@
 
 (declare-function message-make-fqdn "message" ())
 (declare-function org-goto-location "org-goto" (&optional _buf help))
+;; Declared inside `org-element-with-disabled-cache' macro.
+(declare-function org-element--cache-active-p "org-element.el" (&optional called-from-cache-change-func-p))
 
 ;;; Customization
 
@@ -522,30 +524,31 @@ If SILENT is non-nil, messages are suppressed."
          (ndup 0)
          (i 0))
     (with-temp-buffer
-      (delay-mode-hooks
-	(org-mode)
-	(dolist (file files)
-	  (when (file-exists-p file)
-            (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)
-		  (case-fold-search t))
-              (org-with-point-at 1
-		(while (re-search-forward id-regexp nil t)
-		  (when (org-at-property-p)
-                    (push (org-entry-get (point) "ID") ids)))
-		(when ids
-		  (push (cons (abbreviate-file-name file) ids)
-			org-id-locations)
-		  (dolist (id ids)
-                    (cond
-                     ((not (member id seen-ids)) (push id seen-ids))
-                     (silent nil)
-                     (t
-                      (message "Duplicate ID %S" id)
-                      (cl-incf ndup)))))))))))
+      (org-element-with-disabled-cache
+          (delay-mode-hooks
+	    (org-mode)
+	    (dolist (file files)
+	      (when (file-exists-p file)
+                (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)
+		      (case-fold-search t))
+                  (org-with-point-at 1
+		    (while (re-search-forward id-regexp nil t)
+		      (when (org-at-property-p)
+                        (push (org-entry-get (point) "ID") ids)))
+		    (when ids
+		      (push (cons (abbreviate-file-name file) ids)
+			    org-id-locations)
+		      (dolist (id ids)
+                        (cond
+                         ((not (member id seen-ids)) (push id 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.

+ 6 - 0
lisp/org-macs.el

@@ -212,6 +212,12 @@ because otherwise all these markers will point to nowhere."
   `(let (pop-up-frames pop-up-windows)
      ,@body))
 
+(defmacro org-element-with-disabled-cache (&rest body)
+  "Run BODY without active org-element-cache."
+  (declare (debug (form body)) (indent 1))
+  `(cl-letf (((symbol-function #'org-element--cache-active-p) (lambda (&rest _) nil)))
+     ,@body))
+
 
 ;;; Buffer and windows