Function: org-fold-check-before-invisible-edit
org-fold-check-before-invisible-edit is a byte-compiled function
defined in org-fold.el.gz.
Signature
(org-fold-check-before-invisible-edit KIND)
Documentation
Check if editing KIND is dangerous with invisible text around.
The detailed reaction depends on the user option
org-fold-catch-invisible-edits.
Aliases
org-check-before-invisible-edit (obsolete since 9.6)
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-fold.el.gz
;; Catching user edits inside invisible text
(defun org-fold-check-before-invisible-edit (kind)
"Check if editing KIND is dangerous with invisible text around.
The detailed reaction depends on the user option
`org-fold-catch-invisible-edits'."
;; First, try to get out of here as quickly as possible, to reduce overhead
(when (and org-fold-catch-invisible-edits
(or (not (boundp 'visible-mode)) (not visible-mode))
(or (org-invisible-p)
(org-invisible-p (max (point-min) (1- (point))))))
;; OK, we need to take a closer look. Only consider invisibility
;; caused by folding of headlines, drawers, and blocks. Edits
;; inside links will be handled by font-lock.
(let* ((invisible-at-point (org-fold-folded-p (point) '(headline drawer block)))
(invisible-before-point
(and (not (bobp))
(org-fold-folded-p (1- (point)) '(headline drawer block))))
(border-and-ok-direction
(or
;; Check if we are acting predictably before invisible
;; text.
(and invisible-at-point (not invisible-before-point)
(memq kind '(insert delete-backward)))
;; Check if we are acting predictably after invisible text
;; This works not well, and I have turned it off. It seems
;; better to always show and stop after invisible text.
;; (and (not invisible-at-point) invisible-before-point
;; (memq kind '(insert delete)))
)))
(when (or invisible-at-point invisible-before-point)
(when (eq org-fold-catch-invisible-edits 'error)
(user-error "Editing in invisible areas is prohibited, make them visible first"))
(if (and org-custom-properties-overlays
(y-or-n-p "Display invisible properties in this buffer? "))
(org-toggle-custom-properties-visibility)
;; Make the area visible
(save-excursion
(org-fold-show-set-visibility 'local))
(when invisible-before-point
(org-with-point-at (1- (point)) (org-fold-show-set-visibility 'local)))
(cond
((eq org-fold-catch-invisible-edits 'show)
;; That's it, we do the edit after showing
(message
"Unfolding invisible region around point before editing")
(sit-for 1))
((and (eq org-fold-catch-invisible-edits 'smart)
border-and-ok-direction)
(message "Unfolding invisible region around point before editing"))
(t
;; Don't do the edit, make the user repeat it in full visibility
(user-error "Edit in invisible region aborted, repeat to confirm with text visible"))))))))