Explorar o código

org-archive-subtree: Speed up archiving

* lisp/org-element.el (org-element--cache-avoid-synchronous-headline-re-parsing):
  New internal variable controlling latency of cache
  `after-change-functions'.

(org-element--cache-for-removal): Use
`org-element--cache-avoid-synchronous-headline-re-parsing' to decide
if we re-parse changed headlines immidiately.
* lisp/org-archive.el (org-archive-subtree): Let-bind
`org-element--cache-avoid-synchronous-headline-re-parsing' to t while
archiving for better speed.
Ihor Radchenko %!s(int64=3) %!d(string=hai) anos
pai
achega
8868f0fddd
Modificáronse 2 ficheiros con 20 adicións e 1 borrados
  1. 6 1
      lisp/org-archive.el
  2. 14 0
      lisp/org-element.el

+ 6 - 1
lisp/org-archive.el

@@ -35,6 +35,9 @@
 (declare-function org-datetree-find-date-create "org-datetree" (date &optional keep-restriction))
 (declare-function org-inlinetask-remove-END-maybe "org-inlinetask" ())
 
+;; From org-element.el
+(defvar org-element--cache-avoid-synchronous-headline-re-parsing)
+
 (defcustom org-archive-default-command 'org-archive-subtree
   "The default archiving command."
   :group 'org-archive
@@ -253,7 +256,9 @@ direct children of this heading."
 	      (if (local-variable-p 'org-odd-levels-only (current-buffer))
 		  org-odd-levels-only
 		tr-org-odd-levels-only))
-	     level datetree-date datetree-subheading-p)
+	     level datetree-date datetree-subheading-p
+             ;; Suppress on-the-fly headline updates.
+             (org-element--cache-avoid-synchronous-headline-re-parsing t))
 	(when (string-match "\\`datetree/\\(\\**\\)" heading)
 	  ;; "datetree/" corresponds to 3 levels of headings.
 	  (let ((nsub (length (match-string 1 heading))))

+ 14 - 0
lisp/org-element.el

@@ -6583,6 +6583,19 @@ that range.  See `after-change-functions' for more information."
         ;; Activate a timer to process the request during idle time.
         (org-element--cache-set-timer (current-buffer))))))
 
+(defvar org-element--cache-avoid-synchronous-headline-re-parsing nil
+  "This variable controls how buffer changes are handled by the cache.
+
+By default (when this variable is nil), cache re-parses modified
+headlines immidiately after modification preserving all the unaffected
+elements inside the headline.
+
+The default behaviour works best when users types inside Org buffer of
+when buffer modifications are mixed with cache requests.  However,
+large automated edits inserting/deleting many headlines are somewhat
+slower by default (as in `org-archive-subtree').  Let-binding this
+variable to non-nil will reduce cache latency after every singular edit
+(`after-change-functions') at the cost of slower cache queries.")
 (defun org-element--cache-for-removal (beg end offset)
   "Return first element to remove from cache.
 
@@ -6674,6 +6687,7 @@ known element in cache (it may start after END)."
                      ;; its boundaries could have extended to shrinked - we
                      ;; will re-parent and shift them anyway.
                      (and (eq 'headline (org-element-type up))
+                          (not org-element--cache-avoid-synchronous-headline-re-parsing)
                           ;; The change is not inside headline.  Not
                           ;; updating here.
                           (not (<= beg (org-element-property :begin up)))