Browse Source

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'.
Kyle Meyer 3 years ago
parent
commit
57362f7414
2 changed files with 12 additions and 1 deletions
  1. 1 1
      lisp/org.el
  2. 11 0
      testing/lisp/test-org.el

+ 1 - 1
lisp/org.el

@@ -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)))

+ 11 - 0
testing/lisp/test-org.el

@@ -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)))))))