From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Magnus Henoch Newsgroups: gmane.emacs.help Subject: Re: calendar/diary <-> phone? Date: Tue, 25 Dec 2007 13:50:52 +0100 Message-ID: <87sl1rvsyb.fsf@freemail.hu> References: <25e821a2-913f-44a0-b004-cf5f433d3015@b40g2000prf.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1198587310 13998 80.91.229.12 (25 Dec 2007 12:55:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Dec 2007 12:55:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 25 13:55:24 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J79Ja-0005ZA-BM for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Dec 2007 13:55:22 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J79JF-0002q7-Ot for geh-help-gnu-emacs@m.gmane.org; Tue, 25 Dec 2007 07:55:01 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J79Iy-0002pf-Sx for help-gnu-emacs@gnu.org; Tue, 25 Dec 2007 07:54:44 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J79It-0002p7-T1 for help-gnu-emacs@gnu.org; Tue, 25 Dec 2007 07:54:44 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J79It-0002p4-NF for help-gnu-emacs@gnu.org; Tue, 25 Dec 2007 07:54:39 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1J79It-0003Xq-6A for help-gnu-emacs@gnu.org; Tue, 25 Dec 2007 07:54:39 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1J79HY-0005dB-BI for help-gnu-emacs@gnu.org; Tue, 25 Dec 2007 12:53:16 +0000 Original-Received: from etthundrat.olf.sgsnet.se ([193.11.222.85]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Dec 2007 12:53:16 +0000 Original-Received: from mange by etthundrat.olf.sgsnet.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 25 Dec 2007 12:53:16 +0000 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 198 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: etthundrat.olf.sgsnet.se Mail-Copies-To: never Jabber-Id: legoscia@jabber.cd.chalmers.se User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (berkeley-unix) Cancel-Lock: sha1:K3UUKPmvWs4bqUrz0egudrIx1m4= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50325 Archived-At: --=-=-= knubee writes: > How do people synchronize their emacs calendar/diary entries with the > calendars on their phones? I use Gnokii along with the attached elisp hack. Magnus --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=gnokii-diary.el Content-Transfer-Encoding: quoted-printable (require 'icalendar) (defun gnokii-diary-fetch () "Fetch diary entries from phone." (interactive) ;; vcalendar files have CRLF (let ((coding-system-for-read 'utf-8-dos)) (set-process-sentinel (start-process "gnokii-diary"=20 (generate-new-buffer-name "gnokii-diary") "gnokii" "--getcalendarnote" "1" "end" "-v") 'gnokii-diary-fetch-done))) (defun gnokii-diary-send () "Send diary entries to phone." (interactive) ;; vcalendar files have CRLF (let ((coding-system-for-read 'utf-8-dos)) (set-process-sentinel (start-process "gnokii-diary"=20 (generate-new-buffer-name "gnokii-diary") "gnokii" "--getcalendarnote" "1" "end" "-v") 'gnokii-diary-do-send))) (defun gnokii-diary-fetch-done (process string) (let ((entries (with-current-buffer (process-buffer process) (gnokii-diary-parse-vcalendar)))) (dolist (entry entries) (destructuring-bind (year month day summary) entry ;; Only use the entry if it happens today or later. (when (time-less-p (current-time) (encode-time 0 0 24 day month year)) (let ((diary-entry=20 (format "%s %s" (calendar-date-string (list month day year) t t) summary))) (with-temp-buffer (insert-file-contents (substitute-in-file-name diary-file)) (goto-char (point-min)) (unless (search-forward diary-entry nil t) (when (y-or-n-p (format "Insert \"%s\" into diary? " diary-entry)) (make-diary-entry diary-entry)))))))) (message "%d calendar notes read from phone" (length entries)))) (defun gnokii-diary-parse-vcalendar () "Parse all vcalendar events in current buffer. Return a list of entries, each being (YEAR MONTH DAY SUMMARY)." (goto-char (point-min)) (let (entries) (while (search-forward "BEGIN:VEVENT" nil t) (let ((bound (save-excursion=20 (search-forward "END:VEVENT") (point)))) (let* ((summary (save-excursion (search-forward-regexp "^SUMMARY:\\(\\(\n \\|[^\n]\\)+\\)$" bound) (gnokii-decode-ical-string (match-string 1)))) (date-string (save-excursion (and (search-forward-regexp "^DTSTART:\\([0-9]*T[0-9]*\\)" bound t) (match-string 1))))) (when date-string (let ( ;; date is in format "YYYYMMDDTHHMMSS". If AALARM is ;; present, it is the same as DTSTART, just meaning ;; that an alarm was set. (year (string-to-number (substring date-string 0 4))) (month (string-to-number (substring date-string 4 6))) (day (string-to-number (substring date-string 6 8)))) (push (list year month day (gnokii-simplify-whitespace summary)) ent= ries)))))) (nreverse entries))) (defvar gnokii-diary-widget nil) (defun gnokii-diary-do-send (process string) (let* (;; (phone-entries (with-current-buffer (process-buffer process) ;; (gnokii-diary-parse-vcalendar))) (calendar-today (destructuring-bind (seconds minutes hour day month year down dst zone) (decode-time) (list month day year))) (diary-entries (diary-list-entries calendar-today 90 t))) ;;(message "phone: %S\ndiary: %S" phone-entries diary-entries) ;;(unless (y-or-n-p (format "Read %d entries from phone and %d entries = from diary. Proceed? " ;; (length phone-entries) (length diary-entries))) ;;(error "Cancelled")) (with-current-buffer (get-buffer-create "gnokii-calendar") (erase-buffer) (fundamental-mode) (set (make-local-variable 'gnokii-diary-widget) (widget-create '(repeat :tag "Calendar entries" (list :tag "Entry" (list :tag "Date" (integer :tag "Month") (integer :tag "Day") (integer :tag "Year")) (text :tag "Text") (choice (const :tag "No alarm" nil) (list :tag "Alarm" (integer :tag "Hour") (integer :tag "Minute"))))) :value (mapcar (lambda (entry) (destructuring-bind ((month day year) summary &rest ignored) entry (list (list month day year) (gnokii-simplify-whitespace summary) nil))) diary-entries))) (widget-insert "\n") (widget-create 'push-button :notify 'gnokii-diary-really-do-send "Sen= d to phone") (widget-setup) (widget-minor-mode 1) (switch-to-buffer (current-buffer)) (goto-char (point-min))))) (defun gnokii-diary-really-do-send (&rest ignore) (let ((file-name (make-temp-file "gnokii-diary")) (entries (widget-value gnokii-diary-widget))) (with-temp-buffer (insert "BEGIN:VCALENDAR VERSION:1.0 ") (dolist (entry entries) (destructuring-bind ((month day year) summary (&optional hour minute)) ent= ry (setq summary (gnokii-simplify-whitespace summary)) (unless (or ;;(member (list year month day summary) phone-entries) (time-less-p (encode-time 0 0 24 day month year) (current-time))) (insert "BEGIN:VEVENT CATEGORIES:REMINDER SUMMARY:" (gnokii-encode-ical-string summary) "\n") (let* ((alarm (or hour minute)) ;; if there is no alarm, fake the event starting at 09:00 (hour (or hour 9)) (minute (or hour 0)) (second 0) (time-string (format "%04d%02d%02dT%02d%02d%02d" year month day hour m= inute second))) (insert "DTSTART:" time-string "\n") (when alarm (insert "AALARM:" time-string "\n"))) (insert "END:VEVENT\n")))) (insert "END:VCALENDAR\n") (write-region (point-min) (point-max) file-name) (message "Sending calendar entries...") (unless (equal (call-process "gnokii" nil "*gnokii-diary*" nil "--wri= tecalendarnote" file-name "1" "end") 0) (error "Sending calendar entries failed")) (message "Sending calendar entries...done")))) (defun gnokii-simplify-whitespace (s) (replace-regexp-in-string "^[ \t]+\\|[ \t]+$" "" s)) (defun gnokii-encode-ical-string (s) (dolist (replace '(("\\\\" . "\\\\") (";" . "\\\\;") ("," . "\\\\,") ("\n" . "\\\\n")) s) (setf s (replace-regexp-in-string (car replace) (cdr replace) s)))) (defun gnokii-decode-ical-string (s) (dolist (replace '(("\n " . "") ("\\\\n" . "\n") ("\\\\N" . "\n") ("\\\\;" . ";") ("\\\\," . ",") ("\\\\\\\\" . "\\\\")) s) (setf s (replace-regexp-in-string (car replace) (cdr replace) s)))) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs --=-=-=--