2
0
bodicsek 2 лет назад
Родитель
Сommit
09d132dd9b
1 измененных файлов с 90 добавлено и 0 удалено
  1. 90 0
      org-ics.el

+ 90 - 0
org-ics.el

@@ -0,0 +1,90 @@
+;;; org-ics.el --- icsorg npm package wrapper        -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023  
+
+;; Author:  <bodicsek@nerdmail.co>
+;; Keywords: calendar, extensions, processes
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package wraps the icsorg npm package.
+;; It provides an autoloaded org-ics-sync function that invokes icsorg with the configured
+;; custom variables.
+;; The result is a an org file that can be used in org-agenda.
+;; The synchronization is one way: ics -> org.
+
+;;; Code:
+
+;;=============================== custom variables ==============================
+
+(defgroup org-ics nil
+  "org-ics functions and settings."
+  :group 'external
+  :tag "org-ics"
+  :prefix "org-ics-")
+
+(defcustom org-ics-executable (executable-find "icsorg")
+  "The icsorg executable."
+  :group 'org-ics
+  :type 'string)
+
+(defcustom org-ics-ics-file nil
+  "The ics file that should be converted to org. It can be an url."
+  :group 'org-ics
+  :type 'string)
+
+(defcustom org-ics-org-file nil
+  "The org file that should be created from your `org-ics-ics-file'."
+  :group 'org-ics
+  :type 'string)
+
+(defcustom org-ics-past 7
+  "How far back in time (number of days) should we grab the calendar entries from `org-ics-ics-file'."
+  :group 'org-ics
+  :type 'natnum)
+
+(defcustom org-ics-future 14
+  "How far forward in time (number of days) should we grab the calendar entries from `org-ics-ics-file'."
+  :group 'org-ics
+  :type 'natnum)
+
+;;=============================== commands ==============================
+
+;;;###autoload
+(defun org-ics-sync ()
+  "Runs icsorg executable with the customized variables."
+  (interactive)
+  (let* ((ret (funcall 'org-ics--raw-run-icsorg
+		       "-i" org-ics-ics-file
+		       "-o" (expand-file-name org-ics-org-file)
+		       "-p" (number-to-string org-ics-past)
+		       "-f" (number-to-string org-ics-future)))
+         (exit-code (nth 0 ret))
+         (output (nth 1 ret)))
+    (if (eq exit-code 0)
+	output
+      "org-ics-sync error")))
+
+(defun org-ics--raw-run-icsorg (&rest args)
+  "Run icsorg with ARGS.
+Returns a list with the first element being the exit code and the
+second element being the output."
+  (with-temp-buffer
+    (list (apply 'call-process org-ics-executable nil (current-buffer) nil args)
+          (replace-regexp-in-string "\n$" "" (buffer-string)))))
+
+(provide 'org-ics)
+;;; org-ics.el ends here