Prevent duplicating calls to `org-link-search'

* lisp/org.el (org-open-at-point): Do not call twice `org-link-search'
  when destination is not accessible within the current narrowed part of
  the buffer.
This commit is contained in:
Nicolas Goaziou 2015-08-04 14:32:55 +02:00
parent b4d85b47a9
commit 776449fd7d
1 changed files with 16 additions and 14 deletions

View File

@ -10827,22 +10827,24 @@ link in a property drawer line."
(if (not arg) (org-mark-ring-push) (if (not arg) (org-mark-ring-push)
(switch-to-buffer-other-window (switch-to-buffer-other-window
(org-get-buffer-for-internal-link (current-buffer)))) (org-get-buffer-for-internal-link (current-buffer))))
(let ((cmd (let ((destination
(if (equal type "radio") (org-with-wide-buffer
`(org-search-radio-target (if (equal type "radio")
,(org-element-property :path link)) (org-search-radio-target
`(org-link-search (org-element-property :path link))
,(if (member type '("custom-id" "coderef")) (org-link-search
(org-element-property :raw-link link) (if (member type '("custom-id" "coderef"))
path) (org-element-property :raw-link link)
path)
;; Prevent fuzzy links from matching ;; Prevent fuzzy links from matching
;; themselves. ;; themselves.
,(and (equal type "fuzzy") (and (equal type "fuzzy")
(+ 2 (+ 2 (org-element-property :begin link)))))
(org-element-property :begin link))))))) (point))))
(condition-case nil (unless (and (<= (point-min) destination)
(let ((org-link-search-inhibit-query t)) (eval cmd)) (>= (point-max) destination))
(error (progn (widen) (eval cmd))))))) (widen))
(goto-char destination))))
(t (browse-url-at-point)))))) (t (browse-url-at-point))))))
;; On a footnote reference or at a footnote definition's label. ;; On a footnote reference or at a footnote definition's label.
((or (eq type 'footnote-reference) ((or (eq type 'footnote-reference)