diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c5033..3dbbb5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/org-roam.el b/org-roam.el index 9b32d20..8eb399b 100644 --- a/org-roam.el +++ b/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