summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-03 02:20:06 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-08-03 02:20:06 +0200
commite50033d494f981604c5d0ffbe8e8cf1df992a7b2 (patch)
treea0002b6f1cdc8d02cd3cc5d620465a00191a0407
parentcfe5bc97f8b18ccbf49d0764746c7563ce8d29da (diff)
downloadorg-mode-e50033d494f981604c5d0ffbe8e8cf1df992a7b2.tar.gz
Prevent fuzzy links from matching themselves
* lisp/org.el (org-open-at-point): (org-link-search): Prevent fuzzy links from matching themselves.
-rwxr-xr-xlisp/org.el28
1 files changed, 21 insertions, 7 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 0ce4efe..1b69421 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10759,7 +10759,7 @@ link in a property drawer line."
(funcall dedicated-function
(concat path
(and option (concat "::" option))))
- (apply 'org-open-file
+ (apply #'org-open-file
path
(cond (arg)
((equal app "emacs") 'emacs)
@@ -10833,10 +10833,13 @@ link in a property drawer line."
path)
,(cond ((equal arg '(4)) 'occur)
((equal arg '(16)) 'org-occur))
- ,(org-element-property :begin link))))
+ ;; Prevent fuzzy links from matching
+ ;; themselves.
+ ,(and (equal type "fuzzy")
+ (+ 2
+ (org-element-property :begin link))))))
(condition-case nil
- (let ((org-link-search-inhibit-query t))
- (eval cmd))
+ (let ((org-link-search-inhibit-query t)) (eval cmd))
(error (progn (widen) (eval cmd)))))))
(t (browse-url-at-point))))))
;; On a footnote reference or at a footnote definition's label.
@@ -11129,9 +11132,20 @@ Search is case-insensitive and ignores white spaces."
((catch :fuzzy-match
(goto-char (point-min))
(while (re-search-forward s-multi-re nil t)
- (unless (and avoid-pos
- (>= (match-beginning 0) avoid-pos)
- (< (match-end 0) avoid-pos))
+ ;; Skip match if it contains AVOID-POS or it is included
+ ;; in a link with a description but outside the
+ ;; description.
+ (unless (or (and avoid-pos
+ (<= (match-beginning 0) avoid-pos)
+ (> (match-end 0) avoid-pos))
+ (and (save-match-data
+ (org-in-regexp org-bracket-link-regexp))
+ (match-beginning 3)
+ (or (> (match-beginning 3) (point))
+ (<= (match-end 3) (point)))
+ (org-element-lineage
+ (save-match-data (org-element-context))
+ '(link) t)))
(goto-char (match-beginning 0))
(setq type 'fuzzy)
(throw :fuzzy-match t)))