org-copy-visible: Respect buffer-invisibility-spec

* lisp/org.el (org-copy-visible): Decide whether text is invisible by
calling invisible-p rather than checking whether the invisible
property at point is non-nil.

Text may have a non-nil invisible property but _not_ be hidden from
the user (and thus should be copied by org-copy-visible).  For
example, the link itself is shown when org-link-descriptive is nil,
but it still has an invisible property of `org-link'.
This commit is contained in:
Kyle Meyer 2022-02-27 23:31:49 -05:00
parent f2833ff255
commit 57362f7414
2 changed files with 12 additions and 1 deletions

View File

@ -17522,7 +17522,7 @@ this numeric value."
(interactive "r")
(let ((result ""))
(while (/= beg end)
(if (get-char-property beg 'invisible)
(if (invisible-p beg)
(setq beg (next-single-char-property-change beg 'invisible nil end))
(let ((next (next-single-char-property-change beg 'invisible nil end)))
(setq result (concat result (buffer-substring beg next)))

View File

@ -8231,6 +8231,17 @@ CLOSED: %s
(equal "ab"
(org-test-with-temp-text
#("aXXb" 1 2 (invisible t) 2 3 (invisible org-link))
(let ((kill-ring nil))
(org-copy-visible (point-min) (point-max))
(current-kill 0 t)))))
;; Copies text based on what's actually visible, as defined by
;; `buffer-invisibility-spec'.
(should
(equal "aYb"
(org-test-with-temp-text
#("aXYb"
1 2 (invisible t)
2 3 (invisible org-test-copy-visible))
(let ((kill-ring nil))
(org-copy-visible (point-min) (point-max))
(current-kill 0 t)))))))