mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
fix completions
This commit is contained in:
@ -36,18 +36,24 @@
|
||||
:group 'org-roam
|
||||
:type 'boolean)
|
||||
|
||||
(defcustom org-roam-completion-everywhere nil
|
||||
"When non-nil, provide link completion matching outside of Org links.")
|
||||
|
||||
(defvar org-roam-completion-functions (list #'org-roam-complete-link-at-point
|
||||
#'org-roam-complete-everywhere)
|
||||
"List of functions to be used with `completion-at-point' for Org-roam.")
|
||||
|
||||
(defun org-roam-complete-everywhere ()
|
||||
"`completion-at-point' function for word at point.
|
||||
This is active when `org-roam-completion-everywhere' is non-nil."
|
||||
"Provides completions for links for any word at point.
|
||||
This is a `completion-at-point' function, and is active when
|
||||
`org-roam-completion-everywhere' is non-nil."
|
||||
(let ((end (point))
|
||||
(start (point))
|
||||
(exit-fn (lambda (&rest _) nil))
|
||||
collection)
|
||||
(when (thing-at-point 'word)
|
||||
(when (and org-roam-completion-everywhere
|
||||
(thing-at-point 'word)
|
||||
(not (save-match-data (org-in-regexp org-link-any-re))))
|
||||
(let ((bounds (bounds-of-thing-at-point 'word)))
|
||||
(setq start (car bounds)
|
||||
end (cdr bounds)
|
||||
|
@ -133,40 +133,7 @@ in the file."
|
||||
(completing-read "Select node: " nodes)))))
|
||||
|
||||
;;; Completion
|
||||
(defun org-roam-link-complete-at-point ()
|
||||
"Do appropriate completion for the link at point."
|
||||
(let ((end (point))
|
||||
(start (point))
|
||||
collection path)
|
||||
(when (org-in-regexp org-link-bracket-re 1)
|
||||
(setq start (match-beginning 1)
|
||||
end (match-end 1))
|
||||
(let ((context (org-element-context)))
|
||||
(pcase (org-element-lineage context '(link) t)
|
||||
(`nil nil)
|
||||
(link
|
||||
(setq link-type (org-element-property :type link)
|
||||
path (org-element-property :path link))
|
||||
(when (member link-type '("roam" "fuzzy"))
|
||||
(when (string= link-type "roam") (setq start (+ start (length "roam:"))))
|
||||
(setq collection #'org-roam-link--get-nodes))))))
|
||||
(when collection
|
||||
(let ((prefix (buffer-substring-no-properties start end)))
|
||||
(list start end
|
||||
(if (functionp collection)
|
||||
(completion-table-case-fold
|
||||
(completion-table-dynamic
|
||||
(lambda (_)
|
||||
(cl-remove-if (apply-partially #'string= prefix)
|
||||
(funcall collection))))
|
||||
(not org-roam-completion-ignore-case))
|
||||
collection)
|
||||
:exit-function
|
||||
(lambda (str &rest _)
|
||||
(delete-char (- 0 (length str)))
|
||||
(insert (concat (unless (string= link-type "roam") "roam:")
|
||||
str))
|
||||
(forward-char 2)))))))
|
||||
|
||||
|
||||
(provide 'org-roam-link)
|
||||
;;; org-roam-link.el ends here
|
||||
|
Reference in New Issue
Block a user