Add org-mode mailto: link type :complete supporting

This commit is contained in:
stardiviner 2021-12-28 22:14:13 +08:00
parent 81d9ed977d
commit fe466ab2ae

View file

@ -1318,7 +1318,7 @@ Each element has the form (NAME . (FILE . POSITION))."
;;;###autoload ;;;###autoload
(defun org-contacts-link-complete (&optional _arg) (defun org-contacts-link-complete (&optional _arg)
"Create a org-contacts link using completion." "Create a org-contacts link using completion."
(let ((name (completing-read "org-contact Name: " (let ((name (completing-read "org-contacts NAME: "
(mapcar (mapcar
(lambda (plist) (plist-get plist :name)) (lambda (plist) (plist-get plist :name))
(org-contacts--all-contacts))))) (org-contacts--all-contacts)))))
@ -1331,6 +1331,32 @@ Each element has the form (NAME . (FILE . POSITION))."
'(:background "sky blue" :overline t :slant 'italic)) '(:background "sky blue" :overline t :slant 'italic))
(t '(:inherit 'org-link)))) (t '(:inherit 'org-link))))
;;; org-mode link "mailto:" email completion.
(org-link-set-parameters "mailto" :complete #'org-contacts-mailto-link-completion)
(defun org-contacts-mailto-link--get-all-emails ()
"Retrieve all org-contacts EMAIL property values."
(mapcar
(lambda (contact)
(let* ((org-contacts-buffer (find-file-noselect (car org-contacts-files)))
(name (plist-get contact :name))
(position (plist-get contact :position))
(email (save-excursion
(with-current-buffer org-contacts-buffer
(goto-char position)
;; (symbol-name (org-property-or-variable-value 'EMAIL))
(org-entry-get (point) "EMAIL")))))
;; (cons name email)
email))
(org-contacts--all-contacts)))
(defun org-contacts-mailto-link-completion (&optional _arg)
"Org mode link `mailto:' completion with org-contacts emails."
(let ((email (completing-read "org-contacts EMAIL: "
(org-contacts-mailto-link--get-all-emails))))
(concat "mailto:" email)))
(provide 'org-contacts) (provide 'org-contacts)
;;; org-contacts.el ends here ;;; org-contacts.el ends here