emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Improving Emacs' iCalendar support


From: Visuwesh
Subject: Re: Improving Emacs' iCalendar support
Date: Mon, 21 Oct 2024 11:52:22 +0530
User-agent: Gnus/5.13 (Gnus v5.13)

[வெள்ளி அக்டோபர் 18, 2024] Richard Lawrence wrote:

> Dear emacs-devel,
>
> Hello! I've been a happy Emacs user for almost twenty years now(!), but
> this is my first time subscribing to this list, so please help me follow
> the local conventions.
>
> I would like to start a discussion about improving Emacs' iCalendar
> support, beyond what is already available in icalendar.el. I personally
> would like to see Emacs gain a more full-fledged RFC5545 implementation
> that is primarily designed as a library for other applications to use.
>
> This is an itch that's been bugging me for a while, and so for the past
> couple of weeks I've been working on scratching it, and I now have a
> reasonable chunk of work to share: I've drafted a new implementation of
> the iCalendar grammar, and a major mode which uses this grammar to
> provide syntax highlighting. I wrote up what I've done and why here:
>
> https://recursewithless.net/emacs/icalendar-parser-and-mode.org
>
> That's a literate Org mode file containing the code and my commentary.
> If you just want to read the code itself, see:
>
> https://recursewithless.net/emacs/icalendar/icalendar-parser.el
> https://recursewithless.net/emacs/icalendar/icalendar-mode.el
>
> I could release this work as a package, but as I describe in more
> detail in the write-up, I think there's a good case that an improved
> iCalendar library belongs in Emacs' core. There are currently at least
> *three* partial iCalendar implementations in Emacs (icalendar.el,
> gnus-icalendar.el, and ox-icalendar.el), which are each focused on a
> particular major mode (diary, Gnus, and Org). I think it would be good
> to consolidate this work in one place and generalize it so that all
> three of these applications, as well as third party packages, can
> benefit.
>
> So, some questions for the list:
>
> 1) Is there interest in getting this code, and/or a future version of
> such a library, into Emacs?

I don't use much of the icalendar stuff except this one function that I
use to extract holidays from govt. supplied ical file:

    (defun vz/get-indian-holidays ()
      "Parse the icalendar file provided by the Indian government.
    This returns a list that can be used in calendar's holiday."
      (unless (file-exists-p (expand-file-name "~/lib/indianical/"))
        (make-directory (expand-file-name "~/lib/indianical/") t))
      (let* ((year (decoded-time-year (decode-time)))
             (file (expand-file-name (format "~/lib/indianical/%d" year))))
        (unless (file-exists-p file)
          (url-copy-file
           (format "http://www.india.gov.in/calendar/%d/export.ics"; year)
           file))
        (with-temp-buffer
          (require 'icalendar)
          (insert-file-contents file)
          ;; (set-buffer-file-coding-system 'unix)
          (goto-char (point-min))
          (seq-keep
           (lambda (x)
             (when-let* ((description (icalendar--get-event-property x 
'DESCRIPTION))
                         ((seq-find (lambda (h) (let (case-fold-search)
                                                    (string-match-p h 
description)))
                                      vz/indian-holidays)))
               (let ((time (icalendar--decode-isodatetime 
(icalendar--get-event-property x 'DTSTART))))
                 (list 'holiday-fixed (decoded-time-month time) 
(decoded-time-day time)
                       (string-trim-right description " +([GR])")))))
           (icalendar--all-events (icalendar--read-element nil nil))))))

It has been at least a couple years since I wrote this function so I
don't remember the hurdles I faced when I wrote it very well but it
perplexed me that there were no "public" functions that were geared
towards parsing an ical file.  In retrospect, it would have been less
confusing if these functions were "public" functions.  AFAIR, and this
very well might not be true, the structure returned
icalendar--read-element is not really documented anywhere which further
added to the confusion.

That said, this function has been rock solid ever since I wrote it.
Going by the ical files I have, it is working just fine since 2021.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]