(feat): enable completions for both roam and fuzzy links (#1133)

Co-authored-by: Jethro Kuan <jethrokuan95@gmail.com>
This commit is contained in:
Noboru Ota
2020-09-26 12:05:13 +02:00
committed by GitHub
parent 176b2bf19d
commit 346bbf50a1

View File

@ -236,15 +236,17 @@ DESC is the link description."
"Do appropriate completion for the link at point." "Do appropriate completion for the link at point."
(let ((end (point)) (let ((end (point))
(start (point)) (start (point))
(exit-fn (lambda (&rest _) nil)) collection link-type)
collection)
(when (org-in-regexp org-link-bracket-re 1) (when (org-in-regexp org-link-bracket-re 1)
(setq start (+ (match-beginning 1) (length "roam:")) (setq start (match-beginning 1)
end (match-end 1)) end (match-end 1))
(let ((context (org-element-context))) (let ((context (org-element-context)))
(pcase (org-element-lineage context '(link) t) (pcase (org-element-lineage context '(link) t)
(`nil nil) (`nil nil)
(link (when (string-equal "roam" (org-element-property :type link)) (link
(setq link-type (org-element-property :type link))
(when (member link-type '("roam" "fuzzy"))
(when (string= link-type "roam") (setq start (+ start (length "roam:"))))
(pcase-let ((`(,type ,title _ ,star-idx) (pcase-let ((`(,type ,title _ ,star-idx)
(org-roam-link--split-path (org-element-property :path link)))) (org-roam-link--split-path (org-element-property :path link))))
(pcase type (pcase type
@ -268,7 +270,10 @@ DESC is the link description."
(funcall collection)))) (funcall collection))))
(not org-roam-completion-ignore-case)) (not org-roam-completion-ignore-case))
collection) collection)
:exit-function exit-fn))))) :exit-function
(lambda (str &rest _)
(delete-char (- (length str)))
(insert (concat (unless (string= link-type "roam") "roam:") str))))))))
(provide 'org-roam-link) (provide 'org-roam-link)
;;; org-roam-link.el ends here ;;; org-roam-link.el ends here