mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat): add org-roam-enable-fuzzy-links (#1097)
`org-roam-enable-fuzzy-links` controls whether to enable Org-roam's fuzzy link behaviour. This can be undesirable to some users, who would like to use [[foo]] links to reference named blocks
This commit is contained in:
65
org-roam.el
65
org-roam.el
@ -1139,29 +1139,31 @@ This function hooks into `org-open-at-point' via
|
|||||||
exit-fn (lambda (str _status)
|
exit-fn (lambda (str _status)
|
||||||
(delete-char (- (length str)))
|
(delete-char (- (length str)))
|
||||||
(insert "\"" str "\""))))
|
(insert "\"" str "\""))))
|
||||||
|
(;; Completions for fuzzy links
|
||||||
(;; In a fuzzy link
|
org-roam-enable-fuzzy-links
|
||||||
(org-roam--fuzzy-link-p)
|
(cond
|
||||||
(org-in-regexp org-link-any-re 1) ; org-roam--fuzzy-link-p guarantees this is true
|
(;; In a fuzzy link
|
||||||
(setq start (match-beginning 2)
|
(and (org-roam--fuzzy-link-p))
|
||||||
end (match-end 2))
|
(org-in-regexp org-link-any-re 1) ; org-roam--fuzzy-link-p guarantees this is true
|
||||||
(pcase-let ((`(,type ,title _ ,star-idx)
|
(setq start (match-beginning 2)
|
||||||
(org-roam--split-fuzzy-link (match-string-no-properties 2))))
|
end (match-end 2))
|
||||||
(pcase type
|
(pcase-let ((`(,type ,title _ ,star-idx)
|
||||||
('title+headline
|
(org-roam--split-fuzzy-link (match-string-no-properties 2))))
|
||||||
(when-let ((file (org-roam--get-file-from-title title t)))
|
(pcase type
|
||||||
(setq collection (apply-partially #'org-roam--get-headlines file))
|
('title+headline
|
||||||
(setq start (+ start star-idx 1))))
|
(when-let ((file (org-roam--get-file-from-title title t)))
|
||||||
('title
|
(setq collection (apply-partially #'org-roam--get-headlines file))
|
||||||
(setq collection #'org-roam--get-titles))
|
(setq start (+ start star-idx 1))))
|
||||||
('headline
|
('title
|
||||||
(setq collection #'org-roam--get-headlines)
|
(setq collection #'org-roam--get-titles))
|
||||||
(setq start (+ start star-idx 1))))))
|
('headline
|
||||||
(;; At a plain "[[|]]"
|
(setq collection #'org-roam--get-headlines)
|
||||||
(org-in-regexp (rx "[[]]"))
|
(setq start (+ start star-idx 1))))))
|
||||||
(setq start (+ (match-beginning 0) 2)
|
(;; At a plain "[[|]]"
|
||||||
end (+ (match-beginning 0) 2)
|
(org-in-regexp (rx "[[]]"))
|
||||||
collection #'org-roam--get-titles))
|
(setq start (+ (match-beginning 0) 2)
|
||||||
|
end (+ (match-beginning 0) 2)
|
||||||
|
collection #'org-roam--get-titles))))
|
||||||
(;; Completions everywhere
|
(;; Completions everywhere
|
||||||
(and org-roam-completion-everywhere
|
(and org-roam-completion-everywhere
|
||||||
(thing-at-point 'word))
|
(thing-at-point 'word))
|
||||||
@ -1184,8 +1186,17 @@ This function hooks into `org-open-at-point' via
|
|||||||
:exit-function exit-fn)))))
|
:exit-function exit-fn)))))
|
||||||
|
|
||||||
;;; Fuzzy Links
|
;;; Fuzzy Links
|
||||||
|
(defcustom org-roam-enable-fuzzy-links t
|
||||||
|
"When non-nil, replace Org's [[fuzzy link]] behaviour with Org-roam's.
|
||||||
|
|
||||||
|
Org-roam emulates Roam Research, treating [[Foo]] links as links
|
||||||
|
to files titled Foo. In addition to this behaviour, [[Foo*Bar]]
|
||||||
|
links to the headline Bar within the file titled Foo."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'boolean)
|
||||||
|
|
||||||
(defcustom org-roam-auto-replace-fuzzy-links t
|
(defcustom org-roam-auto-replace-fuzzy-links t
|
||||||
"When t, replace Org-roam's fuzzy links with file or id links whenever possible."
|
"When non-nil, replace Org-roam's fuzzy links with file or id links whenever possible."
|
||||||
:group 'org-roam
|
:group 'org-roam
|
||||||
:type 'boolean)
|
:type 'boolean)
|
||||||
|
|
||||||
@ -1351,7 +1362,8 @@ Three types of fuzzy links are supported:
|
|||||||
|
|
||||||
[[Title*Headline]]
|
[[Title*Headline]]
|
||||||
Creates or gets an ID for the corresponding headline from file with corresponding title."
|
Creates or gets an ID for the corresponding headline from file with corresponding title."
|
||||||
(when (and (bound-and-true-p org-roam-mode)
|
(when (and org-roam-enable-fuzzy-links
|
||||||
|
(bound-and-true-p org-roam-mode)
|
||||||
(org-roam--org-roam-file-p))
|
(org-roam--org-roam-file-p))
|
||||||
(when-let ((location (org-roam--get-fuzzy-link-location link)))
|
(when-let ((location (org-roam--get-fuzzy-link-location link)))
|
||||||
(pcase-let ((`(,link-type ,loc ,desc ,mkr) location))
|
(pcase-let ((`(,link-type ,loc ,desc ,mkr) location))
|
||||||
@ -1381,7 +1393,8 @@ Three types of fuzzy links are supported:
|
|||||||
|
|
||||||
(defun org-roam--replace-fuzzy-link-on-save ()
|
(defun org-roam--replace-fuzzy-link-on-save ()
|
||||||
"Hook to replace all fuzzy links on save."
|
"Hook to replace all fuzzy links on save."
|
||||||
(when org-roam-auto-replace-fuzzy-links
|
(when (and org-roam-enable-fuzzy-links
|
||||||
|
org-roam-auto-replace-fuzzy-links)
|
||||||
(org-roam-replace-all-fuzzy-links)))
|
(org-roam-replace-all-fuzzy-links)))
|
||||||
|
|
||||||
;;; Org-roam-mode
|
;;; Org-roam-mode
|
||||||
|
Reference in New Issue
Block a user