Merge branch 'internal-link-exact-headline-match'

This commit is contained in:
Carsten Dominik 2010-08-06 15:04:59 +02:00
commit d593bae0ff
3 changed files with 55 additions and 38 deletions

View File

@ -2806,23 +2806,13 @@ text before the first headline is usually not exported, so the first such
target should be after the first headline, or in the line directly before the target should be after the first headline, or in the line directly before the
first headline.}. first headline.}.
If no dedicated target exists, Org will search for the words in the link. In If no dedicated target exists, Org will search for a headline that is exactly
the above example the search would be for @samp{my target}. Links starting the link text but may also include a TODO keyword and tags@footnote{To insert
with a star like @samp{*My Target} restrict the search to a link targeting a headline, in-buffer completion can be used. Just type a
headlines@footnote{To insert a link targeting a headline, in-buffer star followed by a few optional letters into the buffer and press
completion can be used. Just type a star followed by a few optional letters @kbd{M-@key{TAB}}. All headlines in the current buffer will be offered as
into the buffer and press @kbd{M-@key{TAB}}. All headlines in the current completions.}. In non-Org files, the search will look for the words in the
buffer will be offered as completions. @xref{Handling links}, for more link text, in the above example the search would be for @samp{my target}.
commands creating links.}. When searching, Org-mode will first try an
exact match, but then move on to more and more lenient searches. For
example, the link @samp{[[*My Targets]]} will find any of the following:
@example
** My targets
** TODO my targets are bright
** my 20 targets are
@end example
Following a link pushes a mark onto Org's own mark ring. You can Following a link pushes a mark onto Org's own mark ring. You can
return to the previous position with @kbd{C-c &}. Using this command return to the previous position with @kbd{C-c &}. Using this command

View File

@ -1289,6 +1289,7 @@ the current file."
(string-match "^\\." link)) (string-match "^\\." link))
nil) nil)
(t (t
(let ((org-link-search-inhibit-query t))
(save-excursion (save-excursion
(setq found (condition-case nil (org-link-search link) (setq found (condition-case nil (org-link-search link)
(error nil))) (error nil)))
@ -1300,7 +1301,7 @@ the current file."
(max (point-min) (max (point-min)
(1- (or (previous-single-property-change (1- (or (previous-single-property-change
(point) 'target) 0))) (point) 'target) 0)))
'target)))))))) 'target)))))))))
(when target (when target
(set-match-data md) (set-match-data md)
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))

View File

@ -1439,6 +1439,17 @@ Changing this requires a restart of Emacs to work correctly."
:group 'org-link-follow :group 'org-link-follow
:type 'integer) :type 'integer)
(defcustom org-link-search-must-match-exact-headline 'query-to-create
"Non-nil means internal links in Org files must exactly match a headline.
When nil, the link search tries to match a phrase will all words
in the search text."
:group 'org-link-follow
:type '(choice
(const :tag "Use fuzy text search" nil)
(const :tag "Match only exact headline" t)
(const :tag "Match extact headline or query to create it"
query-to-create)))
(defcustom org-link-frame-setup (defcustom org-link-frame-setup
'((vm . vm-visit-folder-other-frame) '((vm . vm-visit-folder-other-frame)
(gnus . org-gnus-no-new-news) (gnus . org-gnus-no-new-news)
@ -9306,6 +9317,7 @@ the window configuration before `org-open-at-point' was called using:
(set-window-configuration org-window-config-before-follow-link)") (set-window-configuration org-window-config-before-follow-link)")
(defvar org-link-search-inhibit-query nil) ;; dynamically scoped
(defun org-link-search (s &optional type avoid-pos) (defun org-link-search (s &optional type avoid-pos)
"Search for a link search option. "Search for a link search option.
If S is surrounded by forward slashes, it is interpreted as a If S is surrounded by forward slashes, it is interpreted as a
@ -9323,7 +9335,7 @@ in all files. If AVOID-POS is given, ignore matches near that position."
(pre nil) (post nil) (pre nil) (post nil)
words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall) words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
(cond (cond
;; First check if there are any special ;; First check if there are any special search functions
((run-hook-with-args-until-success 'org-execute-file-search-functions s)) ((run-hook-with-args-until-success 'org-execute-file-search-functions s))
;; Now try the builtin stuff ;; Now try the builtin stuff
((and (equal (string-to-char s0) ?#) ((and (equal (string-to-char s0) ?#)
@ -9368,8 +9380,28 @@ in all files. If AVOID-POS is given, ignore matches near that position."
;;((eq major-mode 'dired-mode) ;;((eq major-mode 'dired-mode)
;; (grep (concat "grep -n -e '" (match-string 1 s) "' *"))) ;; (grep (concat "grep -n -e '" (match-string 1 s) "' *")))
(t (org-do-occur (match-string 1 s))))) (t (org-do-occur (match-string 1 s)))))
((and (org-mode-p) org-link-search-must-match-exact-headline)
(and (equal (string-to-char s) ?*) (setq s (substring s 1)))
(goto-char (point-min))
(cond
((let (case-fold-search)
(re-search-forward (format org-complex-heading-regexp-format
(regexp-quote s))
nil t))
;; OK, found a match
(goto-char (match-beginning 0)))
((and (not org-link-search-inhibit-query)
(eq org-link-search-must-match-exact-headline 'query-to-create)
(y-or-n-p "No match - create this as a new heading? "))
(goto-char (point-max))
(or (bolp) (newline))
(insert "* " s "\n")
(beginning-of-line 0))
(t (t
;; A normal search strings (goto-char pos)
(error "No match"))))
(t
;; A normal search string
(when (equal (string-to-char s) ?*) (when (equal (string-to-char s) ?*)
;; Anchor on headlines, post may include tags. ;; Anchor on headlines, post may include tags.
(setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*" (setq pre "^\\*+[ \t]+\\(?:\\sw+\\)?[ \t]*"
@ -9414,13 +9446,7 @@ in all files. If AVOID-POS is given, ignore matches near that position."
) )
(goto-char (match-beginning 1)) (goto-char (match-beginning 1))
(goto-char pos) (goto-char pos)
(error "No match"))))) (error "No match"))))))
(t
;; Normal string-search
(goto-char (point-min))
(if (search-forward s nil t)
(goto-char (match-beginning 0))
(error "No match"))))
(and (org-mode-p) (org-show-context 'link-search)) (and (org-mode-p) (org-show-context 'link-search))
type)) type))