Emacs package integrating khard, a console cardav client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

khardel-org.el 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; khardel-org.el --- Support for links to khard contact buffers in org -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2019 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; Url: https://gitlab.petton.fr/DamienCassou/khardel
  5. ;; Package-requires: ((emacs "26.1"))
  6. ;; Version: 0.2.0
  7. ;; This program is free software; you can redistribute it and/or modify
  8. ;; it under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation, either version 3 of the License, or
  10. ;; (at your option) any later version.
  11. ;; This program is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;; GNU General Public License for more details.
  15. ;; You should have received a copy of the GNU General Public License
  16. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. ;;; Commentary:
  18. ;; This file implements org links to khard contact edit buffers. A query to
  19. ;; find a khard contact by its full name is performed when a link is followed.
  20. ;;; Code:
  21. (require 'org)
  22. (require 'map)
  23. (require 'khardel)
  24. (defun khardel-org--follow-link (fullname)
  25. "Follow a khardel link specified by FULLNAME.
  26. FULLNAME is a string to match against a contact name."
  27. (let ((contact (seq-find (lambda (contact)
  28. (string= (cdr contact) fullname))
  29. (map-values (khardel--list-contacts)))))
  30. (khardel-edit-contact contact)))
  31. (defun khardel-org--link-complete (&optional _)
  32. "Complete a contact name.
  33. Return an `org-mode' link for the completed contact."
  34. (khardel-org--link (khardel-choose-contact)))
  35. (defun khardel-org--store-link ()
  36. "Store a link to a khard contact from a khard contact edit buffer."
  37. (when (eq major-mode 'khardel-edit-mode)
  38. (org-store-link-props :type "khardel"
  39. :description (cdr khardel-edit-contact)
  40. :link (khardel-org--link khardel-edit-contact))))
  41. (defun khardel-org--link (contact)
  42. "Return an `org-mode' khardel link for CONTACT."
  43. (format "khardel:%s" (cdr contact)))
  44. (org-link-set-parameters "khardel"
  45. :complete #'khardel-org--link-complete
  46. :follow #'khardel-org--follow-link
  47. :store #'khardel-org--store-link)
  48. (provide 'khardel-org)
  49. ;;; khardel-org.el ends here