mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat): allow enabling of link completions everywhere (#1062)
Completions for Org-roam files can be enabled everywhere by setting `org-roam-completion-everywhere` to `t`.
This commit is contained in:
@ -15,6 +15,7 @@ In this release we support fuzzy links of the form `[[Title]]`, `[[*Headline]]`
|
||||
- [#1032](https://github.com/org-roam/org-roam/pull/1032) File changes are now propagated to the database on idle timer. This prevents large wait times during file saves.
|
||||
- [#974](https://github.com/org-roam/org-roam/pull/974) Protect region targeted by `org-roam-insert`
|
||||
- [#994](https://github.com/org-roam/org-roam/pull/994) Simplify org-roam-store-link
|
||||
- [#1062](https://github.com/org-roam/org-roam/pull/1062) Variable `org-roam-completions-everywhere` allows for completions everywhere from word at point
|
||||
- [#910](https://github.com/org-roam/org-roam/pull/910) Support fuzzy links of the form [[Title]], [[*Headline]] and [[Title*Headline]]
|
||||
|
||||
### Bugfixes
|
||||
|
20
org-roam.el
20
org-roam.el
@ -1119,6 +1119,11 @@ This function hooks into `org-open-at-point' via
|
||||
nil)))))
|
||||
|
||||
;;; Completion at point
|
||||
(defcustom org-roam-completion-everywhere nil
|
||||
"If non-nil, provide completions from the current word at point."
|
||||
:group 'org-roam
|
||||
:type 'boolean)
|
||||
|
||||
(defconst org-roam-fuzzy-link-regexp
|
||||
(rx (seq "[["
|
||||
(group
|
||||
@ -1126,7 +1131,8 @@ This function hooks into `org-open-at-point' via
|
||||
(or (not (any "[]\\"))
|
||||
(and "\\" (zero-or-more "\\\\") (any "[]"))
|
||||
(and (one-or-more "\\") (not (any "[]"))))))
|
||||
"]]")))
|
||||
"]]"))
|
||||
"Regexp identifying a bracketed Org fuzzy link.")
|
||||
|
||||
(defun org-roam-complete-at-point ()
|
||||
"Do appropriate completion for the thing at point."
|
||||
@ -1160,7 +1166,17 @@ This function hooks into `org-open-at-point' via
|
||||
(setq collection #'org-roam--get-titles))
|
||||
('headline
|
||||
(setq collection #'org-roam--get-headlines)
|
||||
(setq start (+ start star-idx 1)))))))
|
||||
(setq start (+ start star-idx 1))))))
|
||||
(;; Completions everywhere
|
||||
(and org-roam-completion-everywhere
|
||||
(thing-at-point 'word))
|
||||
(let ((bounds (bounds-of-thing-at-point 'word)))
|
||||
(setq start (car bounds)
|
||||
end (cdr bounds)
|
||||
collection #'org-roam--get-titles
|
||||
exit-fn (lambda (str _status)
|
||||
(delete-char (- (length str)))
|
||||
(insert "[[" str "]]"))))))
|
||||
(when collection
|
||||
(let ((prefix (buffer-substring-no-properties start end)))
|
||||
(list start end
|
||||
|
Reference in New Issue
Block a user