From 40f2b885f67585f500ae0bfec2c4c8c511de30b2 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 20 Nov 2014 23:35:28 +0100 Subject: [PATCH] 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 --- lisp/org.el | 17 +++++++++++------ testing/lisp/test-org.el | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index dbd2cb700..6ab13f4b3 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -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)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 6a71938f8..cee67525e 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -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:emacs#Top]]" + (org-open-at-point) + (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual")) + (kill-buffer "*info*"))))) + ;;; Node Properties -- 2.11.4.GIT