summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-07-01 14:23:41 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-07-01 14:23:41 +0200
commit4f372457f2655077aa9a58b0f9bcf4232f7d7529 (patch)
tree423647bb4e87e02b13301f4f6ecb6f480bd117e0
parent79f29b490ea9424cb5a9a1789b7fbdba0cd9b4d8 (diff)
downloadorg-mode-4f372457f2655077aa9a58b0f9bcf4232f7d7529.tar.gz
Fix `org-check-before-invisible-edit', part 2
* lisp/org.el (org-check-before-invisible-edit): Fix error before first headline. Handle nested overlays.
-rw-r--r--lisp/org.el30
1 files changed, 18 insertions, 12 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 3a06da8..916f54b 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