From 4f372457f2655077aa9a58b0f9bcf4232f7d7529 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 1 Jul 2017 14:23:41 +0200 Subject: [PATCH] Fix `org-check-before-invisible-edit', part 2 * lisp/org.el (org-check-before-invisible-edit): Fix error before first headline. Handle nested overlays. --- lisp/org.el | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 3a06da81e..916f54b88 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20200,15 +20200,19 @@ The detailed reaction depends on the user option `org-catch-invisible-edits'." ;; fontification), as it cannot be toggled. (let* ((invisible-at-point (pcase (get-char-property-and-overlay (point) 'invisible) - (`(,value . ,(pred overlayp)) value))) + (`(,_ . ,(and (pred overlayp) o)) o))) + ;; Assume that point cannot land in the middle of an + ;; overlay, or between two overlays. (invisible-before-point - (and (not (bobp)) + (and (not invisible-at-point) + (not (bobp)) (pcase (get-char-property-and-overlay (1- (point)) 'invisible) - (`(,value . ,(pred overlayp)) value)))) + (`(,_ . ,(and (pred overlayp) o)) o)))) (border-and-ok-direction (or - ;; Check if we are acting predictably before invisible text - (and invisible-at-point (not invisible-before-point) + ;; Check if we are acting predictably before invisible + ;; text. + (and invisible-at-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 @@ -20216,8 +20220,7 @@ The detailed reaction depends on the user option `org-catch-invisible-edits'." ;; (and (not invisible-at-point) invisible-before-point ;; (memq kind '(insert delete))) ))) - (when (or (memq invisible-at-point '(outline org-hide-block t)) - (memq invisible-before-point '(outline org-hide-block t))) + (when (or invisible-at-point invisible-before-point) (when (eq org-catch-invisible-edits 'error) (user-error "Editing in invisible areas is prohibited, make them visible first")) (if (and org-custom-properties-overlays @@ -20229,11 +20232,14 @@ The detailed reaction depends on the user option `org-catch-invisible-edits'." (goto-char (previous-single-char-property-change (point) 'invisible))) ;; Remove whatever overlay is currently making yet-to-be - ;; edited text invisible. - (remove-overlays (point) - (org-end-of-subtree t t) - 'invisible - (or invisible-at-point invisible-before-point))) + ;; edited text invisible. Also remove nested invisibility + ;; related overlays. + (delete-overlay (or invisible-at-point invisible-before-point)) + (let ((origin (if invisible-at-point (point) (1- (point))))) + (while (pcase (get-char-property-and-overlay origin 'invisible) + (`(,_ . ,(and (pred overlayp) o)) + (delete-overlay o) + t))))) (cond ((eq org-catch-invisible-edits 'show) ;; That's it, we do the edit after showing -- 2.11.4.GIT