Merge branch 'feature/org-persist-new-tidy'

This commit is contained in:
Ihor Radchenko 2022-01-29 17:16:35 +08:00
commit ac5742f296
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 857 additions and 283 deletions

View File

@ -7054,15 +7054,17 @@ The element is: %S\n The real element is: %S\n Cache around :begin:\n%S\n%S\n%S"
;;; Cache persistance ;;; Cache persistance
(defun org-element--cache-persist-before-write (var &optional buffer) (defun org-element--cache-persist-before-write (container &optional associated)
"Sync cache before saving." "Sync cache before saving."
(when (and org-element-use-cache (when (equal container '(elisp org-element--cache))
buffer (if (and org-element-use-cache
org-element-cache-persistent (plist-get associated :file)
(eq var 'org-element--cache) (get-file-buffer (plist-get associated :file))
(derived-mode-p 'org-mode) org-element-cache-persistent)
(with-current-buffer (get-file-buffer (plist-get associated :file))
(if (and (derived-mode-p 'org-mode)
org-element--cache) org-element--cache)
(with-current-buffer buffer (progn
;; Cleanup cache request keys to avoid collisions during next ;; Cleanup cache request keys to avoid collisions during next
;; Emacs session. ;; Emacs session.
(avl-tree-mapc (avl-tree-mapc
@ -7070,27 +7072,35 @@ The element is: %S\n The real element is: %S\n Cache around :begin:\n%S\n%S\n%S"
(org-element-put-property el :org-element--cache-sync-key nil)) (org-element-put-property el :org-element--cache-sync-key nil))
org-element--cache) org-element--cache)
(org-with-wide-buffer (org-with-wide-buffer
(org-element-at-point (point-max)))) (org-element-at-point (point-max)))
nil)) nil)
'forbid))
'forbid)))
(defun org-element--cache-persist-before-read (var &optional buffer) (defun org-element--cache-persist-before-read (container &optional associated)
"Avoid reading cache before Org mode is loaded." "Avoid reading cache before Org mode is loaded."
(when (memq var '(org-element--cache org-element--headline-cache)) (when (equal container '(elisp org-element--cache))
(if (not buffer) 'forbid (if (not (and (plist-get associated :file)
(with-current-buffer buffer (get-file-buffer (plist-get associated :file))))
'forbid
(with-current-buffer (get-file-buffer (plist-get associated :file))
(unless (and org-element-use-cache (unless (and org-element-use-cache
org-element-cache-persistent org-element-cache-persistent
(derived-mode-p 'org-mode)) (derived-mode-p 'org-mode)
(equal (secure-hash 'md5 (current-buffer))
(plist-get associated :hash)))
'forbid))))) 'forbid)))))
(defun org-element--cache-persist-after-read (var &optional buffer) (defun org-element--cache-persist-after-read (container &optional associated)
"Setup restored cache." "Setup restored cache."
(with-current-buffer buffer (when (and (plist-get associated :file)
(get-file-buffer (plist-get associated :file)))
(with-current-buffer (get-file-buffer (plist-get associated :file))
(when (and org-element-use-cache org-element-cache-persistent) (when (and org-element-use-cache org-element-cache-persistent)
(when (and (eq var 'org-element--cache) org-element--cache) (when (and (equal container '(elisp org-element--cache)) org-element--cache)
(setq-local org-element--cache-size (avl-tree-size org-element--cache))) (setq-local org-element--cache-size (avl-tree-size org-element--cache)))
(when (and (eq var 'org-element--headline-cache) org-element--headline-cache) (when (and (equal container '(elisp org-element--headline-cache)) org-element--headline-cache)
(setq-local org-element--headline-cache-size (avl-tree-size org-element--headline-cache)))))) (setq-local org-element--headline-cache-size (avl-tree-size org-element--headline-cache)))))))
(add-hook 'org-persist-before-write-hook #'org-element--cache-persist-before-write) (add-hook 'org-persist-before-write-hook #'org-element--cache-persist-before-write)
(add-hook 'org-persist-before-read-hook #'org-element--cache-persist-before-read) (add-hook 'org-persist-before-read-hook #'org-element--cache-persist-before-read)
@ -7115,7 +7125,8 @@ buffers."
(when (not org-element-cache-persistent) (when (not org-element-cache-persistent)
(org-persist-unregister 'org-element--headline-cache (current-buffer)) (org-persist-unregister 'org-element--headline-cache (current-buffer))
(org-persist-unregister 'org-element--cache (current-buffer))) (org-persist-unregister 'org-element--cache (current-buffer)))
(when org-element-cache-persistent (when (and org-element-cache-persistent
(buffer-file-name (current-buffer)))
(org-persist-register 'org-element--cache (current-buffer)) (org-persist-register 'org-element--cache (current-buffer))
(org-persist-register 'org-element--headline-cache (org-persist-register 'org-element--headline-cache
(current-buffer) (current-buffer)

File diff suppressed because it is too large Load Diff

View File

@ -191,7 +191,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
(declare-function org-latex-make-preamble "ox-latex" (info &optional template snippet?)) (declare-function org-latex-make-preamble "ox-latex" (info &optional template snippet?))
(declare-function org-num-mode "org-num" (&optional arg)) (declare-function org-num-mode "org-num" (&optional arg))
(declare-function org-plot/gnuplot "org-plot" (&optional params)) (declare-function org-plot/gnuplot "org-plot" (&optional params))
(declare-function org-persist-read "org-persist" (var &optional buffer)) (declare-function org-persist-load "org-persist" (container &optional associated hash-must-match))
(declare-function org-tags-view "org-agenda" (&optional todo-only match)) (declare-function org-tags-view "org-agenda" (&optional todo-only match))
(declare-function org-timer "org-timer" (&optional restart no-insert)) (declare-function org-timer "org-timer" (&optional restart no-insert))
(declare-function org-timer-item "org-timer" (&optional arg)) (declare-function org-timer-item "org-timer" (&optional arg))
@ -204,6 +204,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
(defvar org-agenda-buffer-name) (defvar org-agenda-buffer-name)
(defvar org-element-paragraph-separate) (defvar org-element-paragraph-separate)
(defvar org-element-cache-map-continue-from)
(defvar org-indent-indentation-per-level) (defvar org-indent-indentation-per-level)
(defvar org-radio-target-regexp) (defvar org-radio-target-regexp)
(defvar org-target-link-regexp) (defvar org-target-link-regexp)
@ -4881,7 +4882,7 @@ The following commands are available:
(org-element-cache-reset) (org-element-cache-reset)
(when (and org-element-cache-persistent (when (and org-element-cache-persistent
org-element-use-cache) org-element-use-cache)
(org-persist-read 'org-element--cache (current-buffer))) (org-persist-load 'org-element--cache (current-buffer) t))
;; Initialize macros templates. ;; Initialize macros templates.
(org-macro-initialize-templates) (org-macro-initialize-templates)
;; Initialize radio targets. ;; Initialize radio targets.