emacs-devel
[Top][All Lists]
Advanced

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

[ELPA] Proposed package: vcard


From: Eric Abrahamsen
Subject: [ELPA] Proposed package: vcard
Date: Fri, 31 Jan 2020 20:21:25 -0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi all,

I wanted to add full vCard support to EBDB, including parsing vCard
files. There are some vCard-related packages in the repos already, but
they're all tied to some other specific library (BBDB, Org, etc), and I
thought it would be good to have a library that does a sort of
vCard-to-vanilla-data-structure process, so I wrote a new one. Yes, I am
aware of the relevant XKCD comic.

I've attached the two main files in the package: one for parsing vCard
text, the other providing an extremely basic vcard-mode for looking at
*.vcf files. The missing piece is a vcard-write library, for going from
data structures back to vCard files, but I wanted to wait on that until
I've got some feedback.

vCard-to-vanilla-data-structure means that this vCard data:

BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
TITLE:Imaginary test person
EMAIL;type=INTERNET;type=WORK;type=pref:address@hidden
item1.URL;type=pref:http\://www.example/com/doe
item1.X-ABLabel:_$!<HomePage>!$_
BDAY:--0415
CATEGORIES:Work,Test group
END:VCARD

Turns into this elisp data:

((version 3.0)
 (n ("Doe" "John" "" "" "") nil)
 (fn "John Doe" nil)
 (title "Imaginary test person" nil)
 (email "address@hidden"
        ((type . "pref")
         (type . "work")
         (type . "internet")))
 (url "http://www.example/com/doe";
      ((type . "pref")
       (group . "item1")))
 (x-ablabel "HomePage"
            ((group . "item1")))
 (bday (nil nil nil 15 4 nil nil -1 nil) nil)
 (categories ("Work" "Test group") nil))

It's possible to register your own consumer functions on a per-property
and a per-card basis. I considered using structs instead of plain lists,
but vCards are essentially just bags of properties, so lists seemed
fine. The library comes with some accessors to help with eg. getting all
the properties with the same "group" parameter key.

Potential issues:

1. All date/time properties are parsed with the new iso8601 library. The
   package includes a copy of the library for use in older Emacs, but
   only loads it if the built-in library isn't found. I hope this is
   okay.
2. vCard files are line-wrapped using a CRLF-(SPC|TAB) sequence. The
   parser unwraps long lines. The RFC says:

   Note: It is possible for very simple implementations to generate
   improperly folded lines in the middle of a UTF-8 multi-octet
   sequence.  For this reason, implementations SHOULD unfold lines in
   such a way as to properly restore the original sequence.

   The dumb solution is to find *.vcf files literally, and delete all
   runs of \015\012\040 or \015\012\011. But then the file should be
   _revisited_ and decoded using whatever coding system and other
   parameters that Emacs had originally guessed heuristically for the
   file. I haven't come up with a clean way of doing that (apart from
   maybe saving a temporary intermediate file).
3. The vcard-mode font-locking doesn't work correctly. The value of
   `font-lock-defaults' is set to:

   (defvar vcard-font-lock-keywords
    '("BEGIN:VCARD" "END:VCARD"
     ("^[^;:]+" . 'vcard-property-face)
     (";\\([^=]+\\)=" (1 'vcard-parameter-key-face))
     ("=\\([^;:]+\\)[;:]" (1 'vcard-parameter-value-face))))

   But this _sometimes_ doesn't highlight the parameter keys correctly,
   and I don't know why. I've never messed with font locking before, and
   would appreciate pointers. I think it might have to do with
   overlapping matches.

All comments welcome!

Eric

Attachment: vcard-mode.el
Description: Text document

Attachment: vcard-parse.el
Description: Text document


reply via email to

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