(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:
Jethro Kuan
2020-08-25 17:09:10 +08:00
committed by GitHub
parent 2cd993e0a5
commit 0a64a5def4
2 changed files with 19 additions and 2 deletions

View File

@ -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. - [#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` - [#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 - [#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]] - [#910](https://github.com/org-roam/org-roam/pull/910) Support fuzzy links of the form [[Title]], [[*Headline]] and [[Title*Headline]]
### Bugfixes ### Bugfixes

View File

@ -1119,6 +1119,11 @@ This function hooks into `org-open-at-point' via
nil))))) nil)))))
;;; Completion at point ;;; 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 (defconst org-roam-fuzzy-link-regexp
(rx (seq "[[" (rx (seq "[["
(group (group
@ -1126,7 +1131,8 @@ This function hooks into `org-open-at-point' via
(or (not (any "[]\\")) (or (not (any "[]\\"))
(and "\\" (zero-or-more "\\\\") (any "[]")) (and "\\" (zero-or-more "\\\\") (any "[]"))
(and (one-or-more "\\") (not (any "[]")))))) (and (one-or-more "\\") (not (any "[]"))))))
"]]"))) "]]"))
"Regexp identifying a bracketed Org fuzzy link.")
(defun org-roam-complete-at-point () (defun org-roam-complete-at-point ()
"Do appropriate completion for the thing 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)) (setq collection #'org-roam--get-titles))
('headline ('headline
(setq collection #'org-roam--get-headlines) (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 (when collection
(let ((prefix (buffer-substring-no-properties start end))) (let ((prefix (buffer-substring-no-properties start end)))
(list start end (list start end