From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/82998 Path: news.gmane.org!not-for-mail From: david.goldberg6@verizon.net (Dave Goldberg) Newsgroups: gmane.emacs.gnus.general Subject: Re: Gnus window configuration with transient buffers Date: Fri, 15 Mar 2013 23:27:35 -0400 Message-ID: <848v5oyqfs.fsf@davestoy.homelinux.org> References: <5n5x2rd2v16jp5.fsf@nb-jtatarik2.xing.hh> <871ubgy7nt.fsf@randomsample.de> <5n5x2rli9owa0b.fsf@nb-jtatarik2.xing.hh> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1363404515 17779 80.91.229.3 (16 Mar 2013 03:28:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 16 Mar 2013 03:28:35 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M31264@lists.math.uh.edu Sat Mar 16 04:29:00 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UGhnn-0005Cd-Sk for ding-account@gmane.org; Sat, 16 Mar 2013 04:29:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1UGhmw-0007X7-Eo; Fri, 15 Mar 2013 22:28:06 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1UGhmt-0007Wh-T7 for ding@lists.math.uh.edu; Fri, 15 Mar 2013 22:28:03 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1UGhms-0002xH-8v for ding@lists.math.uh.edu; Fri, 15 Mar 2013 22:28:03 -0500 Original-Received: from vms173003pub.verizon.net ([206.46.173.3]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1UGhmq-0008Op-LI for ding@gnus.org; Sat, 16 Mar 2013 04:28:00 +0100 Original-Received: from davestoy.homelinux.org.verizon.net ([unknown] [173.48.214.182]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0MJQ006G9HLZL930@vms173003.mailsrvcs.net> for ding@gnus.org; Fri, 15 Mar 2013 22:27:40 -0500 (CDT) X-Face: W!bie|rYVd43O:2CkHTb*~s5}Yzx30X<@6Tq_bnP56Hp!xX4sVl4tgYRirjRcke\wfY!JJ9 i?]VIUJicJzq2\!3%7$5R%wi!R[.]Va97q In-reply-to: <5n5x2rli9owa0b.fsf@nb-jtatarik2.xing.hh> (Jan Tatarik's message of "Fri, 15 Mar 2013 23:53:08 +0100") User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (gnu/linux) X-Spam-Score: -4.3 (----) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:82998 Archived-At: I wrote a function based on functions in icalendar.el to parse a text/calen= dar handle and put it into my diary (one of two, actually, depending on whe= ther it's a repeating event) file. My code was set up to trigger upon open= ing a message, which was annoying but not so much that I bothered to do any= thing else. Recently Adam Sj=C3=B8gren posted some code to nicely format a text/calenda= r type. I now use this, and have set up an action to save the calendar eve= nt in the context menu of the text/calendar mime button. I have posted my = function before in the past. Someone, though I unfortunately don't recall = who, suggested some changes to handle timezones which I've incorporated. Here is the code in hopes it proves useful to someone else: (add-to-list 'mm-inlined-types "text/calendar") (add-to-list 'mm-automatic-display "text/calendar") (add-to-list 'mm-inline-media-tests '("text/calendar" mm-inline-text-calend= ar identity)) (require 'icalendar) (require 'boxquote) (defun mm-inline-text-calendar (handle) (let ((text "")) (with-temp-buffer (mm-insert-part handle) (save-window-excursion (setq info (mapcar (lambda (s) (mm-decode-string s "utf-8")) (format-text-calendar-for-display (icalendar--re= ad-element nil nil)))))) (let ((start (point))) (mm-insert-inline handle "\n") (mm-insert-inline handle (car info)) (mm-insert-inline handle "\n") (goto-char start) (when (search-forward "DESCRIPTION " nil t) (replace-match "" nil t) (beginning-of-line) (fill-region (point) (point-max))) (boxquote-region start (point-max))) (boxquote-title (car (cdr info))) (mm-insert-inline handle "\n"))) (defun format-text-calendar-for-display (element) "Format a text/calendar element parsed by icalendar--read-element into te= xt" (let ((fields '(LOCATION ORGANIZER DESCRIPTION)) (fieldformat "%-11s %s\n") (content "") (first-date "") (last-date "") (title "")) (dolist (event (icalendar--all-events element)) (let* ((zone-map (icalendar--convert-all-timezones element)) (dtstart-zone (icalendar--find-time-zone (icalendar--get-event= -property-attributes event 'DTSTART) zone-map)) (dtstart (icalendar--decode-isodatetime (icalendar--get-event-= property event 'DTSTART) nil dtstart-zone)) (dtend-zone (icalendar--find-time-zone (icalendar--get-event-p= roperty-attributes event 'DTEND) zone-map)) (dtend (icalendar--decode-isodatetime (icalendar--get-event-= property event 'DTEND) nil dtend-zone)) (datestring (concat (icalendar--datetime-to-iso-date dtstart "= -") " " (icalendar--datetime-to-colontime dtstart)= "-" (icalendar--datetime-to-colontime dtend)))) (when (string-equal first-date "") (setq first-date datestring)) (setq last-date datestring) (dolist (field fields) (let ((propertyvalue (mapconcat (lambda (property) (icalendar--convert-string-for-= import property) (replace-regexp-in-string "\\\\= n" "\n" (repl= ace-regexp-in-string "^MAILTO:" "" property))) (icalendar--get-event-properties = event field) " "))) (when (not (string-equal propertyvalue "")) (setq content (concat content (format fieldformat field (repl= ace-regexp-in-string "\\\\ " "" propertyvalue))))))))) (setq content (replace-regexp-in-string "\n\n$" "" content)) (setq title (if (string-equal first-date last-date) first-date (concat = first-date " ... " last-date))) (list content title))) (defun dsg-icalendar-handle-part (handle) (when (equal (car (mm-handle-type handle)) "text/calendar") (with-temp-buffer (insert (mm-get-part handle)) (if (equal (mm-handle-encoding handle) 'uuencode) (uudecode-decode-region-internal (point-min) (point-max))) (goto-char (point-min)) (decode-coding-region (point-min) (point-max) 'utf-8 nil) (let* ((e (icalendar--all-events (icalendar--read-element nil nil))) (ce (car e)) (subject (icalendar--convert-string-for-import (or (icalendar--get-event-property ce 'SUMMARY) "No Subject"))) (zone-map (icalendar--convert-all-timezones e)) (dtstart-zone (icalendar--find-time-zone (icalendar--get-event= -property-attributes ce 'DTSTART) zone-map)) (dtstart (icalendar--decode-isodatetime (icalendar--get-event-= property ce 'DTSTART) nil dtstart-zone)) (start-d (icalendar--datetime-to-diary-date dtstart)) (start-t (icalendar--datetime-to-colontime dtstart)) (repq (icalendar--get-event-property ce 'RRULE))) (if (y-or-n-p (format "Add %s for \"%s\" on %s at %s to diary? " (if repq "repeating event" "appointment") subject start-d start-t)) (icalendar-import-buffer (expand-file-name (if repq "~/repeating-diary" "~/ical-diary")) t nil)))))) (defun dsg-gnus-mime-save-calendar-event () "Save the Calendar event in the text/calendar part under point." (interactive) (gnus-article-check-buffer) (let ((data (get-text-property (point) 'gnus-data))) (when data (dsg-icalendar-handle-part data)))) (add-to-list 'gnus-mime-action-alist (cons "save calendar event" 'dsg-gnus-= mime-save-calendar-event) t) --=20 Dave Goldberg david.goldberg6@verizon.net