diff --git a/lisp/org.el b/lisp/org.el index 010a59b8d..075c8f32f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20525,7 +20525,14 @@ object (e.g., within a comment). In these case, you need to use ;; `org-return-follows-link' allows it. Tolerate fuzzy ;; locations, e.g., in a comment, as `org-open-at-point'. ((and org-return-follows-link - (or (org-in-regexp org-ts-regexp-both nil t) + (or (and (eq 'link (org-element-type context)) + ;; Ensure point is not on the white spaces after + ;; the link. + (let ((origin (point))) + (org-with-point-at (org-element-property :end context) + (skip-chars-backward " \t") + (> (point) origin)))) + (org-in-regexp org-ts-regexp-both nil t) (org-in-regexp org-tsr-regexp-both nil t) (org-in-regexp org-any-link-re nil t))) (call-interactively #'org-open-at-point)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 5ab35f7de..fe2111392 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1127,6 +1127,21 @@ (org-link-search-must-match-exact-headline nil)) (org-return)) (looking-at-p "<>"))) + ;; `org-return-follows-link' handle multi-line lines. + (should + (org-test-with-temp-text + "[[target][This is a very\n long description]]\n <>" + (let ((org-return-follows-link t) + (org-link-search-must-match-exact-headline nil)) + (org-return)) + (looking-at-p "<>"))) + (should-not + (org-test-with-temp-text + "[[target][This is a very\n long description]]\n <>" + (let ((org-return-follows-link t) + (org-link-search-must-match-exact-headline nil)) + (org-return)) + (looking-at-p "<>"))) ;; However, do not open link when point is in a table. (should (org-test-with-temp-text "| [[target]] |\n| between |\n| <> |"