summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-08-26 00:12:46 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-08-26 00:12:46 +0200
commite0682619dd59bec1ed145f66f0ae03f5fbeaca5c (patch)
treec57efdde44bca6d9c1400ea5b886b490a0263d3b
parentdd4a3d3b1112e99e2e11ba647c14c1e76ea27be7 (diff)
parenta6840598ed288f2141771512b846ecba9c64b0e1 (diff)
downloadorg-mode-e0682619dd59bec1ed145f66f0ae03f5fbeaca5c.tar.gz
Merge branch 'maint'
-rw-r--r--lisp/org.el18
-rw-r--r--testing/lisp/test-org.el173
2 files changed, 118 insertions, 73 deletions
diff --git a/lisp/org.el b/lisp/org.el
index e57c5c4..491649e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20615,16 +20615,14 @@ this numeric value."
(defun org-copy-visible (beg end)
"Copy the visible parts of the region."
(interactive "r")
- (let (snippets s)
- (save-excursion
- (save-restriction
- (narrow-to-region beg end)
- (setq s (goto-char (point-min)))
- (while (not (= (point) (point-max)))
- (goto-char (org-find-invisible))
- (push (buffer-substring s (point)) snippets)
- (setq s (goto-char (org-find-visible))))))
- (kill-new (apply 'concat (nreverse snippets)))))
+ (let ((result ""))
+ (while (/= beg end)
+ (when (get-char-property beg 'invisible)
+ (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)))
+ (setq beg next)))
+ (kill-new result)))
(defun org-copy-special ()
"Copy region in table or copy current subtree.
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 7ecf900..ccb0899 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2933,6 +2933,73 @@ SCHEDULED: <2017-05-06 Sat>
(org-sort-entries nil ?k)
(buffer-string)))))
+(ert-deftest test-org/file-contents ()
+ "Test `org-file-contents' specifications."
+ ;; Open files.
+ (should
+ (string= "#+BIND: variable value
+#+DESCRIPTION: l2
+#+LANGUAGE: en
+#+SELECT_TAGS: b
+#+TITLE: b
+#+PROPERTY: a 1
+" (org-file-contents (expand-file-name "setupfile3.org"
+ (concat org-test-dir "examples/")))))
+ ;; Throw error when trying to access an invalid file.
+ (should-error (org-file-contents "this-file-must-not-exist"))
+ ;; Try to access an invalid file, but do not throw an error.
+ (should
+ (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
+ ;; Open URL.
+ (should
+ (string= "foo"
+ (let ((buffer (generate-new-buffer "url-retrieve-output")))
+ (unwind-protect
+ ;; Simulate successful retrieval of a URL.
+ (cl-letf (((symbol-function 'url-retrieve-synchronously)
+ (lambda (&rest_)
+ (with-current-buffer buffer
+ (insert "HTTP/1.1 200 OK\n\nfoo"))
+ buffer)))
+ (org-file-contents "http://some-valid-url"))
+ (kill-buffer buffer)))))
+ ;; Throw error when trying to access an invalid URL.
+ (should-error
+ (let ((buffer (generate-new-buffer "url-retrieve-output")))
+ (unwind-protect
+ ;; Simulate unsuccessful retrieval of a URL.
+ (cl-letf (((symbol-function 'url-retrieve-synchronously)
+ (lambda (&rest_)
+ (with-current-buffer buffer
+ (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+ buffer)))
+ (org-file-contents "http://this-url-must-not-exist"))
+ (kill-buffer buffer))))
+ ;; Try to access an invalid URL, but do not throw an error.
+ (should-error
+ (let ((buffer (generate-new-buffer "url-retrieve-output")))
+ (unwind-protect
+ ;; Simulate unsuccessful retrieval of a URL.
+ (cl-letf (((symbol-function 'url-retrieve-synchronously)
+ (lambda (&rest_)
+ (with-current-buffer buffer
+ (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+ buffer)))
+ (org-file-contents "http://this-url-must-not-exist"))
+ (kill-buffer buffer))))
+ (should
+ (let ((buffer (generate-new-buffer "url-retrieve-output")))
+ (unwind-protect
+ ;; Simulate unsuccessful retrieval of a URL.
+ (cl-letf (((symbol-function 'url-retrieve-synchronously)
+ (lambda (&rest_)
+ (with-current-buffer buffer
+ (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
+ buffer)))
+ (org-file-contents "http://this-url-must-not-exist" :noerror))
+ (kill-buffer buffer))
+ t)))
+
;;; Navigation
@@ -6527,72 +6594,52 @@ Paragraph<point>"
(org-show-set-visibility 'minimal)
(org-invisible-p2))))
-(ert-deftest test-org/file-contents ()
- "Test `org-file-contents' specifications."
- ;; Open files.
+(defun test-org/copy-visible ()
+ "Test `org-copy-visible' specifications."
+ (should
+ (equal "Foo"
+ (org-test-with-temp-text "Foo"
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t)))))
+ ;; Skip invisible characters by text property.
+ (should
+ (equal "Foo"
+ (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t)))))
+ ;; Skip invisible characters by overlay.
+ (should
+ (equal "Foo"
+ (org-test-with-temp-text "F<hidden>oo"
+ (let ((o (make-overlay 2 10)))
+ (overlay-put o 'invisible t))
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t)))))
+ ;; Handle invisible characters at the beginning and the end of the
+ ;; buffer.
(should
- (string= "#+BIND: variable value
-#+DESCRIPTION: l2
-#+LANGUAGE: en
-#+SELECT_TAGS: b
-#+TITLE: b
-#+PROPERTY: a 1
-" (org-file-contents (expand-file-name "setupfile3.org"
- (concat org-test-dir "examples/")))))
- ;; Throw error when trying to access an invalid file.
- (should-error (org-file-contents "this-file-must-not-exist"))
- ;; Try to access an invalid file, but do not throw an error.
+ (equal "Foo"
+ (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t)))))
(should
- (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
- ;; Open URL.
- (should
- (string= "foo"
- (let ((buffer (generate-new-buffer "url-retrieve-output")))
- (unwind-protect
- ;; Simulate successful retrieval of a URL.
- (cl-letf (((symbol-function 'url-retrieve-synchronously)
- (lambda (&rest_)
- (with-current-buffer buffer
- (insert "HTTP/1.1 200 OK\n\nfoo"))
- buffer)))
- (org-file-contents "http://some-valid-url"))
- (kill-buffer buffer)))))
- ;; Throw error when trying to access an invalid URL.
- (should-error
- (let ((buffer (generate-new-buffer "url-retrieve-output")))
- (unwind-protect
- ;; Simulate unsuccessful retrieval of a URL.
- (cl-letf (((symbol-function 'url-retrieve-synchronously)
- (lambda (&rest_)
- (with-current-buffer buffer
- (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
- buffer)))
- (org-file-contents "http://this-url-must-not-exist"))
- (kill-buffer buffer))))
- ;; Try to access an invalid URL, but do not throw an error.
- (should-error
- (let ((buffer (generate-new-buffer "url-retrieve-output")))
- (unwind-protect
- ;; Simulate unsuccessful retrieval of a URL.
- (cl-letf (((symbol-function 'url-retrieve-synchronously)
- (lambda (&rest_)
- (with-current-buffer buffer
- (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
- buffer)))
- (org-file-contents "http://this-url-must-not-exist"))
- (kill-buffer buffer))))
+ (equal "Foo"
+ (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t)))))
+ ;; Handle multiple visible parts.
(should
- (let ((buffer (generate-new-buffer "url-retrieve-output")))
- (unwind-protect
- ;; Simulate unsuccessful retrieval of a URL.
- (cl-letf (((symbol-function 'url-retrieve-synchronously)
- (lambda (&rest_)
- (with-current-buffer buffer
- (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
- buffer)))
- (org-file-contents "http://this-url-must-not-exist" :noerror))
- (kill-buffer buffer))
- t)))
+ (equal "abc"
+ (org-test-with-temp-text
+ #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
+ (let ((kill-ring nil))
+ (org-copy-visible (point-min) (point-max))
+ (current-kill 0 t))))))
(provide 'test-org)