Fix `org-check-before-invisible-edit' before first headline

* lisp/org.el (org-check-before-invisible-edit): Fix "Before first
  heading" error.

Invisible characters can come from overlays and text properties.  The
current implementation tries to remove outline overlays, even though
it may be something else.

Reported-by: John Kitchin <jkitchin@andrew.cmu.edu>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00365.html>
This commit is contained in:
Nicolas Goaziou 2017-06-29 16:29:20 +02:00
parent 582fc12d0e
commit f409c13be1
1 changed files with 18 additions and 7 deletions

View File

@ -20195,10 +20195,16 @@ The detailed reaction depends on the user option `org-catch-invisible-edits'."
(or (not (boundp 'visible-mode)) (not visible-mode))
(or (get-char-property (point) 'invisible)
(get-char-property (max (point-min) (1- (point))) 'invisible)))
;; OK, we need to take a closer look
(let* ((invisible-at-point (get-char-property (point) 'invisible))
(invisible-before-point (unless (bobp) (get-char-property
(1- (point)) 'invisible)))
;; OK, we need to take a closer look. Do not consider
;; invisibility obtained through text properties (e.g., link
;; fontification), as it cannot be toggled.
(let* ((invisible-at-point
(pcase (get-char-property-and-overlay (point) 'invisible)
(`(,value . ,(pred overlayp)) value)))
(invisible-before-point
(and (not (bobp))
(pcase (get-char-property-and-overlay (1- (point)) 'invisible)
(`(,value . ,(pred overlayp)) value))))
(border-and-ok-direction
(or
;; Check if we are acting predictably before invisible text
@ -20220,9 +20226,14 @@ The detailed reaction depends on the user option `org-catch-invisible-edits'."
;; Make the area visible
(save-excursion
(when invisible-before-point
(goto-char (previous-single-char-property-change
(point) 'invisible)))
(outline-show-subtree))
(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)))
(cond
((eq org-catch-invisible-edits 'show)
;; That's it, we do the edit after showing