From fe466ab2aeeb4201179be88ac58a997473214aad Mon Sep 17 00:00:00 2001 From: stardiviner Date: Tue, 28 Dec 2021 22:14:13 +0800 Subject: [PATCH] Add org-mode mailto: link type :complete supporting --- org-contacts.el | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/org-contacts.el b/org-contacts.el index b06e39f..d452118 100644 --- a/org-contacts.el +++ b/org-contacts.el @@ -1318,7 +1318,7 @@ Each element has the form (NAME . (FILE . POSITION))." ;;;###autoload (defun org-contacts-link-complete (&optional _arg) "Create a org-contacts link using completion." - (let ((name (completing-read "org-contact Name: " + (let ((name (completing-read "org-contacts NAME: " (mapcar (lambda (plist) (plist-get plist :name)) (org-contacts--all-contacts))))) @@ -1331,6 +1331,32 @@ Each element has the form (NAME . (FILE . POSITION))." '(:background "sky blue" :overline t :slant 'italic)) (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) ;;; org-contacts.el ends here