Skip to content

Instantly share code, notes, and snippets.

@kanru
Created January 22, 2015 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanru/26fda6f3de6e82df3015 to your computer and use it in GitHub Desktop.
Save kanru/26fda6f3de6e82df3015 to your computer and use it in GitHub Desktop.
Sync icalendar to diary file
;;; diary-sync-ical.el --- Sync iCalendar to diary -*- lexical-binding: t; -*-
;; Copyright (C) 2015 Kan-Ru Chen (陳侃如)
;; Author: Kan-Ru Chen (陳侃如) <kanru@kanru.info>
;; Keywords:
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'cl-lib)
(require 'icalendar)
(require 'url)
(defvar diary-sync-ical-url "")
(defvar diary-sync-ical-dst "")
(defun diary-sync-ical--save-ical ()
(set-buffer-multibyte t)
(set-buffer-file-coding-system 'utf-8)
(goto-char (point-min))
(save-excursion
(recode-region (point-min) (point-max) 'utf-8-dos 'utf-8-unix))
(unless (icalendar-import-buffer
(expand-file-name diary-sync-ical-dst) t nil)
(warn "Unable to import icalendar. See *icalendar-errors* for details.")))
(defun diary-sync-ical (&optional sync)
(interactive)
(with-temp-file (expand-file-name diary-sync-ical-dst)
(erase-buffer))
(if sync
(with-current-buffer
(url-retrieve-synchronously diary-sync-ical-url)
(diary-sync-ical--save-ical))
(url-retrieve diary-sync-ical-url
(lambda (status &rest args)
(when (plist-get status :error)
(cl-destructuring-bind (error-symbol . data)
(plist-get status :error)
(signal error-symbol data)))
(diary-sync-ical--save-ical)))))
(provide 'diary-sync-ical)
;;; diary-sync-ical.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment