org-ics.el 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. ;;; org-ics.el --- icsorg npm package wrapper -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023
  3. ;; Author: <bodicsek@nerdmail.co>
  4. ;; Keywords: calendar, extensions, processes
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This package wraps the icsorg npm package.
  17. ;; It provides an autoloaded org-ics-sync function that invokes icsorg with the configured
  18. ;; custom variables.
  19. ;; The result is a an org file that can be used in org-agenda.
  20. ;; The synchronization is one way: ics -> org.
  21. ;;; Code:
  22. ;;=============================== custom variables ==============================
  23. (defgroup org-ics nil
  24. "org-ics functions and settings."
  25. :group 'external
  26. :tag "org-ics"
  27. :prefix "org-ics-")
  28. (defcustom org-ics-executable (executable-find "icsorg")
  29. "The icsorg executable."
  30. :group 'org-ics
  31. :type 'string)
  32. (defcustom org-ics-ics-file nil
  33. "The ics file that should be converted to org. It can be an url."
  34. :group 'org-ics
  35. :type 'string)
  36. (defcustom org-ics-org-file nil
  37. "The org file that should be created from your `org-ics-ics-file'."
  38. :group 'org-ics
  39. :type 'string)
  40. (defcustom org-ics-past 7
  41. "How far back in time (number of days) should we grab the calendar entries from `org-ics-ics-file'."
  42. :group 'org-ics
  43. :type 'natnum)
  44. (defcustom org-ics-future 14
  45. "How far forward in time (number of days) should we grab the calendar entries from `org-ics-ics-file'."
  46. :group 'org-ics
  47. :type 'natnum)
  48. ;;=============================== commands ==============================
  49. ;;;###autoload
  50. (defun org-ics-sync ()
  51. "Runs icsorg executable with the customized variables."
  52. (interactive)
  53. (let* ((ret (funcall 'org-ics--raw-run-icsorg
  54. "-i" org-ics-ics-file
  55. "-o" (expand-file-name org-ics-org-file)
  56. "-p" (number-to-string org-ics-past)
  57. "-f" (number-to-string org-ics-future)))
  58. (exit-code (nth 0 ret))
  59. (output (nth 1 ret)))
  60. (if (eq exit-code 0)
  61. output
  62. "org-ics-sync error")))
  63. (defun org-ics--raw-run-icsorg (&rest args)
  64. "Run icsorg with ARGS.
  65. Returns a list with the first element being the exit code and the
  66. second element being the output."
  67. (with-temp-buffer
  68. (list (apply 'call-process org-ics-executable nil (current-buffer) nil args)
  69. (replace-regexp-in-string "\n$" "" (buffer-string)))))
  70. (provide 'org-ics)
  71. ;;; org-ics.el ends here