Function: org-element-with-enabled-cache

org-element-with-enabled-cache is a macro defined in org-element.el.gz.

Signature

(org-element-with-enabled-cache &rest BODY)

Documentation

Run BODY with org-element cache enabled (maybe temporarily).

When cache is enabled, just run body. When cache is disabled, initialize a new cache, run BODY, and cleanup at the end.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-element.el.gz
(defmacro org-element-with-enabled-cache (&rest body)
  "Run BODY with org-element cache enabled (maybe temporarily).
When cache is enabled, just run body.
When cache is disabled, initialize a new cache, run BODY, and cleanup
at the end."
  (declare (debug (form body)) (indent 0))
  (org-with-gensyms (old-state buffer)
    `(if (org-element--cache-active-p)
         ;; Cache is active, just run BODY.
         (progn ,@body)
       ;; Cache is disabled.
       ;; Save existing cache.
       (let ((,buffer (current-buffer))
             (,old-state
              (org-with-base-buffer nil
                (mapcar #'symbol-value org-element--cache-variables)))
             (org-element-use-cache t))
         (unwind-protect
             (progn
               (org-element-cache-reset)
               ,@body)
           (cl-mapc
            (lambda (var values)
              (org-with-base-buffer ,buffer
                (set var values)))
            org-element--cache-variables
            ,old-state))))))