Refuse to follow link right after the link

* lisp/org.el (org-open-at-point):
(org-return): Refuse to follow link right after the link.

* testing/lisp/test-org.el (test-org/return): Add tests.
(test-org/coderef):
(test-org/custom-id):
(test-org/fuzzy-links): Update tests.

Reported-by: "Stefan-W. Hahn" <stefan.hahn@s-hahn.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/102054>
This commit is contained in:
Nicolas Goaziou 2015-10-31 23:32:47 +01:00
parent ddd58ff99a
commit 21ba5f510e
2 changed files with 34 additions and 19 deletions

View File

@ -10707,7 +10707,8 @@ link in a property drawer line."
((memq type '(comment comment-block keyword node-property)) ((memq type '(comment comment-block keyword node-property))
(cond ((org-in-regexp org-any-link-re) (cond ((org-in-regexp org-any-link-re)
(org-open-link-from-string (match-string-no-properties 0))) (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)) (org-follow-timestamp-link))
(t (user-error "No link found")))) (t (user-error "No link found"))))
;; On a headline or an inlinetask, but not on a timestamp, ;; On a headline or an inlinetask, but not on a timestamp,
@ -10735,9 +10736,8 @@ link in a property drawer line."
(>= (point) (org-element-property :begin value)) (>= (point) (org-element-property :begin value))
(<= (point) (org-element-property :end value))) (<= (point) (org-element-property :end value)))
(org-follow-timestamp-link)) (org-follow-timestamp-link))
;; Do nothing on white spaces after an object, unless point ;; Do nothing on white spaces after an object.
;; is right after it. ((>= (point)
((> (point)
(save-excursion (save-excursion
(goto-char (org-element-property :end context)) (goto-char (org-element-property :end context))
(skip-chars-backward " \t") (skip-chars-backward " \t")
@ -21380,13 +21380,13 @@ object (e.g., within a comment). In these case, you need to use
(org-element-lineage context '(table-row table-cell) t)) (org-element-lineage context '(table-row table-cell) t))
(org-table-justify-field-maybe) (org-table-justify-field-maybe)
(call-interactively #'org-table-next-row)) (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 ;; `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 ((and org-return-follows-link
(or (org-at-timestamp-p t) (or (org-in-regexp org-ts-regexp-both nil t)
(org-at-date-range-p t) (org-in-regexp org-tsr-regexp-both nil t)
(org-in-regexp org-any-link-re))) (org-in-regexp org-any-link-re nil t)))
(call-interactively #'org-open-at-point)) (call-interactively #'org-open-at-point))
;; Insert newline in heading, but preserve tags. ;; Insert newline in heading, but preserve tags.
((and (not (bolp)) ((and (not (bolp))

View File

@ -914,6 +914,12 @@
(org-link-search-must-match-exact-headline nil)) (org-link-search-must-match-exact-headline nil))
(org-return)) (org-return))
(org-looking-at-p "<<target>>"))) (org-looking-at-p "<<target>>")))
(should-not
(org-test-with-temp-text "Link [[target]]<point> <<target>>"
(let ((org-return-follows-link t)
(org-link-search-must-match-exact-headline nil))
(org-return))
(org-looking-at-p "<<target>>")))
;; When `org-return-follows-link' is non-nil, tolerate links and ;; When `org-return-follows-link' is non-nil, tolerate links and
;; timestamps in comments, node properties, etc. ;; timestamps in comments, node properties, etc.
(should (should
@ -922,6 +928,16 @@
(org-link-search-must-match-exact-headline nil)) (org-link-search-must-match-exact-headline nil))
(org-return)) (org-return))
(org-looking-at-p "<<target>>"))) (org-looking-at-p "<<target>>")))
(should-not
(org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
(let ((org-return-follows-link nil)) (org-return))
(org-looking-at-p "<<target>>")))
(should-not
(org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
(let ((org-return-follows-link t)
(org-link-search-must-match-exact-headline nil))
(org-return))
(org-looking-at-p "<<target>>")))
;; However, do not open link when point is in a table. ;; However, do not open link when point is in a table.
(should (should
(org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |" (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
@ -1603,7 +1619,7 @@
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
\(+ 1 1) (ref:sc) \(+ 1 1) (ref:sc)
#+END_SRC #+END_SRC
\[[(sc)]]<point>" \[[(sc)<point>]]"
(org-open-at-point) (org-open-at-point)
(looking-at "(ref:sc)"))) (looking-at "(ref:sc)")))
;; Find coderef even with alternate label format. ;; Find coderef even with alternate label format.
@ -1612,7 +1628,7 @@
#+BEGIN_SRC emacs-lisp -l \"{ref:%s}\" #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
\(+ 1 1) {ref:sc} \(+ 1 1) {ref:sc}
#+END_SRC #+END_SRC
\[[(sc)]]<point>" \[[(sc)<point>]]"
(org-open-at-point) (org-open-at-point)
(looking-at "{ref:sc}")))) (looking-at "{ref:sc}"))))
@ -1622,13 +1638,13 @@
"Test custom ID links specifications." "Test custom ID links specifications."
(should (should
(org-test-with-temp-text (org-test-with-temp-text
"* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>" "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
(org-open-at-point) (org-open-at-point)
(org-looking-at-p "\\* H1"))) (org-looking-at-p "\\* H1")))
;; Throw an error on false positives. ;; Throw an error on false positives.
(should-error (should-error
(org-test-with-temp-text (org-test-with-temp-text
"* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]<point>" "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
(org-open-at-point) (org-open-at-point)
(org-looking-at-p "\\* H1")))) (org-looking-at-p "\\* H1"))))
@ -1702,8 +1718,7 @@
(looking-at "\\* COMMENT Test"))) (looking-at "\\* COMMENT Test")))
;; Correctly un-hexify fuzzy links. ;; Correctly un-hexify fuzzy links.
(should (should
(org-test-with-temp-text "* With space\n[[*With%20space][With space]]" (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
(goto-char (point-max))
(org-open-at-point) (org-open-at-point)
(bobp)))) (bobp))))