diff --git a/lisp/org.el b/lisp/org.el index 987e8f1d3..6218a3a81 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -10708,7 +10708,8 @@ link in a property drawer line." ((memq type '(comment comment-block keyword node-property)) (cond ((org-in-regexp org-any-link-re) (org-open-link-from-string (match-string-no-properties 0))) - ((or (org-at-timestamp-p t) (org-at-date-range-p t)) + ((or (org-in-regexp org-ts-regexp-both nil t) + (org-in-regexp org-tsr-regexp-both nil t)) (org-follow-timestamp-link)) (t (user-error "No link found")))) ;; On a headline or an inlinetask, but not on a timestamp, @@ -10736,13 +10737,12 @@ link in a property drawer line." (>= (point) (org-element-property :begin value)) (<= (point) (org-element-property :end value))) (org-follow-timestamp-link)) - ;; Do nothing on white spaces after an object, unless point - ;; is right after it. - ((> (point) - (save-excursion - (goto-char (org-element-property :end context)) - (skip-chars-backward " \t") - (point))) + ;; Do nothing on white spaces after an object. + ((>= (point) + (save-excursion + (goto-char (org-element-property :end context)) + (skip-chars-backward " \t") + (point))) (user-error "No link found")) ((eq type 'timestamp) (org-follow-timestamp-link)) ;; On tags within a headline or an inlinetask. @@ -21349,13 +21349,13 @@ object (e.g., within a comment). In these case, you need to use (org-element-lineage context '(table-row table-cell) t)) (org-table-justify-field-maybe) (call-interactively #'org-table-next-row)) - ;; On a link or a timestamp, call `org-open-line' if + ;; On a link or a timestamp, call `org-open-at-point' if ;; `org-return-follows-link' allows it. Tolerate fuzzy - ;; locations, e.g., in a comment, as `org-open-line'. + ;; locations, e.g., in a comment, as `org-open-at-point'. ((and org-return-follows-link - (or (org-at-timestamp-p t) - (org-at-date-range-p t) - (org-in-regexp org-any-link-re))) + (or (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)) ;; Insert newline in heading, but preserve tags. ((and (not (bolp)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 861134d76..dc8f2fb16 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -982,6 +982,12 @@ (org-link-search-must-match-exact-headline nil)) (org-return)) (org-looking-at-p "<>"))) + (should-not + (org-test-with-temp-text "Link [[target]] <>" + (let ((org-return-follows-link t) + (org-link-search-must-match-exact-headline nil)) + (org-return)) + (org-looking-at-p "<>"))) ;; When `org-return-follows-link' is non-nil, tolerate links and ;; timestamps in comments, node properties, etc. (should @@ -990,6 +996,16 @@ (org-link-search-must-match-exact-headline nil)) (org-return)) (org-looking-at-p "<>"))) + (should-not + (org-test-with-temp-text "# Comment [[target]]\n <>" + (let ((org-return-follows-link nil)) (org-return)) + (org-looking-at-p "<>"))) + (should-not + (org-test-with-temp-text "# Comment [[target]]\n <>" + (let ((org-return-follows-link t) + (org-link-search-must-match-exact-headline nil)) + (org-return)) + (org-looking-at-p "<>"))) ;; However, do not open link when point is in a table. (should (org-test-with-temp-text "| [[target]] |\n| between |\n| <> |" @@ -1606,7 +1622,7 @@ #+BEGIN_SRC emacs-lisp \(+ 1 1) (ref:sc) #+END_SRC -\[[(sc)]]" +\[[(sc)]]" (org-open-at-point) (looking-at "(ref:sc)"))) ;; Find coderef even with alternate label format. @@ -1615,7 +1631,7 @@ #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\" \(+ 1 1) {ref:sc} #+END_SRC -\[[(sc)]]" +\[[(sc)]]" (org-open-at-point) (looking-at "{ref:sc}")))) @@ -1625,13 +1641,13 @@ "Test custom ID links specifications." (should (org-test-with-temp-text - "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]" + "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]" (org-open-at-point) (org-looking-at-p "\\* H1"))) ;; Throw an error on false positives. (should-error (org-test-with-temp-text - "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]" + "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]" (org-open-at-point) (org-looking-at-p "\\* H1")))) @@ -1705,8 +1721,7 @@ (looking-at "\\* COMMENT Test"))) ;; Correctly un-hexify fuzzy links. (should - (org-test-with-temp-text "* With space\n[[*With%20space][With space]]" - (goto-char (point-max)) + (org-test-with-temp-text "* With space\n[[*With%20space][With space]]" (org-open-at-point) (bobp))))