Function: icalendar--parse-summary-and-rest
icalendar--parse-summary-and-rest is a byte-compiled function defined
in icalendar.el.gz.
Signature
(icalendar--parse-summary-and-rest SUMMARY-AND-REST)
Documentation
Parse SUMMARY-AND-REST from a diary to fill iCalendar properties.
Returns an alist.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
(defun icalendar--parse-summary-and-rest (summary-and-rest)
"Parse SUMMARY-AND-REST from a diary to fill iCalendar properties.
Returns an alist."
(save-match-data
(if (functionp icalendar-import-format)
;; can't do anything
nil
;; split summary-and-rest
(let* ((case-fold-search nil)
(s icalendar-import-format)
(p-cla (or (string-match "%c" icalendar-import-format) -1))
(p-des (or (string-match "%d" icalendar-import-format) -1))
(p-loc (or (string-match "%l" icalendar-import-format) -1))
(p-org (or (string-match "%o" icalendar-import-format) -1))
(p-sum (or (string-match "%s" icalendar-import-format) -1))
(p-sta (or (string-match "%t" icalendar-import-format) -1))
(p-url (or (string-match "%u" icalendar-import-format) -1))
(p-uid (or (string-match "%U" icalendar-import-format) -1))
(p-list (sort (list p-cla p-des p-loc p-org p-sta p-sum p-url p-uid) '<))
(ct 0)
pos-cla pos-des pos-loc pos-org pos-sta pos-url pos-uid) ;pos-sum
(dotimes (i (length p-list))
;; Use 'ct' to keep track of current position in list
(cond ((and (>= p-cla 0) (= (nth i p-list) p-cla))
(setq ct (+ ct 1))
(setq pos-cla (* 2 ct)))
((and (>= p-des 0) (= (nth i p-list) p-des))
(setq ct (+ ct 1))
(setq pos-des (* 2 ct)))
((and (>= p-loc 0) (= (nth i p-list) p-loc))
(setq ct (+ ct 1))
(setq pos-loc (* 2 ct)))
((and (>= p-org 0) (= (nth i p-list) p-org))
(setq ct (+ ct 1))
(setq pos-org (* 2 ct)))
((and (>= p-sta 0) (= (nth i p-list) p-sta))
(setq ct (+ ct 1))
(setq pos-sta (* 2 ct)))
((and (>= p-sum 0) (= (nth i p-list) p-sum))
(setq ct (+ ct 1))
;; (setq pos-sum (* 2 ct))
)
((and (>= p-url 0) (= (nth i p-list) p-url))
(setq ct (+ ct 1))
(setq pos-url (* 2 ct)))
((and (>= p-uid 0) (= (nth i p-list) p-uid))
(setq ct (+ ct 1))
(setq pos-uid (* 2 ct)))) )
(mapc (lambda (ij)
(setq s (replace-regexp-in-string (car ij) (cadr ij) s t t)))
(list
;; summary must be first! because of %s
(list "%s"
(concat "\\(" icalendar-import-format-summary "\\)??"))
(list "%c"
(concat "\\(" icalendar-import-format-class "\\)??"))
(list "%d"
(concat "\\(" icalendar-import-format-description "\\)??"))
(list "%l"
(concat "\\(" icalendar-import-format-location "\\)??"))
(list "%o"
(concat "\\(" icalendar-import-format-organizer "\\)??"))
(list "%t"
(concat "\\(" icalendar-import-format-status "\\)??"))
(list "%u"
(concat "\\(" icalendar-import-format-url "\\)??"))
(list "%U"
(concat "\\(" icalendar-import-format-uid "\\)??"))))
;; Need the \' regexp in order to detect multi-line items
(setq s (concat "\\`"
(replace-regexp-in-string "%s" "\\([^z-a]*?\\)" s nil t)
"\\'"))
(if (string-match s summary-and-rest)
(let (cla des loc org sta url uid) ;; sum
;; (if (and pos-sum (match-beginning pos-sum))
;; (setq sum (substring summary-and-rest
;; (match-beginning pos-sum)
;; (match-end pos-sum))))
(if (and pos-cla (match-beginning pos-cla))
(setq cla (substring summary-and-rest
(match-beginning pos-cla)
(match-end pos-cla))))
(if (and pos-des (match-beginning pos-des))
(setq des (substring summary-and-rest
(match-beginning pos-des)
(match-end pos-des))))
(if (and pos-loc (match-beginning pos-loc))
(setq loc (substring summary-and-rest
(match-beginning pos-loc)
(match-end pos-loc))))
(if (and pos-org (match-beginning pos-org))
(setq org (substring summary-and-rest
(match-beginning pos-org)
(match-end pos-org))))
(if (and pos-sta (match-beginning pos-sta))
(setq sta (substring summary-and-rest
(match-beginning pos-sta)
(match-end pos-sta))))
(if (and pos-url (match-beginning pos-url))
(setq url (substring summary-and-rest
(match-beginning pos-url)
(match-end pos-url))))
(if (and pos-uid (match-beginning pos-uid))
(setq uid (substring summary-and-rest
(match-beginning pos-uid)
(match-end pos-uid))))
(list (if cla (cons 'cla cla) nil)
(if des (cons 'des des) nil)
(if loc (cons 'loc loc) nil)
(if org (cons 'org org) nil)
(if sta (cons 'sta sta) nil)
;;(if sum (cons 'sum sum) nil)
(if url (cons 'url url) nil)
(if uid (cons 'uid uid) nil))))))))