Merge branch 'maint'

This commit is contained in:
Nicolas Goaziou 2017-06-22 18:32:38 +02:00
commit a0d1ad325d
2 changed files with 40 additions and 33 deletions

View File

@ -10618,9 +10618,10 @@ When optional argument REFERENCE-BUFFER is non-nil, it should
specify a buffer from where the link search should happen. This specify a buffer from where the link search should happen. This
is used internally by `org-open-link-from-string'. is used internally by `org-open-link-from-string'.
On top of syntactically correct links, this function will open On top of syntactically correct links, this function will also
the link at point in comments or comment blocks and the first try to open links and time-stamps in comments, example
link in a property drawer line." blocks... i.e., whenever point is on something looking like
a timestamp or a link."
(interactive "P") (interactive "P")
;; On a code block, open block's results. ;; On a code block, open block's results.
(unless (call-interactively 'org-babel-open-src-block-result) (unless (call-interactively 'org-babel-open-src-block-result)
@ -10633,28 +10634,20 @@ link in a property drawer line."
;; the closest one. ;; the closest one.
(org-element-lineage (org-element-lineage
(org-element-context) (org-element-context)
'(clock comment comment-block footnote-definition '(clock footnote-definition footnote-reference headline
footnote-reference headline inlinetask keyword link inlinetask link timestamp)
node-property timestamp)
t)) t))
(type (org-element-type context)) (type (org-element-type context))
(value (org-element-property :value context))) (value (org-element-property :value context)))
(cond (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, ;; On a headline or an inlinetask, but not on a timestamp,
;; a link, a footnote reference or on tags. ;; a link, a footnote reference or on tags.
((and (memq type '(headline inlinetask)) ((and (memq type '(headline inlinetask))
;; Not on tags. ;; Not on tags.
(let ((case-fold-search nil)) (let ((case-fold-search nil))
(save-excursion (and (org-match-line org-complex-heading-regexp)
(beginning-of-line)
(looking-at org-complex-heading-regexp))
(or (not (match-beginning 5)) (or (not (match-beginning 5))
(< (point) (match-beginning 5))))) (< (point) (match-beginning 5))))))
(let* ((data (org-offer-links-in-entry (current-buffer) (point) arg)) (let* ((data (org-offer-links-in-entry (current-buffer) (point) arg))
(links (car data)) (links (car data))
(links-end (cdr data))) (links-end (cdr data)))
@ -10665,6 +10658,26 @@ link in a property drawer line."
(org-open-at-point)) (org-open-at-point))
(require 'org-attach) (require 'org-attach)
(org-attach-reveal 'if-exists)))) (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 ;; On a clock line, make sure point is on the timestamp
;; before opening it. ;; before opening it.
((and (eq type 'clock) ((and (eq type 'clock)
@ -10752,20 +10765,6 @@ link in a property drawer line."
(widen)) (widen))
(goto-char destination)))) (goto-char destination))))
(t (browse-url-at-point)))))) (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"))))) (t (user-error "No link found")))))
(run-hook-with-args 'org-follow-link-hook))) (run-hook-with-args 'org-follow-link-hook)))

View File

@ -2421,14 +2421,18 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
;;;; Open at point ;;;; 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?" "Does `org-open-at-point' open link in a keyword line?"
(should (should
(org-test-with-temp-text (org-test-with-temp-text
"<<top>>\n#+KEYWORD: <point>[[top]]" "<<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))) (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?" "Does `org-open-at-point' open link in property drawer?"
(should (should
(org-test-with-temp-text (org-test-with-temp-text
@ -2438,11 +2442,15 @@ http://article.gmane.org/gmane.emacs.orgmode/21459/"
:END:" :END:"
(org-open-at-point) t))) (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?" "Does `org-open-at-point' open link in a commented line?"
(should (should
(org-test-with-temp-text (org-test-with-temp-text
"<<top>>\n# <point>[[top]]" "<<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))) (org-open-at-point) t)))
(ert-deftest test-org/open-at-point/inline-image () (ert-deftest test-org/open-at-point/inline-image ()