forked from mirrors/org-mode
org-fold-core: Try harder to reduce overheads
* lisp/org-fold-core.el (org-fold-core-cycle-over-indirect-buffers): Clear folds from killed indirect buffers once only. Avoid calling `remove-text-properties' when there is nothing to remove. * lisp/org-fold-core.el (org-fold-core--fix-folded-region): Ignore deletions more aggressively, avoiding the calls to `org-fold-core-cycle-over-indirect-buffers'.
This commit is contained in:
parent
e9d6a54791
commit
7b3b7b92e7
|
@ -502,6 +502,9 @@ hanging around."
|
||||||
;; different buffer. This can happen, for example, when
|
;; different buffer. This can happen, for example, when
|
||||||
;; org-capture copies local variables into *Capture* buffer.
|
;; org-capture copies local variables into *Capture* buffer.
|
||||||
(setq buffers (list (current-buffer)))
|
(setq buffers (list (current-buffer)))
|
||||||
|
(let ((all-buffers (buffer-local-value
|
||||||
|
'org-fold-core--indirect-buffers
|
||||||
|
(or (buffer-base-buffer) (current-buffer)))))
|
||||||
(dolist (buf (cons (or (buffer-base-buffer) (current-buffer))
|
(dolist (buf (cons (or (buffer-base-buffer) (current-buffer))
|
||||||
(buffer-local-value 'org-fold-core--indirect-buffers (or (buffer-base-buffer) (current-buffer)))))
|
(buffer-local-value 'org-fold-core--indirect-buffers (or (buffer-base-buffer) (current-buffer)))))
|
||||||
(if (buffer-live-p buf)
|
(if (buffer-live-p buf)
|
||||||
|
@ -513,15 +516,20 @@ hanging around."
|
||||||
;; as argument to `remove-text-properties'.
|
;; as argument to `remove-text-properties'.
|
||||||
(push t dead-properties)
|
(push t dead-properties)
|
||||||
(push (gethash (cons buf spec) org-fold-core--property-symbol-cache)
|
(push (gethash (cons buf spec) org-fold-core--property-symbol-cache)
|
||||||
dead-properties))))))
|
dead-properties)))))
|
||||||
|
(when dead-properties
|
||||||
|
(with-current-buffer (or (buffer-base-buffer) (current-buffer))
|
||||||
|
(setq-local org-fold-core--indirect-buffers
|
||||||
|
(seq-filter #'buffer-live-p all-buffers))))))
|
||||||
(dolist (buf buffers)
|
(dolist (buf buffers)
|
||||||
(with-current-buffer buf
|
(with-current-buffer buf
|
||||||
|
(when dead-properties
|
||||||
(with-silent-modifications
|
(with-silent-modifications
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
(remove-text-properties
|
(remove-text-properties
|
||||||
(point-min) (point-max)
|
(point-min) (point-max)
|
||||||
dead-properties)))
|
dead-properties))))
|
||||||
,@body))))
|
,@body))))
|
||||||
|
|
||||||
;; This is the core function used to fold text in buffers. We use
|
;; This is the core function used to fold text in buffers. We use
|
||||||
|
@ -1277,19 +1285,19 @@ to :front-sticky/:rear-sticky folding spec property.
|
||||||
If the folded region is folded with a spec with non-nil :fragile
|
If the folded region is folded with a spec with non-nil :fragile
|
||||||
property, unfold the region if the :fragile function returns non-nil."
|
property, unfold the region if the :fragile function returns non-nil."
|
||||||
;; If no insertions or deletions in buffer, skip all the checks.
|
;; If no insertions or deletions in buffer, skip all the checks.
|
||||||
(unless (or (eq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick))
|
(unless (or org-fold-core--ignore-modifications
|
||||||
org-fold-core--ignore-modifications
|
(eq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick))
|
||||||
(memql 'ignore-modification-checks org-fold-core--optimise-for-huge-buffers))
|
(memql 'ignore-modification-checks org-fold-core--optimise-for-huge-buffers))
|
||||||
;; Store the new buffer modification state.
|
;; Store the new buffer modification state.
|
||||||
(setq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick))
|
(setq org-fold-core--last-buffer-chars-modified-tick (buffer-chars-modified-tick))
|
||||||
(save-match-data
|
(save-match-data
|
||||||
;; Handle changes in all the indirect buffers and in the base
|
;; Handle changes in all the indirect buffers and in the base
|
||||||
;; buffer. Work around Emacs bug#46982.
|
;; buffer. Work around Emacs bug#46982.
|
||||||
(when (eq org-fold-core-style 'text-properties)
|
|
||||||
(org-fold-core-cycle-over-indirect-buffers
|
|
||||||
;; Re-hide text inserted in the middle/front/back of a folded
|
;; Re-hide text inserted in the middle/front/back of a folded
|
||||||
;; region.
|
;; region.
|
||||||
(unless (equal from to) ; Ignore deletions.
|
(unless (equal from to) ; Ignore deletions.
|
||||||
|
(when (eq org-fold-core-style 'text-properties)
|
||||||
|
(org-fold-core-cycle-over-indirect-buffers
|
||||||
(dolist (spec (org-fold-core-folding-spec-list))
|
(dolist (spec (org-fold-core-folding-spec-list))
|
||||||
;; Reveal fully invisible text inserted in the middle
|
;; Reveal fully invisible text inserted in the middle
|
||||||
;; of visible portion of the buffer. This is needed,
|
;; of visible portion of the buffer. This is needed,
|
||||||
|
|
Loading…
Reference in a new issue