org-mode: Initialise cache before initialising file-local regexps

* lisp/org.el (org-mode): Initialise cache earlier, allowing the
file-local settings to be taken from persistent cache when
possible.  Also, bind `org-mode-loading' while org-mode is loading.
* lisp/ol.el (org-update-radio-target-regexp): Do not try to refresh
cache when we are loading file for the first time.
This commit is contained in:
Ihor Radchenko 2022-01-19 11:53:34 +08:00
parent 0725237eed
commit 37edef8bbd
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 12 additions and 7 deletions

View File

@ -2020,7 +2020,8 @@ Also refresh fontification if needed."
(list old-regexp org-target-link-regexp)
"\\|")
after-re)))))
(when (featurep 'org-element)
(when (and (featurep 'org-element)
(not (bound-and-true-p org-mode-loading)))
(org-with-point-at 1
(while (re-search-forward regexp nil t)
(org-element-cache-refresh (match-beginning 1))))))

View File

@ -4820,6 +4820,8 @@ This is for getting out of special buffers like capture.")
(defvar org-element-cache-persistent); Defined in org-element.el
(defvar org-element-use-cache); Defined in org-element.el
(defvar org-mode-loading nil
"Non-nil during Org mode initialisation.")
;;;###autoload
(define-derived-mode org-mode outline-mode "Org"
"Outline-based notes management and organizer, alias
@ -4839,6 +4841,7 @@ can be exported as a structured ASCII or HTML file.
The following commands are available:
\\{org-mode-map}"
(setq-local org-mode-loading t)
(org-load-modules-maybe)
(org-install-agenda-files-menu)
(when org-link-descriptive (add-to-invisibility-spec '(org-link)))
@ -4874,6 +4877,11 @@ The following commands are available:
(add-hook 'before-change-functions 'org-before-change-function nil 'local)
;; Check for running clock before killing a buffer
(add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local)
;; Initialize cache.
(org-element-cache-reset)
(when (and org-element-cache-persistent
org-element-use-cache)
(org-persist-read 'org-element--cache (current-buffer)))
;; Initialize macros templates.
(org-macro-initialize-templates)
;; Initialize radio targets.
@ -4885,11 +4893,6 @@ The following commands are available:
(org-setup-filling)
;; Comments.
(org-setup-comments-handling)
;; Initialize cache.
(org-element-cache-reset)
(when (and org-element-cache-persistent
org-element-use-cache)
(org-persist-read 'org-element--cache (current-buffer)))
;; Beginning/end of defun
(setq-local beginning-of-defun-function 'org-backward-element)
(setq-local end-of-defun-function
@ -4978,7 +4981,8 @@ The following commands are available:
;; Set face extension as requested.
(org--set-faces-extend '(org-block-begin-line org-block-end-line)
org-fontify-whole-block-delimiter-line)
(org--set-faces-extend org-level-faces org-fontify-whole-heading-line))
(org--set-faces-extend org-level-faces org-fontify-whole-heading-line)
(setq-local org-mode-loading nil))
;; Update `customize-package-emacs-version-alist'
(add-to-list 'customize-package-emacs-version-alist