summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-22 10:32:40 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-06-22 18:30:58 +0200
commit5d99560ddf4ea362394a645d3cefcc4d8cb80686 (patch)
treef46379c6c42d287fdc3e58ce63be41e33b6dea12
parent521734d51fa2695257793886cb62d16851185d63 (diff)
downloadorg-mode-5d99560ddf4ea362394a645d3cefcc4d8cb80686.tar.gz
Fix open-at-point in example blocks and diary-sexps
* lisp/org.el (org-open-at-point): Also open links in example blocks and diary-sexps. * testing/lisp/test-org.el (test-org/open-at-point/keyword): (test-org/open-at-point/property): (test-org/open-at-point/comment): Add tests. Reported-by: Dieter Faulbaum <Dieter.Faulbaum@helmholtz-berlin.de> <http://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00277.html>
-rw-r--r--lisp/org.el59
-rw-r--r--testing/lisp/test-org.el14
2 files changed, 40 insertions, 33 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 22b7dbf..1e6d009 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10780,9 +10780,10 @@ When optional argument REFERENCE-BUFFER is non-nil, it should
specify a buffer from where the link search should happen. This
is used internally by `org-open-link-from-string'.
-On top of syntactically correct links, this function will open
-the link at point in comments or comment blocks and the first
-link in a property drawer line."
+On top of syntactically correct links, this function will also
+try to open links and time-stamps in comments, example
+blocks... i.e., whenever point is on something looking like
+a timestamp or a link."
(interactive "P")
;; On a code block, open block's results.
(unless (call-interactively 'org-babel-open-src-block-result)
@@ -10795,28 +10796,20 @@ link in a property drawer line."
;; the closest one.
(org-element-lineage
(org-element-context)
- '(clock comment comment-block footnote-definition
- footnote-reference headline inlinetask keyword link
- node-property timestamp)
+ '(clock footnote-definition footnote-reference headline
+ inlinetask link timestamp)
t))
(type (org-element-type context))
(value (org-element-property :value context)))
(cond
- ((not context) (user-error "No link found"))
- ;; Exception: open timestamps and links in properties
- ;; drawers, keywords and comments.
- ((memq type '(comment comment-block keyword node-property))
- (call-interactively #'org-open-at-point-global))
;; On a headline or an inlinetask, but not on a timestamp,
;; a link, a footnote reference or on tags.
((and (memq type '(headline inlinetask))
;; Not on tags.
(let ((case-fold-search nil))
- (save-excursion
- (beginning-of-line)
- (looking-at org-complex-heading-regexp))
- (or (not (match-beginning 5))
- (< (point) (match-beginning 5)))))
+ (and (org-match-line org-complex-heading-regexp)
+ (or (not (match-beginning 5))
+ (< (point) (match-beginning 5))))))
(let* ((data (org-offer-links-in-entry (current-buffer) (point) arg))
(links (car data))
(links-end (cdr data)))
@@ -10827,6 +10820,26 @@ link in a property drawer line."
(org-open-at-point))
(require 'org-attach)
(org-attach-reveal 'if-exists))))
+ ;; On a footnote reference or at definition's label.
+ ((or (eq type 'footnote-reference)
+ (and (eq type 'footnote-definition)
+ (save-excursion
+ ;; Do not validate action when point is on the
+ ;; spaces right after the footnote label, in
+ ;; order to be on par with behaviour on links.
+ (skip-chars-forward " \t")
+ (let ((begin
+ (org-element-property :contents-begin context)))
+ (if begin (< (point) begin)
+ (= (org-element-property :post-affiliated context)
+ (line-beginning-position)))))))
+ (org-footnote-action))
+ ;; No valid context. Ignore catch-all types like `headline'.
+ ;; If point is on something looking like a link or
+ ;; a time-stamp, try opening it. It may be useful in
+ ;; comments, example blocks...
+ ((memq type '(footnote-definition headline inlinetask nil))
+ (call-interactively #'org-open-at-point-global))
;; On a clock line, make sure point is on the timestamp
;; before opening it.
((and (eq type 'clock)
@@ -10919,20 +10932,6 @@ link in a property drawer line."
(widen))
(goto-char destination))))
(t (browse-url-at-point))))))
- ;; On a footnote reference or at a footnote definition's label.
- ((or (eq type 'footnote-reference)
- (and (eq type 'footnote-definition)
- (save-excursion
- ;; Do not validate action when point is on the
- ;; spaces right after the footnote label, in
- ;; order to be on par with behaviour on links.
- (skip-chars-forward " \t")
- (let ((begin
- (org-element-property :contents-begin context)))
- (if begin (< (point) begin)
- (= (org-element-property :post-affiliated context)
- (line-beginning-position)))))))
- (org-footnote-action))
(t (user-error "No link found")))))
(run-hook-with-args 'org-follow-link-hook)))
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index ebbea9b..2c06522 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -2319,14 +2319,18 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
;;;; Open at point
-(ert-deftest test-org/open-at-point-in-keyword ()
+(ert-deftest test-org/open-at-point/keyword ()
"Does `org-open-at-point' open link in a keyword line?"
(should
(org-test-with-temp-text
"<<top>>\n#+KEYWORD: <point>[[top]]"
+ (org-open-at-point) t))
+ (should
+ (org-test-with-temp-text
+ "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
(org-open-at-point) t)))
-(ert-deftest test-org/open-at-point-in-property ()
+(ert-deftest test-org/open-at-point/property ()
"Does `org-open-at-point' open link in property drawer?"
(should
(org-test-with-temp-text
@@ -2336,11 +2340,15 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
:END:"
(org-open-at-point) t)))
-(ert-deftest test-org/open-at-point-in-comment ()
+(ert-deftest test-org/open-at-point/comment ()
"Does `org-open-at-point' open link in a commented line?"
(should
(org-test-with-temp-text
"<<top>>\n# <point>[[top]]"
+ (org-open-at-point) t))
+ (should
+ (org-test-with-temp-text
+ "* H\n<<top>>\n# <point>[[top]]"
(org-open-at-point) t)))
(ert-deftest test-org/open-at-point/inline-image ()