mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-18 10:17:03 +00:00
Merge branch 'internal-link-exact-headline-match'
This commit is contained in:
commit
d593bae0ff
24
doc/org.texi
24
doc/org.texi
@ -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
|
||||
first headline.}.
|
||||
|
||||
If no dedicated target exists, Org will search for the words in the link. In
|
||||
the above example the search would be for @samp{my target}. Links starting
|
||||
with a star like @samp{*My Target} restrict the search to
|
||||
headlines@footnote{To insert a link targeting a headline, in-buffer
|
||||
completion can be used. Just type a star followed by a few optional letters
|
||||
into the buffer and press @kbd{M-@key{TAB}}. All headlines in the current
|
||||
buffer will be offered as completions. @xref{Handling links}, for more
|
||||
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
|
||||
|
||||
If no dedicated target exists, Org will search for a headline that is exactly
|
||||
the link text but may also include a TODO keyword and tags@footnote{To insert
|
||||
a link targeting a headline, in-buffer completion can be used. Just type a
|
||||
star followed by a few optional letters into the buffer and press
|
||||
@kbd{M-@key{TAB}}. All headlines in the current buffer will be offered as
|
||||
completions.}. In non-Org files, the search will look for the words in the
|
||||
link text, in the above example the search would be for @samp{my target}.
|
||||
|
||||
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
|
||||
|
@ -1289,18 +1289,19 @@ the current file."
|
||||
(string-match "^\\." link))
|
||||
nil)
|
||||
(t
|
||||
(save-excursion
|
||||
(setq found (condition-case nil (org-link-search link)
|
||||
(error nil)))
|
||||
(when (and found
|
||||
(or (org-on-heading-p)
|
||||
(not (eq found 'dedicated))))
|
||||
(or (get-text-property (point) 'target)
|
||||
(get-text-property
|
||||
(max (point-min)
|
||||
(1- (or (previous-single-property-change
|
||||
(point) 'target) 0)))
|
||||
'target))))))))
|
||||
(let ((org-link-search-inhibit-query t))
|
||||
(save-excursion
|
||||
(setq found (condition-case nil (org-link-search link)
|
||||
(error nil)))
|
||||
(when (and found
|
||||
(or (org-on-heading-p)
|
||||
(not (eq found 'dedicated))))
|
||||
(or (get-text-property (point) 'target)
|
||||
(get-text-property
|
||||
(max (point-min)
|
||||
(1- (or (previous-single-property-change
|
||||
(point) 'target) 0)))
|
||||
'target)))))))))
|
||||
(when target
|
||||
(set-match-data md)
|
||||
(goto-char (match-beginning 1))
|
||||
|
44
lisp/org.el
44
lisp/org.el
@ -1439,6 +1439,17 @@ Changing this requires a restart of Emacs to work correctly."
|
||||
:group 'org-link-follow
|
||||
: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
|
||||
'((vm . vm-visit-folder-other-frame)
|
||||
(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)")
|
||||
|
||||
(defvar org-link-search-inhibit-query nil) ;; dynamically scoped
|
||||
(defun org-link-search (s &optional type avoid-pos)
|
||||
"Search for a link search option.
|
||||
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)
|
||||
words re0 re1 re2 re3 re4_ re4 re5 re2a re2a_ reall)
|
||||
(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))
|
||||
;; Now try the builtin stuff
|
||||
((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)
|
||||
;; (grep (concat "grep -n -e '" (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
|
||||
(goto-char pos)
|
||||
(error "No match"))))
|
||||
(t
|
||||
;; A normal search strings
|
||||
;; A normal search string
|
||||
(when (equal (string-to-char s) ?*)
|
||||
;; Anchor on headlines, post may include tags.
|
||||
(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 pos)
|
||||
(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"))))
|
||||
(error "No match"))))))
|
||||
(and (org-mode-p) (org-show-context 'link-search))
|
||||
type))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user