org-fold-check-before-invisible-edit: Be smart about editing at border

*
lisp/org-fold.el (org-fold-check-before-invisible-edit--text-properties):
Consider `border-and-ok-direction' value when deciding whether to
throw an error and reveal the fold.  Never throw an error when editing
at border without affecting the text inside.

Fixes https://orgmode.org/list/m2ilqle995.fsf@gmail.com
This commit is contained in:
Ihor Radchenko 2022-05-04 22:37:29 +08:00
parent ebbef7b30c
commit d2a459d259
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 5 deletions

View File

@ -1125,16 +1125,18 @@ The detailed reaction depends on the user option
(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)
(when (and (eq org-fold-catch-invisible-edits 'error)
(not border-and-ok-direction))
(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)))
(unless (eq org-fold-catch-invisible-edits 'error)
(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
@ -1144,6 +1146,9 @@ The detailed reaction depends on the user option
((and (eq org-fold-catch-invisible-edits 'smart)
border-and-ok-direction)
(message "Unfolding invisible region around point before editing"))
(border-and-ok-direction
;; Just continue editing.
nil)
(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"))))))))