Function: org-fold-core-region
org-fold-core-region is a byte-compiled function defined in
org-fold-core.el.gz.
Signature
(org-fold-core-region FROM TO FLAG &optional SPEC-OR-ALIAS)
Documentation
Hide or show lines from FROM to TO, according to FLAG.
SPEC-OR-ALIAS is the folding spec or foldable element, as a symbol. If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region.
Aliases
org-fold-region
org-flag-region (obsolete since 9.6)
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-fold-core.el.gz
;;;; Changing visibility
;;;;; Region visibility
;; This is the core function performing actual folding/unfolding. The
;; folding state is stored in text property (folding property)
;; returned by `org-fold-core--property-symbol-get-create'. The value of the
;; folding property is folding spec symbol.
(defun org-fold-core-region (from to flag &optional spec-or-alias)
"Hide or show lines from FROM to TO, according to FLAG.
SPEC-OR-ALIAS is the folding spec or foldable element, as a symbol.
If SPEC-OR-ALIAS is omitted and FLAG is nil, unfold everything in the region."
(let ((spec (org-fold-core-get-folding-spec-from-alias spec-or-alias)))
(when spec (org-fold-core--check-spec spec))
(with-silent-modifications
(org-with-wide-buffer
(when (eq org-fold-core-style 'overlays) (remove-overlays from to 'invisible spec))
(if flag
(if (not spec)
(error "Calling `org-fold-core-region' with missing SPEC")
(if (eq org-fold-core-style 'overlays)
;; Use `front-advance' since text right before to the beginning of
;; the overlay belongs to the visible line than to the contents.
(let ((o (make-overlay from to nil
(org-fold-core-get-folding-spec-property spec :front-sticky)
(org-fold-core-get-folding-spec-property spec :rear-sticky))))
(overlay-put o 'evaporate t)
(overlay-put o (org-fold-core--property-symbol-get-create spec) spec)
(overlay-put o 'invisible spec)
(overlay-put o 'isearch-open-invisible #'org-fold-core--isearch-show)
;; FIXME: Disabling to work around Emacs bug#60399
;; and https://orgmode.org/list/87zgb6tk6h.fsf@localhost.
;; The proper fix will require making sure that
;; `org-fold-core-isearch-open-function' does not
;; delete the overlays used by isearch.
;; (overlay-put o 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
)
(put-text-property from to (org-fold-core--property-symbol-get-create spec) spec)
(put-text-property from to 'isearch-open-invisible #'org-fold-core--isearch-show)
(put-text-property from to 'isearch-open-invisible-temporary #'org-fold-core--isearch-show-temporary)
(when (memql 'grab-invisible org-fold-core--optimise-for-huge-buffers)
;; If the SPEC has highest priority, assign it directly
;; to 'invisible property as well. This is done to speed
;; up Emacs redisplay on huge (Mbs) folded regions where
;; we don't even want Emacs to spend time cycling over
;; `char-property-alias-alist'.
(when (eq spec (caar org-fold-core--specs)) (put-text-property from to 'invisible spec)))))
(if (not spec)
(mapc (lambda (spec) (org-fold-core-region from to nil spec)) (org-fold-core-folding-spec-list))
(when (and (memql 'grab-invisible org-fold-core--optimise-for-huge-buffers)
(eq org-fold-core-style 'text-properties))
(when (eq spec (caar org-fold-core--specs))
(let ((pos from))
(while (< pos to)
(if (eq spec (get-text-property pos 'invisible))
(let ((next (org-fold-core-next-folding-state-change spec pos to)))
(remove-text-properties pos next '(invisible t))
(setq pos next))
(setq pos (next-single-char-property-change pos 'invisible nil to)))))))
(when (eq org-fold-core-style 'text-properties)
(remove-text-properties from to (list (org-fold-core--property-symbol-get-create spec) nil)))))))))