Open outer link on nested links

* lisp/org.el (org-open-at-point): Open outer link on nested links.

* testing/lisp/test-org.el (test-org/open-at-point/inline-image): New
  test.

Suggested-by: Daniel Bausch <bausch@dvs.tu-darmstadt.de>
<http://permalink.gmane.org/gmane.emacs.orgmode/92796>
This commit is contained in:
Nicolas Goaziou 2014-11-20 23:35:28 +01:00
parent 0e52f02f2c
commit 40f2b885f6
2 changed files with 19 additions and 6 deletions

View File

@ -10791,8 +10791,13 @@ link in a property drawer line."
(>= (point) (match-beginning 5)))))
(org-tags-view arg (substring (match-string 5) 0 -1)))
((eq type 'link)
(let ((type (org-element-property :type context))
(path (org-link-unescape (org-element-property :path context))))
;; When link is located within the description of another
;; link (e.g., an inline image), always open the parent
;; link.
(let*((link (let ((up (org-element-property :parent context)))
(if (eq (org-element-type up) 'link) up context)))
(type (org-element-property :type link))
(path (org-link-unescape (org-element-property :path link))))
;; Switch back to REFERENCE-BUFFER needed when called in
;; a temporary buffer through `org-open-link-from-string'.
(with-current-buffer (or reference-buffer (current-buffer))
@ -10811,8 +10816,8 @@ link in a property drawer line."
;; Note : "file+emacs" and "file+sys" types are
;; hard-coded in order to escape the previous
;; limitation.
(let* ((option (org-element-property :search-option context))
(app (org-element-property :application context))
(let* ((option (org-element-property :search-option link))
(app (org-element-property :application link))
(dedicated-function
(nth 1 (assoc app org-link-protocols))))
(if dedicated-function
@ -10889,11 +10894,11 @@ link in a property drawer line."
(org-get-buffer-for-internal-link (current-buffer))))
(let ((cmd `(org-link-search
,(if (member type '("custom-id" "coderef"))
(org-element-property :raw-link context)
(org-element-property :raw-link link)
path)
,(cond ((equal arg '(4)) 'occur)
((equal arg '(16)) 'org-occur))
,(org-element-property :begin context))))
,(org-element-property :begin link))))
(condition-case nil
(let ((org-link-search-inhibit-query t))
(eval cmd))

View File

@ -1376,6 +1376,14 @@ drops support for Emacs 24.1 and 24.2."
(looking-at "\nThe Emacs Editor")
(kill-buffer))))))
(ert-deftest test-org/open-at-point/inline-image ()
"Test `org-open-at-point' on nested links."
(should
(org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
(org-open-at-point)
(prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
(kill-buffer "*info*")))))
;;; Node Properties