(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:
Jethro Kuan
2020-09-12 19:30:05 +08:00
committed by GitHub
parent 6d09323218
commit fac0465dd8

View File

@ -1139,9 +1139,11 @@ 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
org-roam-enable-fuzzy-links
(cond
(;; In a fuzzy link (;; In a fuzzy link
(org-roam--fuzzy-link-p) (and (org-roam--fuzzy-link-p))
(org-in-regexp org-link-any-re 1) ; org-roam--fuzzy-link-p guarantees this is true (org-in-regexp org-link-any-re 1) ; org-roam--fuzzy-link-p guarantees this is true
(setq start (match-beginning 2) (setq start (match-beginning 2)
end (match-end 2)) end (match-end 2))
@ -1161,7 +1163,7 @@ This function hooks into `org-open-at-point' via
(org-in-regexp (rx "[[]]")) (org-in-regexp (rx "[[]]"))
(setq start (+ (match-beginning 0) 2) (setq start (+ (match-beginning 0) 2)
end (+ (match-beginning 0) 2) end (+ (match-beginning 0) 2)
collection #'org-roam--get-titles)) 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