From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Kanis Newsgroups: gmane.emacs.bugs Subject: bug#8337: patches that fixes the problem in appt Date: Wed, 13 Apr 2011 10:08:32 +0200 Message-ID: <877hay7ev3.fsf@kanis.fr> References: <8739mcfr82.fsf@kanis.fr> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1302710966 2527 80.91.229.12 (13 Apr 2011 16:09:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Apr 2011 16:09:26 +0000 (UTC) To: 8337@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 13 18:09:20 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QA2d5-0004TK-Ex for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Apr 2011 18:09:20 +0200 Original-Received: from localhost ([::1]:60365 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QA2d4-0008Bg-Ql for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Apr 2011 12:09:18 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:48617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9xv1-0002wq-0v for bug-gnu-emacs@gnu.org; Wed, 13 Apr 2011 07:07:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9xus-0005k0-T1 for bug-gnu-emacs@gnu.org; Wed, 13 Apr 2011 07:07:30 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9xus-0005js-OR for bug-gnu-emacs@gnu.org; Wed, 13 Apr 2011 07:07:22 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q9xlq-0002zx-1t; Wed, 13 Apr 2011 06:58:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <8739mcfr82.fsf@kanis.fr> Resent-From: Ivan Kanis Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Apr 2011 10:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8337 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 8337-submit@debbugs.gnu.org id=B8337.130269224011475 (code B ref 8337); Wed, 13 Apr 2011 10:58:01 +0000 Original-Received: (at 8337) by debbugs.gnu.org; 13 Apr 2011 10:57:20 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q9xl7-0002z1-24 for submit@debbugs.gnu.org; Wed, 13 Apr 2011 06:57:19 -0400 Original-Received: from kanis.fr ([174.136.103.202]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q9v85-0007fF-3a for 8337@debbugs.gnu.org; Wed, 13 Apr 2011 04:08:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kanis.fr; s=alpha; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From; bh=Juivjm1pYvomJQlhqC1p9aFIFiLqmQ1wtAPDuKYxsk8=; b=hW1JPTHgCvDikobjXFoFi3xrMNCRCk982K5FnWvNK+yQHsijD5gW/yHINN4kgPVS1R4zzaadtHZfmZQLTy5NbExbrOkF8D4ufTEPRABrDoTWEn6aBorD2vAv5QSq53k+; Original-Received: from nantes.visionobjects.com ([92.103.229.106] helo=yan) by kanis.fr with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Q9v7x-0006AR-7l for 8337@debbugs.gnu.org; Wed, 13 Apr 2011 01:08:42 -0700 Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAAXNSR0IArs4c6QAAAB5QTFRF IBkXUxMTOCwoTC4qcUY8iFxQmmper31txpaJ/v/8aKZ1oAAAAcVJREFUOMt100tu2zAQAFDCXnUZ oAcIqG68LZULVLQBbwuSiffm6AIRRyeotAySJoVu2+FPpJWWC3/4NKOZocSW/yxWfnJ2+Bdwzhj7 8gleWVy7DXC2rkMNr2V/zRbghXIwthf3VbIA9Ffc71vZCSFyCEsBggtNS8ludwvfmhYA0Vn9o4DP zMWxR7+cPWzAYFzwM0ModtdmcDbDS6i/hT7L+RZof5yCXGrYe5jn2YO6BYMjgY+51tCIAqHgBLwR pwLnGuRjAKyBJkuN4yd4U92uCY1vUr2D/c5b8DuxyQwfOHUeaLqDJhnkkuGXbB56h2C1IVBdgncc bBi6feroa9B6jUDojnQPQKupbyXyeeCE1oT7Oqrt+SnfY3mkiyGA/3AmD3H5g32CcBx6hY8pRkwJ 9PpcjRGobUfprFnhAa1vepwcgMOhwG+pdSgKHFU9HAvoAH6XUl7lDUCCq5Qb6GMbVm3Aj++qDYCt wdBc/YHgOFCmS3mjDMRcSE2qY4E3Q3PVIQRQmeodNH4QEbRUFZzW+VotzwX4yTcRTySOML1qjcE5 hTirVqDHkMAP0PjAywp3d18JZtqzvr9zDYD+GaSKtE6Zlr/DLPNFmOcvBAAAAABJRU5ErkJggg== User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Mailman-Approved-At: Wed, 13 Apr 2011 06:57:15 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 13 Apr 2011 06:58:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-Mailman-Approved-At: Wed, 13 Apr 2011 12:09:16 -0400 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45790 Archived-At: --=-=-= Hello, The following patches fix the problem. It applies on emacs 23.3. I have enclosed the final appt.el. Ivan Kanis --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-remove-full-check-and-mode-line-only.patch >From c4cfef7043ff51c48834d55cf0b163fb95f3f5d5 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:32:23 +0100 Subject: [PATCH 01/14] remove full-check and mode-line-only These two variables just make the code more complex than it should be. The main interest is to have the display refresh at n mod time. Remove appt-now-displayed since it's not used anymore. --- appt.el | 23 +++++------------------ 1 files changed, 5 insertions(+), 18 deletions(-) diff --git a/appt.el b/appt.el index 4c318dc..e2b1158 100644 --- a/appt.el +++ b/appt.el @@ -217,9 +217,6 @@ Only used if `appt-display-mode-line' is non-nil.") "Time of day (mins since midnight) at which we last checked appointments. A nil value forces the diary file to be (re-)checked for appointments.") -(defvar appt-now-displayed nil - "Non-nil when we have started notifying about a appointment that is near.") - (defvar appt-display-count nil "Internal variable used to count number of consecutive reminders.") @@ -314,17 +311,7 @@ displayed in a window: (let* ((min-to-app -1) (prev-appt-mode-string appt-mode-string) (prev-appt-display-count (or appt-display-count 0)) - ;; Non-nil means do a full check for pending appointments and - ;; display in whatever ways the user has selected. When no - ;; appointment is being displayed, we always do a full check. - (full-check - (or (not appt-now-displayed) - ;; This is true every appt-display-interval minutes. - (zerop (mod prev-appt-display-count appt-display-interval)))) - ;; Non-nil means only update the interval displayed in the mode line. - (mode-line-only (unless full-check appt-now-displayed)) now cur-comp-time appt-comp-time appt-warn-time) - (when (or full-check mode-line-only) (save-excursion ;; Convert current time to minutes after midnight (12.01am = 1). (setq now (decode-time) @@ -402,10 +389,10 @@ displayed in a window: ;; appt-message-warning time. (when (and (<= min-to-app appt-warn-time) (>= min-to-app 0)) - (setq appt-now-displayed t - appt-display-count (1+ prev-appt-display-count)) - (unless mode-line-only - (appt-display-message (cadr (car appt-time-msg-list)) + (setq appt-display-count (1+ prev-appt-display-count)) + ;; This is true every appt-display-interval minutes. + (if (zerop (mod prev-appt-display-count appt-display-interval)) + (appt-display-message (cadr (car appt-time-msg-list)) min-to-app)) (when appt-display-mode-line (setq appt-mode-string @@ -426,7 +413,7 @@ displayed in a window: (force-mode-line-update t) ;; If the string now has a notification, redisplay right now. (if appt-mode-string - (sit-for 0)))))))) + (sit-for 0))))))) (defun appt-disp-window (min-to-app new-time appt-msg) "Display appointment due in MIN-TO-APP (a string) minutes. -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0002-remove-prev-appt-display-count.patch >From bacf5ac866a12b6527a6144bd53e96781b563367 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:39:43 +0100 Subject: [PATCH 02/14] remove prev-appt-display-count using only global appt-display-count should be sufficient --- appt.el | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/appt.el b/appt.el index e2b1158..8a2919e 100644 --- a/appt.el +++ b/appt.el @@ -217,7 +217,7 @@ Only used if `appt-display-mode-line' is non-nil.") "Time of day (mins since midnight) at which we last checked appointments. A nil value forces the diary file to be (re-)checked for appointments.") -(defvar appt-display-count nil +(defvar appt-display-count 0 "Internal variable used to count number of consecutive reminders.") (defvar appt-timer nil @@ -310,7 +310,6 @@ displayed in a window: (interactive "P") ; so people can force updates (let* ((min-to-app -1) (prev-appt-mode-string appt-mode-string) - (prev-appt-display-count (or appt-display-count 0)) now cur-comp-time appt-comp-time appt-warn-time) (save-excursion ;; Convert current time to minutes after midnight (12.01am = 1). @@ -389,11 +388,11 @@ displayed in a window: ;; appt-message-warning time. (when (and (<= min-to-app appt-warn-time) (>= min-to-app 0)) - (setq appt-display-count (1+ prev-appt-display-count)) ;; This is true every appt-display-interval minutes. (if (zerop (mod prev-appt-display-count appt-display-interval)) (appt-display-message (cadr (car appt-time-msg-list)) min-to-app)) + (setq appt-display-count (1+ appt-display-count)) (when appt-display-mode-line (setq appt-mode-string (concat " " (propertize @@ -404,7 +403,7 @@ displayed in a window: ;; appointment on the next cycle. (if (zerop min-to-app) (setq appt-time-msg-list (cdr appt-time-msg-list) - appt-display-count nil)))) + appt-display-count 0)))) ;; If we have changed the mode line string, redisplay all mode lines. (and appt-display-mode-line (not (string-equal appt-mode-string -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0003-plop-now-and-cur-comp-time-in-the-let-statement.patch >From 0da2c2a482b71a119326490d22184e933c19629e Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:42:52 +0100 Subject: [PATCH 03/14] plop now and cur-comp-time in the let statement --- appt.el | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/appt.el b/appt.el index 8a2919e..3f8493b 100644 --- a/appt.el +++ b/appt.el @@ -310,11 +310,11 @@ displayed in a window: (interactive "P") ; so people can force updates (let* ((min-to-app -1) (prev-appt-mode-string appt-mode-string) - now cur-comp-time appt-comp-time appt-warn-time) + ;; Convert current time to minutes after midnight (12.01am = 1). + (now (decode-time)) + (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) + appt-comp-time appt-warn-time) (save-excursion - ;; Convert current time to minutes after midnight (12.01am = 1). - (setq now (decode-time) - cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) ;; At first check in any day, update appointments to today's list. (if (or force ; eg initialize, diary save (null appt-prev-comp-time) ; first check -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0004-move-diary-update-to-its-own-function-appt-check-dia.patch >From 7353db6f568d0b32d2aaf72d58160e62a830ba25 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:53:37 +0100 Subject: [PATCH 04/14] move diary update to its own function appt-check-diary --- appt.el | 84 +++++++++++++++++++++++++++++++++------------------------------ 1 files changed, 44 insertions(+), 40 deletions(-) diff --git a/appt.el b/appt.el index 3f8493b..9531797 100644 --- a/appt.el +++ b/appt.el @@ -315,46 +315,7 @@ displayed in a window: (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) appt-comp-time appt-warn-time) (save-excursion - ;; At first check in any day, update appointments to today's list. - (if (or force ; eg initialize, diary save - (null appt-prev-comp-time) ; first check - (< cur-comp-time appt-prev-comp-time)) ; new day - (ignore-errors - (if appt-display-diary - (let ((diary-hook - (if (assoc 'appt-make-list diary-hook) - diary-hook - (cons 'appt-make-list diary-hook)))) - (diary)) - (let* ((diary-display-function 'appt-make-list) - (d-buff (find-buffer-visiting diary-file)) - (selective - (if d-buff ; diary buffer exists - (with-current-buffer d-buff - diary-selective-display))) - d-buff2) - ;; Not displaying the diary, so we can ignore - ;; diary-number-of-entries. Since appt.el only - ;; works on a daily basis, no need for more entries. - ;; FIXME why not using diary-list-entries with - ;; non-nil LIST-ONLY? - (diary 1) - ;; If the diary buffer existed before this command, - ;; restore its display state. Otherwise, kill it. - (and (setq d-buff2 (find-buffer-visiting diary-file)) - (if d-buff - (or selective - (with-current-buffer d-buff2 - (if diary-selective-display - ;; diary-show-all-entries displays - ;; the diary buffer. - (diary-unhide-everything)))) - ;; FIXME does not kill any included diary files. - ;; The real issue is that (diary) should not - ;; have the side effect of visiting all the - ;; diary files. It is not really appt.el's job to - ;; clean up this mess... - (kill-buffer d-buff2))))))) + (appt-check-diary force cur-comp-time) (setq appt-prev-comp-time cur-comp-time appt-mode-string nil appt-display-count nil) @@ -414,6 +375,49 @@ displayed in a window: (if appt-mode-string (sit-for 0))))))) +(defun appt-check-diary (force cur-comp-time) + "Update appointments to today's list." + ;; At first check in any day + (if (or force ; eg initialize, diary save + (null appt-prev-comp-time) ; first check + (< cur-comp-time appt-prev-comp-time)) ; new day + (ignore-errors + (if appt-display-diary + (let ((diary-hook + (if (assoc 'appt-make-list diary-hook) + diary-hook + (cons 'appt-make-list diary-hook)))) + (diary)) + (let* ((diary-display-function 'appt-make-list) + (d-buff (find-buffer-visiting diary-file)) + (selective + (if d-buff ; diary buffer exists + (with-current-buffer d-buff + diary-selective-display))) + d-buff2) + ;; Not displaying the diary, so we can ignore + ;; diary-number-of-entries. Since appt.el only + ;; works on a daily basis, no need for more entries. + ;; FIXME why not using diary-list-entries with + ;; non-nil LIST-ONLY? + (diary 1) + ;; If the diary buffer existed before this command, + ;; restore its display state. Otherwise, kill it. + (and (setq d-buff2 (find-buffer-visiting diary-file)) + (if d-buff + (or selective + (with-current-buffer d-buff2 + (if diary-selective-display + ;; diary-show-all-entries displays + ;; the diary buffer. + (diary-unhide-everything)))) + ;; FIXME does not kill any included diary files. + ;; The real issue is that (diary) should not + ;; have the side effect of visiting all the + ;; diary files. It is not really appt.el's job to + ;; clean up this mess... + (kill-buffer d-buff2))))))) + (defun appt-disp-window (min-to-app new-time appt-msg) "Display appointment due in MIN-TO-APP (a string) minutes. NEW-TIME is a string giving the date. Displays the appointment -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0005-appt-issue-message-is-obsolete-so-don-t-use-it-anymo.patch >From bac7910464bf27cf63c541f85f3fd3ee6cf30e38 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:56:14 +0100 Subject: [PATCH 05/14] appt-issue-message is obsolete so don't use it anymore --- appt.el | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/appt.el b/appt.el index 9531797..8cb011f 100644 --- a/appt.el +++ b/appt.el @@ -322,7 +322,7 @@ displayed in a window: ;; If there are entries in the list, and the user wants a ;; message issued, get the first time off of the list and ;; calculate the number of minutes until the appointment. - (when (and appt-issue-message appt-time-msg-list) + (when appt-time-msg-list (setq appt-comp-time (caar (car appt-time-msg-list)) appt-warn-time (or (nth 3 (car appt-time-msg-list)) appt-message-warning-time) -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0006-don-t-initialize-min-to-app-to-1-there-is-no-good-re.patch >From 8c909e82ab3dc93fc0302a92985fd633d3f0e5b2 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 18:59:24 +0100 Subject: [PATCH 06/14] don't initialize min-to-app to -1, there is no good reason --- appt.el | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/appt.el b/appt.el index 8cb011f..f6ff5c1 100644 --- a/appt.el +++ b/appt.el @@ -308,12 +308,11 @@ displayed in a window: `appt-delete-window-function' Function called to remove appointment window and buffer." (interactive "P") ; so people can force updates - (let* ((min-to-app -1) - (prev-appt-mode-string appt-mode-string) + (let* ((prev-appt-mode-string appt-mode-string) ;; Convert current time to minutes after midnight (12.01am = 1). (now (decode-time)) (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) - appt-comp-time appt-warn-time) + appt-comp-time appt-warn-time min-to-app) (save-excursion (appt-check-diary force cur-comp-time) (setq appt-prev-comp-time cur-comp-time -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0007-move-appt-prev-comp-time-to-the-bottom-of-appt-check.patch >From 5df9dfd98fce372b89bbb9f77462d93b745cee84 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 19:05:10 +0100 Subject: [PATCH 07/14] move appt-prev-comp-time to the bottom of appt-check-diary This variable is referenced only in this function so it makes sense to put it there. I have also fixed that function as it was missing a parentheses. --- appt.el | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appt.el b/appt.el index f6ff5c1..51cc5e1 100644 --- a/appt.el +++ b/appt.el @@ -315,8 +315,7 @@ displayed in a window: appt-comp-time appt-warn-time min-to-app) (save-excursion (appt-check-diary force cur-comp-time) - (setq appt-prev-comp-time cur-comp-time - appt-mode-string nil + (setq appt-mode-string nil appt-display-count nil) ;; If there are entries in the list, and the user wants a ;; message issued, get the first time off of the list and @@ -416,6 +415,7 @@ displayed in a window: ;; diary files. It is not really appt.el's job to ;; clean up this mess... (kill-buffer d-buff2))))))) + (setq appt-prev-comp-time cur-comp-time)) (defun appt-disp-window (min-to-app new-time appt-msg) "Display appointment due in MIN-TO-APP (a string) minutes. -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0008-always-refresh-the-mode-line.patch >From d17b6cfd2b6369afe5e4f6032787d871492c59a0 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 19:18:02 +0100 Subject: [PATCH 08/14] always refresh the mode line The operation is not expensive every 60s. Don't pass t to force-mode-line-update since we are only updating the mode line. Remove prev-appt-mode-string since it's not needed anymore. --- appt.el | 15 ++++----------- 1 files changed, 4 insertions(+), 11 deletions(-) diff --git a/appt.el b/appt.el index 51cc5e1..a940831 100644 --- a/appt.el +++ b/appt.el @@ -308,9 +308,8 @@ displayed in a window: `appt-delete-window-function' Function called to remove appointment window and buffer." (interactive "P") ; so people can force updates - (let* ((prev-appt-mode-string appt-mode-string) + (let* ((now (decode-time)) ;; Convert current time to minutes after midnight (12.01am = 1). - (now (decode-time)) (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) appt-comp-time appt-warn-time min-to-app) (save-excursion @@ -363,15 +362,9 @@ displayed in a window: (if (zerop min-to-app) (setq appt-time-msg-list (cdr appt-time-msg-list) appt-display-count 0)))) - ;; If we have changed the mode line string, redisplay all mode lines. - (and appt-display-mode-line - (not (string-equal appt-mode-string - prev-appt-mode-string)) - (progn - (force-mode-line-update t) - ;; If the string now has a notification, redisplay right now. - (if appt-mode-string - (sit-for 0))))))) + ;; Redisplay all mode lines. + (when appt-display-mode-line + (force-mode-line-update))))) (defun appt-check-diary (force cur-comp-time) "Update appointments to today's list." -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0009-fix-stray-prev-appt-display-count-don-t-set-app-disp.patch >From 247dcc5e0bb0414b72feac1b4012db18f334b8da Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Thu, 24 Mar 2011 19:24:13 +0100 Subject: [PATCH 09/14] fix stray prev-appt-display-count, don't set app-display-count to nil --- appt.el | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/appt.el b/appt.el index a940831..48184ea 100644 --- a/appt.el +++ b/appt.el @@ -314,8 +314,7 @@ displayed in a window: appt-comp-time appt-warn-time min-to-app) (save-excursion (appt-check-diary force cur-comp-time) - (setq appt-mode-string nil - appt-display-count nil) + (setq appt-mode-string nil) ;; If there are entries in the list, and the user wants a ;; message issued, get the first time off of the list and ;; calculate the number of minutes until the appointment. @@ -347,7 +346,7 @@ displayed in a window: (when (and (<= min-to-app appt-warn-time) (>= min-to-app 0)) ;; This is true every appt-display-interval minutes. - (if (zerop (mod prev-appt-display-count appt-display-interval)) + (if (zerop (mod appt-display-count appt-display-interval)) (appt-display-message (cadr (car appt-time-msg-list)) min-to-app)) (setq appt-display-count (1+ appt-display-count)) -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0010-precede-all-local-variable-in-appt-check-with-ac.patch >From 0d6589584bc8059f3de85bdf5c2be6e8583c56c0 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Sat, 26 Mar 2011 15:55:04 +0100 Subject: [PATCH 10/14] precede all local variable in appt-check with ac- This helps distinguishing local variables from global variables. There is no code change, just substitution of variables name. --- appt.el | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-) diff --git a/appt.el b/appt.el index 48184ea..17473d2 100644 --- a/appt.el +++ b/appt.el @@ -308,57 +308,57 @@ displayed in a window: `appt-delete-window-function' Function called to remove appointment window and buffer." (interactive "P") ; so people can force updates - (let* ((now (decode-time)) + (let* ((ac-now (decode-time)) ;; Convert current time to minutes after midnight (12.01am = 1). - (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) - appt-comp-time appt-warn-time min-to-app) + (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) + ac-appt-time ac-warn-time ac-min-to-app) (save-excursion - (appt-check-diary force cur-comp-time) + (appt-check-diary force ac-cur-time) (setq appt-mode-string nil) ;; If there are entries in the list, and the user wants a ;; message issued, get the first time off of the list and ;; calculate the number of minutes until the appointment. (when appt-time-msg-list - (setq appt-comp-time (caar (car appt-time-msg-list)) - appt-warn-time (or (nth 3 (car appt-time-msg-list)) + (setq ac-appt-time (caar (car appt-time-msg-list)) + ac-warn-time (or (nth 3 (car appt-time-msg-list)) appt-message-warning-time) - min-to-app (- appt-comp-time cur-comp-time)) + ac-min-to-app (- ac-appt-time ac-cur-time)) (while (and appt-time-msg-list - (< appt-comp-time cur-comp-time)) + (< ac-appt-time ac-cur-time)) (setq appt-time-msg-list (cdr appt-time-msg-list)) (if appt-time-msg-list - (setq appt-comp-time (caar (car appt-time-msg-list))))) + (setq ac-appt-time (caar (car appt-time-msg-list))))) ;; If we have an appointment between midnight and - ;; `appt-warn-time' minutes after midnight, we + ;; `ac-warn-time' minutes after midnight, we ;; must begin to issue a message before midnight. Midnight ;; is considered 0 minutes and 11:59pm is 1439 ;; minutes. Therefore we must recalculate the minutes to ;; appointment variable. It is equal to the number of ;; minutes before midnight plus the number of minutes after ;; midnight our appointment is. - (if (and (< appt-comp-time appt-warn-time) - (> (+ cur-comp-time appt-warn-time) + (if (and (< ac-appt-time ac-warn-time) + (> (+ ac-cur-time ac-warn-time) appt-max-time)) - (setq min-to-app (+ (- (1+ appt-max-time) cur-comp-time) - appt-comp-time))) + (setq ac-min-to-app (+ (- (1+ appt-max-time) ac-cur-time) + ac-appt-time))) ;; Issue warning if the appointment time is within ;; appt-message-warning time. - (when (and (<= min-to-app appt-warn-time) - (>= min-to-app 0)) + (when (and (<= ac-min-to-app ac-warn-time) + (>= ac-min-to-app 0)) ;; This is true every appt-display-interval minutes. (if (zerop (mod appt-display-count appt-display-interval)) (appt-display-message (cadr (car appt-time-msg-list)) - min-to-app)) + ac-min-to-app)) (setq appt-display-count (1+ appt-display-count)) (when appt-display-mode-line (setq appt-mode-string (concat " " (propertize - (format "App't in %s min." min-to-app) + (format "App't in %s min." ac-min-to-app) 'face 'mode-line-emphasis)))) ;; When an appointment is reached, delete it from the ;; list. Reset the count to 0 in case we display another ;; appointment on the next cycle. - (if (zerop min-to-app) + (if (zerop ac-min-to-app) (setq appt-time-msg-list (cdr appt-time-msg-list) appt-display-count 0)))) ;; Redisplay all mode lines. -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0011-copy-appt-time-msg-list-in-a-local-variabl-ac-appt-l.patch >From 0d204807d8c7866f661d65810d32c8ca9e4d5f00 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Sat, 26 Mar 2011 16:46:35 +0100 Subject: [PATCH 11/14] copy appt-time-msg-list in a local variabl ac-appt-list This is in preparation to using this variable do handle multiple appointment. Clean up obscure code at the beginning of the function. The strategy is to remove all appointment prior to the current time. We then setup all necessary local variable in one setq. There is no need to remove appointment from the list at the end of the routine since that's taken care of at the beginning. --- appt.el | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-) diff --git a/appt.el b/appt.el index 17473d2..9bae717 100644 --- a/appt.el +++ b/appt.el @@ -311,23 +311,25 @@ displayed in a window: (let* ((ac-now (decode-time)) ;; Convert current time to minutes after midnight (12.01am = 1). (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) + (ac-appt-list appt-time-msg-list) ac-appt-time ac-warn-time ac-min-to-app) (save-excursion (appt-check-diary force ac-cur-time) - (setq appt-mode-string nil) + ;; Discard appointments previous to current time + (while (and ac-appt-list + (setq ac-appt-time (caar (car ac-appt-list))) + (< ac-appt-time ac-cur-time)) + (setq ac-appt-list (cdr ac-appt-list))) + (setq appt-time-msg-list ac-appt-list) ;; If there are entries in the list, and the user wants a ;; message issued, get the first time off of the list and ;; calculate the number of minutes until the appointment. - (when appt-time-msg-list - (setq ac-appt-time (caar (car appt-time-msg-list)) - ac-warn-time (or (nth 3 (car appt-time-msg-list)) - appt-message-warning-time) - ac-min-to-app (- ac-appt-time ac-cur-time)) - (while (and appt-time-msg-list - (< ac-appt-time ac-cur-time)) - (setq appt-time-msg-list (cdr appt-time-msg-list)) - (if appt-time-msg-list - (setq ac-appt-time (caar (car appt-time-msg-list))))) + (when ac-appt-list + (setq ac-warn-time (or (nth 3 (car ac-appt-list)) + appt-message-warning-time) + ac-min-to-app (- ac-appt-time ac-cur-time) + ac-appt-time (caar (car ac-appt-list)) + appt-mode-string nil) ;; If we have an appointment between midnight and ;; `ac-warn-time' minutes after midnight, we ;; must begin to issue a message before midnight. Midnight @@ -347,7 +349,7 @@ displayed in a window: (>= ac-min-to-app 0)) ;; This is true every appt-display-interval minutes. (if (zerop (mod appt-display-count appt-display-interval)) - (appt-display-message (cadr (car appt-time-msg-list)) + (appt-display-message (cadr (car ac-appt-list)) ac-min-to-app)) (setq appt-display-count (1+ appt-display-count)) (when appt-display-mode-line @@ -355,12 +357,10 @@ displayed in a window: (concat " " (propertize (format "App't in %s min." ac-min-to-app) 'face 'mode-line-emphasis)))) - ;; When an appointment is reached, delete it from the - ;; list. Reset the count to 0 in case we display another - ;; appointment on the next cycle. + ;; When an appointment is reached reset the count to 0 in + ;; case we display another appointment on the next cycle. (if (zerop ac-min-to-app) - (setq appt-time-msg-list (cdr appt-time-msg-list) - appt-display-count 0)))) + (setq appt-display-count 0)))) ;; Redisplay all mode lines. (when appt-display-mode-line (force-mode-line-update))))) -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0012-implement-multiple-appointments.patch >From cf17d3430324cf43d77e3260b4f7dabe6b005860 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Sun, 27 Mar 2011 17:59:07 +0200 Subject: [PATCH 12/14] implement multiple appointments Change strategy in appt-check : first remove old appointments, go through all appointments and pick relevant appointments, last display mode line and message. Add a new variable appt-display-multiple that is set to t by default. I think setting it to t is a good idea to avoid missing appointments. This can happen when a second appointment has a warning time that precedes the first. Add a new variable appt-disp-window-multiple-function that takes the function to display multiple appointments. Add the function appt-disp-multiple-window that does the actual displaying. Add function appt-display-multiple-message that is called from appt-check. Note that the minutes passed is an integer instead of a string for the single appointment version. I just feel the conversion is kind of silly. --- appt.el | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 125 insertions(+), 25 deletions(-) diff --git a/appt.el b/appt.el index 9bae717..1a9e9f3 100644 --- a/appt.el +++ b/appt.el @@ -164,13 +164,24 @@ This will occur at midnight when the appointment list is updated." (defcustom appt-disp-window-function 'appt-disp-window "Function called to display appointment window. -Only relevant if reminders are being displayed in a window. -It should take three string arguments: the number of minutes till -the appointment, the current time, and the text of the appointment." +It's called when `appt-display-multiple' is set to nil. Only +relevant if reminders are being displayed in a window. It should +take three string arguments: the number of minutes till the +appointment, the current time, and the text of the appointment." :type '(choice (const appt-disp-window) function) :group 'appt) +(defcustom appt-disp-window-multiple-function 'appt-disp-multiple-window + "Function called to display appointment window. +It's called when `appt-display-multiple' is set to t. Only +relevant if reminders are being displayed in a window. It takes +two argument the first is the number of minutes until the first +appointment the second contain a list of the appointments." + :type '(choice (const appt-disp-multiple-window) + function) + :group 'appt) + (defcustom appt-delete-window-function 'appt-delete-window "Function called to remove appointment window and buffer. Only relevant if reminders are being displayed in a window." @@ -178,6 +189,10 @@ Only relevant if reminders are being displayed in a window." function) :group 'appt) +(defcustom appt-display-multiple t + "Non-nil means display multiple appointment." + :type 'boolean + :group 'appt) ;;; Internal variables below this point. @@ -252,6 +267,26 @@ The variable `appt-audible' controls the audible reminder." ((eq appt-display-format 'echo) (message "%s" string))))) +(defun appt-display-multiple-message (appt-list mins) + "Display a list of due appointments, first appointment in MINS minutes. +The list APPT-LIST contains the list of appointments. +The format of the visible reminder is controlled by `appt-display-format'. +The variable `appt-audible' controls the audible reminder." + ;; Let-binding for backwards compatibility. Remove when obsolete + ;; vars appt-msg-window and appt-visible are dropped. + (let ((appt-display-format + (if (eq appt-display-format 'ignore) + (cond (appt-msg-window 'window) + (appt-visible 'echo)) + appt-display-format))) + (if appt-audible (beep 1)) + (cond ((eq appt-display-format 'window) + (funcall appt-disp-window-multiple-function mins appt-list) + (run-at-time (format "%d sec" appt-display-duration) + nil + appt-delete-window-function)) + ((eq appt-display-format 'echo) + (message "%s" (mapconcat 'identity (nreverse appt-list) " ")))))) (defvar diary-selective-display) @@ -312,24 +347,24 @@ displayed in a window: ;; Convert current time to minutes after midnight (12.01am = 1). (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) (ac-appt-list appt-time-msg-list) - ac-appt-time ac-warn-time ac-min-to-app) + (ac-first nil) + ac-appt-time ac-warn-time ac-min-to-app ac-msg ac-msg-list) (save-excursion (appt-check-diary force ac-cur-time) ;; Discard appointments previous to current time (while (and ac-appt-list - (setq ac-appt-time (caar (car ac-appt-list))) - (< ac-appt-time ac-cur-time)) + (< (caar (car ac-appt-list)) ac-cur-time)) (setq ac-appt-list (cdr ac-appt-list))) - (setq appt-time-msg-list ac-appt-list) - ;; If there are entries in the list, and the user wants a - ;; message issued, get the first time off of the list and - ;; calculate the number of minutes until the appointment. - (when ac-appt-list + (setq appt-time-msg-list ac-appt-list + appt-mode-string nil + appt-display-count (1+ appt-display-count)) + + (while ac-appt-list (setq ac-warn-time (or (nth 3 (car ac-appt-list)) appt-message-warning-time) - ac-min-to-app (- ac-appt-time ac-cur-time) ac-appt-time (caar (car ac-appt-list)) - appt-mode-string nil) + ac-min-to-app (- ac-appt-time ac-cur-time)) + ;; If we have an appointment between midnight and ;; `ac-warn-time' minutes after midnight, we ;; must begin to issue a message before midnight. Midnight @@ -347,23 +382,28 @@ displayed in a window: ;; appt-message-warning time. (when (and (<= ac-min-to-app ac-warn-time) (>= ac-min-to-app 0)) - ;; This is true every appt-display-interval minutes. - (if (zerop (mod appt-display-count appt-display-interval)) - (appt-display-message (cadr (car ac-appt-list)) - ac-min-to-app)) - (setq appt-display-count (1+ appt-display-count)) - (when appt-display-mode-line - (setq appt-mode-string - (concat " " (propertize - (format "App't in %s min." ac-min-to-app) - 'face 'mode-line-emphasis)))) + (setq ac-msg (cadr (car ac-appt-list))) + (add-to-list 'ac-msg-list ac-msg) + (when (not ac-first) + (setq ac-first (list ac-min-to-app ac-msg))) ;; When an appointment is reached reset the count to 0 in ;; case we display another appointment on the next cycle. (if (zerop ac-min-to-app) - (setq appt-display-count 0)))) + (setq appt-display-count 0))) + (setq ac-appt-list (cdr ac-appt-list))) + (when (and ac-first + (zerop (mod appt-display-count appt-display-interval)) + (if appt-display-multiple + (appt-display-multiple-message ac-msg-list (car ac-first)) + (appt-display-message (cadr ac-first) (car ac-first))))) ;; Redisplay all mode lines. (when appt-display-mode-line - (force-mode-line-update))))) + (when ac-first + (setq appt-mode-string + (concat " " (propertize + (format "App't in %s min." (car ac-first)) + 'face 'mode-line-emphasis))))) + (force-mode-line-update)))) (defun appt-check-diary (force cur-comp-time) "Update appointments to today's list." @@ -450,6 +490,25 @@ message APPT-MSG in a separate buffer." (raise-frame (selected-frame)) (select-window this-window))) +(defun appt-disp-multiple-window (min-to-app appt-list) + "Display list of APPT-LIST." + (let ((this-window (selected-window))) + (with-current-buffer (get-buffer-create appt-buffer-name) + (setq buffer-read-only nil + buffer-undo-list t) + (erase-buffer) + (insert (mapconcat 'identity (nreverse appt-list) "\n"))) + (pop-to-buffer appt-buffer-name) + (fit-window-to-buffer) + (calendar-set-mode-line + (format " Appointment %s." + (if (= min-to-app 0) "now" + (format "in %d minute%s" min-to-app + (if (= min-to-app 1) "" "s"))))) + + (raise-frame (selected-frame)) + (select-window this-window))) + (defun appt-delete-window () "Function called to undisplay appointment messages. Usually just deletes the appointment buffer." @@ -705,6 +764,47 @@ ARG is positive, otherwise off." (appt-check t)))) +;;; Test functions +;; two helper functions for tests +;; (defun appt-test-add (min-from-now msg warntime) +;; (appt-add +;; (format-time-string +;; "%H:%M" +;; (let ((time (current-time))) +;; (cons (nth 0 time) +;; (+ (* 60 min-from-now) (nth 1 time))))) msg warntime)) + +;; (defun appt-test-init () +;; (setq appt-display-count 0) +;; (setq appt-display-interval 1) +;; (setq appt-time-msg-list nil)) + +;; appointment in a minute +;; (progn +;; (appt-test-init) +;; (add-appt 1 "one minute" 1)) + +;; two appointment one after the other, it should display: +;; 1 first +;; 2 first and second +;; 3 second +;; (progn +;; (appt-test-init) +;; (add-appt 1 "first" 1) +;; (add-appt 2 "second" 1)) + +;; typical shadowing problem solved by multiple appointments. The +;; second appointment has warning time that precedes the first. I have +;; actually missed an appointment because of this! It should display: +;; 1 second +;; 2 first and second +;; 3 first and second +;; 4 second +;; (progn +;; (appt-test-init) +;; (add-appt 2 "first" 1) +;; (add-appt 3 "second" 3)) + (provide 'appt) ;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347 -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0013-move-appointment-checking-code-in-a-function.patch >From f58eba27aebbcfb0bbf5385a9efe7a5f3b32f289 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Mon, 28 Mar 2011 19:54:09 +0200 Subject: [PATCH 13/14] move appointment checking code in a function This makes function appt-check a reasonable size and I have added some comments as well. --- appt.el | 78 +++++++++++++++++++++++++++++++++++++------------------------- 1 files changed, 46 insertions(+), 32 deletions(-) diff --git a/appt.el b/appt.el index 1a9e9f3..c3cc429 100644 --- a/appt.el +++ b/appt.el @@ -348,55 +348,39 @@ displayed in a window: (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) (ac-appt-list appt-time-msg-list) (ac-first nil) - ac-appt-time ac-warn-time ac-min-to-app ac-msg ac-msg-list) + ac-msg ac-msg-list ac-min-to-app) (save-excursion (appt-check-diary force ac-cur-time) + ;; Discard appointments previous to current time (while (and ac-appt-list (< (caar (car ac-appt-list)) ac-cur-time)) (setq ac-appt-list (cdr ac-appt-list))) + + ;; Update global list and few other things (setq appt-time-msg-list ac-appt-list appt-mode-string nil appt-display-count (1+ appt-display-count)) + ;; Now walk the remaining list checking for appointments (while ac-appt-list - (setq ac-warn-time (or (nth 3 (car ac-appt-list)) - appt-message-warning-time) - ac-appt-time (caar (car ac-appt-list)) - ac-min-to-app (- ac-appt-time ac-cur-time)) - - ;; If we have an appointment between midnight and - ;; `ac-warn-time' minutes after midnight, we - ;; must begin to issue a message before midnight. Midnight - ;; is considered 0 minutes and 11:59pm is 1439 - ;; minutes. Therefore we must recalculate the minutes to - ;; appointment variable. It is equal to the number of - ;; minutes before midnight plus the number of minutes after - ;; midnight our appointment is. - (if (and (< ac-appt-time ac-warn-time) - (> (+ ac-cur-time ac-warn-time) - appt-max-time)) - (setq ac-min-to-app (+ (- (1+ appt-max-time) ac-cur-time) - ac-appt-time))) - ;; Issue warning if the appointment time is within - ;; appt-message-warning time. - (when (and (<= ac-min-to-app ac-warn-time) - (>= ac-min-to-app 0)) - (setq ac-msg (cadr (car ac-appt-list))) - (add-to-list 'ac-msg-list ac-msg) - (when (not ac-first) - (setq ac-first (list ac-min-to-app ac-msg))) - ;; When an appointment is reached reset the count to 0 in - ;; case we display another appointment on the next cycle. - (if (zerop ac-min-to-app) - (setq appt-display-count 0))) + (setq ac-min-to-app + (appt-check-appointment (car ac-appt-list) ac-cur-time)) + (when ac-min-to-app + (setq ac-msg (cadr (car ac-appt-list))) + (add-to-list 'ac-msg-list ac-msg)) + (when (not ac-first) + (setq ac-first (list ac-min-to-app ac-msg))) (setq ac-appt-list (cdr ac-appt-list))) + + ;; Display messages (when (and ac-first (zerop (mod appt-display-count appt-display-interval)) (if appt-display-multiple (appt-display-multiple-message ac-msg-list (car ac-first)) (appt-display-message (cadr ac-first) (car ac-first))))) - ;; Redisplay all mode lines. + + ;; Display mode line (when appt-display-mode-line (when ac-first (setq appt-mode-string @@ -405,6 +389,36 @@ displayed in a window: 'face 'mode-line-emphasis))))) (force-mode-line-update)))) +(defun appt-check-appointment (appt cur-time) + "Check if apppointment needs to be displayed. +Returns integer of minute till the appointment is due or nil" + (let* ((aca-warn-time (or (nth 3 appt) + appt-message-warning-time)) + (aca-appt-time (caar appt)) + (aca-min-to-app (- aca-appt-time cur-time))) + + ;; If we have an appointment between midnight and + ;; `aca-warn-time' minutes after midnight, we + ;; must begin to issue a message before midnight. Midnight + ;; is considered 0 minutes and 11:59pm is 1439 + ;; minutes. Therefore we must recalculate the minutes to + ;; appointment variable. It is equal to the number of + ;; minutes before midnight plus the number of minutes after + ;; midnight our appointment is. + (when (and (< aca-appt-time aca-warn-time) + (> (+ cur-time aca-warn-time) + appt-max-time)) + (setq aca-min-to-app (+ (- (1+ appt-max-time) cur-time) + aca-appt-time))) + ;; Issue warning if the appointment time is within + ;; appt-message-warning time. + (when (and (<= aca-min-to-app aca-warn-time) + (>= aca-min-to-app 0)) + ;; When an appointment is reached reset the count to 0 in + ;; case we display another appointment on the next cycle. + (when (zerop aca-min-to-app) + (setq appt-display-count 0)) aca-min-to-app))) + (defun appt-check-diary (force cur-comp-time) "Update appointments to today's list." ;; At first check in any day -- 1.7.3.2 --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0014-fix-logic-bug.patch >From 830d6dc5dc758aaa80a9aad08423daf8b060f026 Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Sun, 10 Apr 2011 11:06:01 +0200 Subject: [PATCH 14/14] fix logic bug --- appt.el | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appt.el b/appt.el index c3cc429..b86d657 100644 --- a/appt.el +++ b/appt.el @@ -368,9 +368,9 @@ displayed in a window: (appt-check-appointment (car ac-appt-list) ac-cur-time)) (when ac-min-to-app (setq ac-msg (cadr (car ac-appt-list))) - (add-to-list 'ac-msg-list ac-msg)) + (add-to-list 'ac-msg-list ac-msg) (when (not ac-first) - (setq ac-first (list ac-min-to-app ac-msg))) + (setq ac-first (list ac-min-to-app ac-msg)))) (setq ac-appt-list (cdr ac-appt-list))) ;; Display messages -- 1.7.3.2 --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=appt.el Content-Transfer-Encoding: quoted-printable ;;; appt.el --- appointment notification functions ;; Copyright (C) 1989, 1990, 1994, 1998, 2001, 2002, 2003, 2004, 2005, ;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; Author: Neil Mager ;; Maintainer: Glenn Morris ;; Keywords: calendar ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; ;; appt.el - visible and/or audible notification of ;; appointments from diary file. ;; ;; ;; Thanks to Edward M. Reingold for much help and many suggestions, ;; And to many others for bug fixes and suggestions. ;; ;; ;; This functions in this file will alert the user of a ;; pending appointment based on his/her diary file. This package ;; is documented in the Emacs manual. ;; ;; To activate this package, simply use (appt-activate 1). ;; A `diary-file' with appointments of the format described in the ;; documentation of the function `appt-check' is required. ;; Relevant customizable variables are also listed in the ;; documentation of that function. ;; ;; Today's appointment list is initialized from the diary when this ;; package is activated. Additionally, the appointments list is ;; recreated automatically at 12:01am for those who do not logout ;; every day or are programming late. It is also updated when the ;; `diary-file' (or a file it includes) is saved. Calling ;; `appt-check' with an argument (or re-enabling the package) forces a ;; re-initialization at any time. ;; ;; In order to add or delete items from today's list, without ;; changing the diary file, use `appt-add' and `appt-delete'. ;; ;; Brief internal description - Skip this if you are not interested! ;; ;; The function `appt-make-list' creates the appointments list which ;; `appt-check' reads. ;; ;; You can change the way the appointment window is created/deleted by ;; setting the variables ;; ;; appt-disp-window-function ;; and ;; appt-delete-window-function ;; ;; For instance, these variables could be set to functions that display ;; appointments in pop-up frames, which are lowered or iconified after ;; `appt-display-interval' minutes. ;; ;;; Code: (require 'diary-lib) (defgroup appt nil "Appointment notification." :prefix "appt-" :group 'calendar) (defcustom appt-issue-message t "Non-nil means check for appointments in the diary buffer. To be detected, the diary entry must have the format described in the documentation of the function `appt-check'." :type 'boolean :group 'appt) (make-obsolete-variable 'appt-issue-message "use the function `appt-activate', and the \ variable `appt-display-format' instead." "22.1") (defcustom appt-message-warning-time 12 "Time in minutes before an appointment that the warning begins." :type 'integer :group 'appt) (defcustom appt-audible t "Non-nil means beep to indicate appointment." :type 'boolean :group 'appt) (defcustom appt-visible t "Non-nil means display appointment message in echo area. This variable is only relevant if `appt-msg-window' is nil." :type 'boolean :group 'appt) (make-obsolete-variable 'appt-visible 'appt-display-format "22.1") (defcustom appt-msg-window t "Non-nil means display appointment message in another window. If non-nil, this variable overrides `appt-visible'." :type 'boolean :group 'appt) (make-obsolete-variable 'appt-msg-window 'appt-display-format "22.1") ;; TODO - add popup. (defcustom appt-display-format 'ignore "How appointment reminders should be displayed. The options are: window - use a separate window echo - use the echo area nil - no visible reminder. See also `appt-audible' and `appt-display-mode-line'. The default value is 'ignore, which means to fall back on the value of the (obsolete) variables `appt-msg-window' and `appt-visible'." :type '(choice (const :tag "Separate window" window) (const :tag "Echo-area" echo) (const :tag "No visible display" nil) (const :tag "Backwards compatibility setting - choose another val= ue" ignore)) :group 'appt :version "22.1") (defcustom appt-display-mode-line t "Non-nil means display minutes to appointment and time on the mode line. This is in addition to any other display of appointment messages." :type 'boolean :group 'appt) (defcustom appt-display-duration 10 "The number of seconds an appointment message is displayed. Only relevant if reminders are to be displayed in their own window." :type 'integer :group 'appt) (defcustom appt-display-diary t "Non-nil displays the diary when the appointment list is first initialize= d. This will occur at midnight when the appointment list is updated." :type 'boolean :group 'appt) (defcustom appt-display-interval 3 "Number of minutes to wait between checking the appointment list." :type 'integer :group 'appt) (defcustom appt-disp-window-function 'appt-disp-window "Function called to display appointment window. It's called when `appt-display-multiple' is set to nil. Only relevant if reminders are being displayed in a window. It should take three string arguments: the number of minutes till the appointment, the current time, and the text of the appointment." :type '(choice (const appt-disp-window) function) :group 'appt) (defcustom appt-disp-window-multiple-function 'appt-disp-multiple-window "Function called to display appointment window. It's called when `appt-display-multiple' is set to t. Only relevant if reminders are being displayed in a window. It takes two argument the first is the number of minutes until the first appointment the second contain a list of the appointments." :type '(choice (const appt-disp-multiple-window) function) :group 'appt) (defcustom appt-delete-window-function 'appt-delete-window "Function called to remove appointment window and buffer. Only relevant if reminders are being displayed in a window." :type '(choice (const appt-delete-window) function) :group 'appt) (defcustom appt-display-multiple t "Non-nil means display multiple appointment." :type 'boolean :group 'appt) ;;; Internal variables below this point. (defconst appt-buffer-name "*appt-buf*" "Name of the appointments buffer.") ;; TODO Turn this into an alist? It would be easier to add more ;; optional elements. ;; TODO There should be a way to set WARNTIME (and other properties) ;; from the diary-file. Implementing that would be a good reason ;; to change this to an alist. (defvar appt-time-msg-list nil "The list of appointments for today. Use `appt-add' and `appt-delete' to add and delete appointments. The original list is generated from today's `diary-entries-list', and can be regenerated using the function `appt-check'. Each element of the generated list has the form \(MINUTES STRING [FLAG] [WARNTIME]) where MINUTES is the time in minutes of the appointment after midnight, and STRING is the description of the appointment. FLAG and WARNTIME can only be present if the element was made with `appt-add'. A non-nil FLAG indicates that the element was made with `appt-add', so calling `appt-make-list' again should preserve it. If WARNTIME is non-nil, it is an integer to use in place of `appt-message-warning-time'.") (defconst appt-max-time (1- (* 24 60)) "11:59pm in minutes - number of minutes in a day minus 1.") (defvar appt-mode-string nil "String being displayed in the mode line saying you have an appointment. The actual string includes the amount of time till the appointment. Only used if `appt-display-mode-line' is non-nil.") (put 'appt-mode-string 'risky-local-variable t) ; for 'face property (defvar appt-prev-comp-time nil "Time of day (mins since midnight) at which we last checked appointments. A nil value forces the diary file to be (re-)checked for appointments.") (defvar appt-display-count 0 "Internal variable used to count number of consecutive reminders.") (defvar appt-timer nil "Timer used for diary appointment notifications (`appt-check'). If this is non-nil, appointment checking is active.") ;;; Functions. (defun appt-display-message (string mins) "Display a reminder about an appointment. The string STRING describes the appointment, due in integer MINS minutes. The format of the visible reminder is controlled by `appt-display-format'. The variable `appt-audible' controls the audible reminder." ;; Let-binding for backwards compatibility. Remove when obsolete ;; vars appt-msg-window and appt-visible are dropped. (let ((appt-display-format (if (eq appt-display-format 'ignore) (cond (appt-msg-window 'window) (appt-visible 'echo)) appt-display-format))) (if appt-audible (beep 1)) (cond ((eq appt-display-format 'window) (funcall appt-disp-window-function (number-to-string mins) ;; TODO - use calendar-month-abbrev-array rather than %= b? (format-time-string "%a %b %e " (current-time)) string) (run-at-time (format "%d sec" appt-display-duration) nil appt-delete-window-function)) ((eq appt-display-format 'echo) (message "%s" string))))) (defun appt-display-multiple-message (appt-list mins) "Display a list of due appointments, first appointment in MINS minutes. The list APPT-LIST contains the list of appointments. The format of the visible reminder is controlled by `appt-display-format'. The variable `appt-audible' controls the audible reminder." ;; Let-binding for backwards compatibility. Remove when obsolete ;; vars appt-msg-window and appt-visible are dropped. (let ((appt-display-format (if (eq appt-display-format 'ignore) (cond (appt-msg-window 'window) (appt-visible 'echo)) appt-display-format))) (if appt-audible (beep 1)) (cond ((eq appt-display-format 'window) (funcall appt-disp-window-multiple-function mins appt-list) (run-at-time (format "%d sec" appt-display-duration) nil appt-delete-window-function)) ((eq appt-display-format 'echo) (message "%s" (mapconcat 'identity (nreverse appt-list) " ")))))) (defvar diary-selective-display) (defun appt-check (&optional force) "Check for an appointment and update any reminder display. If optional argument FORCE is non-nil, reparse the diary file for appointments. Otherwise the diary file is only parsed once per day, or when it (or a file it includes) is saved. Note: the time must be the first thing in the line in the diary for a warning to be issued. The format of the time can be either 24 hour or am/pm. For example: 02/23/89 18:00 Dinner Thursday 11:45am Lunch meeting. Appointments are checked every `appt-display-interval' minutes. The following variables control appointment notification: `appt-display-format' Controls the format in which reminders are displayed. `appt-audible' Variable used to determine if reminder is audible. Default is t. `appt-message-warning-time' Variable used to determine when appointment message should first be displayed. `appt-display-mode-line' If non-nil, a generic message giving the time remaining is shown in the mode-line when an appointment is due. `appt-display-interval' Interval in minutes at which to check for pending appointments. `appt-display-diary' Display the diary buffer when the appointment list is initialized for the first time in a day. The following variables are only relevant if reminders are being displayed in a window: `appt-display-duration' The number of seconds an appointment message is displayed. `appt-disp-window-function' Function called to display appointment window. `appt-delete-window-function' Function called to remove appointment window and buffer." (interactive "P") ; so people can force updates (let* ((ac-now (decode-time)) ;; Convert current time to minutes after midnight (12.01am =3D 1). (ac-cur-time (+ (* 60 (nth 2 ac-now)) (nth 1 ac-now))) (ac-appt-list appt-time-msg-list) (ac-first nil) ac-msg ac-msg-list ac-min-to-app) (save-excursion (appt-check-diary force ac-cur-time) ;; Discard appointments previous to current time (while (and ac-appt-list (< (caar (car ac-appt-list)) ac-cur-time)) (setq ac-appt-list (cdr ac-appt-list))) ;; Update global list and few other things (setq appt-time-msg-list ac-appt-list appt-mode-string nil appt-display-count (1+ appt-display-count)) ;; Now walk the remaining list checking for appointments (while ac-appt-list (setq ac-min-to-app (appt-check-appointment (car ac-appt-list) ac-cur-time)) (when ac-min-to-app (setq ac-msg (cadr (car ac-appt-list))) (add-to-list 'ac-msg-list ac-msg) (when (not ac-first) (setq ac-first (list ac-min-to-app ac-msg)))) (setq ac-appt-list (cdr ac-appt-list))) ;; Display messages (when (and ac-first (zerop (mod appt-display-count appt-display-interval)) (if appt-display-multiple (appt-display-multiple-message ac-msg-list (car ac-first)) (appt-display-message (cadr ac-first) (car ac-first))))) ;; Display mode line (when appt-display-mode-line (when ac-first (setq appt-mode-string (concat " " (propertize (format "App't in %s min." (car ac-first)) 'face 'mode-line-emphasis))))) (force-mode-line-update)))) (defun appt-check-appointment (appt cur-time) "Check if apppointment needs to be displayed. Returns integer of minute till the appointment is due or nil" (let* ((aca-warn-time (or (nth 3 appt) appt-message-warning-time)) (aca-appt-time (caar appt)) (aca-min-to-app (- aca-appt-time cur-time))) =20=20=20=20 ;; If we have an appointment between midnight and ;; `aca-warn-time' minutes after midnight, we ;; must begin to issue a message before midnight. Midnight ;; is considered 0 minutes and 11:59pm is 1439 ;; minutes. Therefore we must recalculate the minutes to ;; appointment variable. It is equal to the number of ;; minutes before midnight plus the number of minutes after ;; midnight our appointment is. (when (and (< aca-appt-time aca-warn-time) (> (+ cur-time aca-warn-time) appt-max-time)) (setq aca-min-to-app (+ (- (1+ appt-max-time) cur-time) aca-appt-time))) ;; Issue warning if the appointment time is within ;; appt-message-warning time. (when (and (<=3D aca-min-to-app aca-warn-time) (>=3D aca-min-to-app 0)) ;; When an appointment is reached reset the count to 0 in ;; case we display another appointment on the next cycle. (when (zerop aca-min-to-app) (setq appt-display-count 0)) aca-min-to-app))) =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 (defun appt-check-diary (force cur-comp-time) "Update appointments to today's list." ;; At first check in any day (if (or force ; eg initialize, diary save (null appt-prev-comp-time) ; first check (< cur-comp-time appt-prev-comp-time)) ; new day (ignore-errors (if appt-display-diary (let ((diary-hook (if (assoc 'appt-make-list diary-hook) diary-hook (cons 'appt-make-list diary-hook)))) (diary)) (let* ((diary-display-function 'appt-make-list) (d-buff (find-buffer-visiting diary-file)) (selective (if d-buff ; diary buffer exists (with-current-buffer d-buff diary-selective-display))) d-buff2) ;; Not displaying the diary, so we can ignore ;; diary-number-of-entries. Since appt.el only ;; works on a daily basis, no need for more entries. ;; FIXME why not using diary-list-entries with ;; non-nil LIST-ONLY? (diary 1) ;; If the diary buffer existed before this command, ;; restore its display state. Otherwise, kill it. (and (setq d-buff2 (find-buffer-visiting diary-file)) (if d-buff (or selective (with-current-buffer d-buff2 (if diary-selective-display ;; diary-show-all-entries displays ;; the diary buffer. (diary-unhide-everything)))) ;; FIXME does not kill any included diary files. ;; The real issue is that (diary) should not ;; have the side effect of visiting all the ;; diary files. It is not really appt.el's job to ;; clean up this mess... (kill-buffer d-buff2))))))) (setq appt-prev-comp-time cur-comp-time)) (defun appt-disp-window (min-to-app new-time appt-msg) "Display appointment due in MIN-TO-APP (a string) minutes. NEW-TIME is a string giving the date. Displays the appointment message APPT-MSG in a separate buffer." (let ((this-window (selected-window)) (appt-disp-buf (get-buffer-create appt-buffer-name))) ;; Make sure we're not in the minibuffer before splitting the window. ;; FIXME this seems needlessly complicated? (when (minibufferp) (other-window 1) (and (minibufferp) (display-multi-frame-p) (other-frame 1))) (if (cdr (assq 'unsplittable (frame-parameters))) ;; In an unsplittable frame, use something somewhere else. (progn (set-buffer appt-disp-buf) (display-buffer appt-disp-buf)) (unless (or (special-display-p (buffer-name appt-disp-buf)) (same-window-p (buffer-name appt-disp-buf))) ;; By default, split the bottom window and use the lower part. (appt-select-lowest-window) ;; Split the window, unless it's too small to do so. (when (>=3D (window-height) (* 2 window-min-height)) (select-window (split-window)))) (switch-to-buffer appt-disp-buf)) ;; FIXME Link to diary entry? (calendar-set-mode-line (format " Appointment %s. %s " (if (string-equal "0" min-to-app) "now" (format "in %s minute%s" min-to-app (if (string-equal "1" min-to-app) "" "s"))) new-time)) (setq buffer-read-only nil buffer-undo-list t) (erase-buffer) (insert appt-msg) (shrink-window-if-larger-than-buffer (get-buffer-window appt-disp-buf t= )) (set-buffer-modified-p nil) (setq buffer-read-only t) (raise-frame (selected-frame)) (select-window this-window))) (defun appt-disp-multiple-window (min-to-app appt-list) "Display list of APPT-LIST." (let ((this-window (selected-window))) (with-current-buffer (get-buffer-create appt-buffer-name) (setq buffer-read-only nil buffer-undo-list t) (erase-buffer) (insert (mapconcat 'identity (nreverse appt-list) "\n"))) (pop-to-buffer appt-buffer-name) (fit-window-to-buffer) (calendar-set-mode-line (format " Appointment %s." (if (=3D min-to-app 0) "now" (format "in %d minute%s" min-to-app (if (=3D min-to-app 1) "" "s"))))) (raise-frame (selected-frame)) (select-window this-window))) (defun appt-delete-window () "Function called to undisplay appointment messages. Usually just deletes the appointment buffer." (let ((window (get-buffer-window appt-buffer-name t))) (and window (or (eq window (frame-root-window (window-frame window))) (delete-window window)))) (kill-buffer appt-buffer-name) (if appt-audible (beep 1))) (defun appt-select-lowest-window () "Select the lowest window on the frame." (let ((lowest-window (selected-window)) (bottom-edge (nth 3 (window-edges))) next-bottom-edge) (walk-windows (lambda (w) (when (< bottom-edge (setq next-bottom-edge (nth 3 (window-edges w)))) (setq bottom-edge next-bottom-edge lowest-window w))) 'nomini) (select-window lowest-window))) (defconst appt-time-regexp "[0-9]?[0-9]\\(h\\([0-9][0-9]\\)?\\|[:.][0-9][0-9]\\)\\(am\\|pm\\)?") ;;;###autoload (defun appt-add (time msg &optional warntime) "Add an appointment for today at TIME with message MSG. The time should be in either 24 hour format or am/pm format. Optional argument WARNTIME is an integer (or string) giving the number of minutes before the appointment at which to start warning. The default is `appt-message-warning-time'." (interactive "sTime (hh:mm[am/pm]): \nsMessage:=20 sMinutes before the appointment to start warning: ") (unless (string-match appt-time-regexp time) (error "Unacceptable time-string")) (and (stringp warntime) (setq warntime (unless (string-equal warntime "") (string-to-number warntime)))) (and warntime (not (integerp warntime)) (error "Argument WARNTIME must be an integer, or nil")) (let ((time-msg (list (list (appt-convert-time time)) (concat time " " msg) t))) ;; It is presently non-sensical to have multiple warnings about ;; the same appointment with just different delays, but it might ;; not always be so. TODO (if warntime (setq time-msg (append time-msg (list warntime)))) (unless (member time-msg appt-time-msg-list) (setq appt-time-msg-list (appt-sort-list (nconc appt-time-msg-list (list time-msg))))))) ;;;###autoload (defun appt-delete () "Delete an appointment from the list of appointments." (interactive) (let ((tmp-msg-list appt-time-msg-list)) (dolist (element tmp-msg-list) (if (y-or-n-p (concat "Delete " ;; We want to quote any doublequotes in the ;; string, as well as put doublequotes around i= t. (prin1-to-string (substring-no-properties (cadr element) 0)) " from list? ")) (setq appt-time-msg-list (delq element appt-time-msg-list))))) (appt-check) (message "")) (defvar number) (defvar original-date) (defvar diary-entries-list) ;; Autoload for the old way of using this package. Can be removed sometime. ;;;###autoload (defun appt-make-list () "Update the appointments list from today's diary buffer. The time must be at the beginning of a line for it to be put in the appointments list (see examples in documentation of the function `appt-check'). We assume that the variables DATE and NUMBER hold the arguments that `diary-list-entries' received. They specify the range of dates that the diary is being processed for. Any appointments made with `appt-add' are not affected by this function. For backwards compatibility, this function activates the appointment package (if it is not already active)." ;; See comments above appt-activate defun. (if (not appt-timer) (appt-activate 1) ;; We have something to do if the range of dates that the diary is ;; considering includes the current date. (if (and (not (calendar-date-compare (list (calendar-current-date)) (list original-date))) (calendar-date-compare (list (calendar-current-date)) (list (calendar-gregorian-from-absolute (+ (calendar-absolute-from-gregorian original-date) number))))) (save-excursion ;; Clear the appointments list, then fill it in from the diary. (dolist (elt appt-time-msg-list) ;; Delete any entries that were not made with appt-add. (unless (nth 2 elt) (setq appt-time-msg-list (delq elt appt-time-msg-list)))) (if diary-entries-list ;; Cycle through the entry-list (diary-entries-list) ;; looking for entries beginning with a time. If the ;; entry begins with a time, add it to the ;; appt-time-msg-list. Then sort the list. (let ((entry-list diary-entries-list) (new-time-string "") time-string) ;; Below, we assume diary-entries-list was in date ;; order. It is, unless something on ;; diary-list-entries-hook has changed it, eg ;; diary-include-other-files (bug#7019). It must be ;; in date order if number =3D 1. (and diary-list-entries-hook appt-display-diary (not (eq diary-number-of-entries 1)) (not (memq (car (last diary-list-entries-hook)) '(diary-sort-entries sort-diary-entries))) (setq entry-list (sort entry-list 'diary-entry-compare= ))) ;; Skip diary entries for dates before today. (while (and entry-list (calendar-date-compare (car entry-list) (list (calendar-current-date)= ))) (setq entry-list (cdr entry-list))) ;; Parse the entries for today. (while (and entry-list (calendar-date-equal (calendar-current-date) (caar entry-list))) (setq time-string (cadr (car entry-list))) (while (string-match appt-time-regexp time-string) (let* ((beg (match-beginning 0)) ;; Get just the time for this appointment. (only-time (match-string 0 time-string)) ;; Find the end of this appointment ;; (the start of the next). (end (string-match (concat "\n[ \t]*" appt-time-regexp) time-string (match-end 0))) ;; Get the whole string for this appointment. (appt-time-string (substring time-string beg end)) (appt-time (list (appt-convert-time only-time))) (time-msg (list appt-time appt-time-string))) ;; Add this appointment to appt-time-msg-list. (setq appt-time-msg-list (nconc appt-time-msg-list (list time-msg)) ;; Discard this appointment from the string. time-string (if end (substring time-string end) "")))) (setq entry-list (cdr entry-list))))) (setq appt-time-msg-list (appt-sort-list appt-time-msg-list)) ;; Convert current time to minutes after midnight (12:01am =3D 1), ;; so that elements in the list that are earlier than the ;; present time can be removed. (let* ((now (decode-time)) (cur-comp-time (+ (* 60 (nth 2 now)) (nth 1 now))) (appt-comp-time (caar (car appt-time-msg-list)))) (while (and appt-time-msg-list (< appt-comp-time cur-comp-time)) (setq appt-time-msg-list (cdr appt-time-msg-list)) (if appt-time-msg-list (setq appt-comp-time (caar (car appt-time-msg-list)))))))= ))) (defun appt-sort-list (appt-list) "Sort an appointment list, putting earlier items at the front. APPT-LIST is a list of the same format as `appt-time-msg-list'." (sort appt-list (lambda (e1 e2) (< (caar e1) (caar e2))))) (defun appt-convert-time (time2conv) "Convert hour:min[am/pm] format TIME2CONV to minutes from midnight. A period (.) can be used instead of a colon (:) to separate the hour and minute parts." ;; Formats that should be accepted: ;; 10:00 10.00 10h00 10h 10am 10:00am 10.00am (let ((min (if (string-match "[h:.]\\([0-9][0-9]\\)" time2conv) (string-to-number (match-string 1 time2conv)) 0)) (hr (if (string-match "[0-9]*[0-9]" time2conv) (string-to-number (match-string 0 time2conv)) 0))) ;; Convert the time appointment time into 24 hour time. (cond ((and (string-match "pm" time2conv) (< hr 12)) (setq hr (+ 12 hr))) ((and (string-match "am" time2conv) (=3D hr 12)) (setq hr 0))) ;; Convert the actual time into minutes. (+ (* hr 60) min))) (defun appt-update-list () "If the current buffer is visiting the diary, update appointments. This function also acts on any file listed in `diary-included-files'. It is intended for use with `write-file-functions'." (and (member buffer-file-name (append diary-included-files (list (expand-file-name diary-file)= ))) appt-timer (let ((appt-display-diary nil)) (appt-check t))) nil) ;; In Emacs-21.3, the manual documented the following procedure to ;; activate this package: ;; (display-time) ;; (add-hook 'diary-hook 'appt-make-list) ;; (diary 0) ;; The display-time call was not necessary, AFAICS. ;; What was really needed was to add the hook and load this file. ;; Calling (diary 0) once the hook had been added was in some sense a ;; roundabout way of loading this file. This file used to have code at ;; the top-level that set up the appt-timer and global-mode-string. ;; One way to maintain backwards compatibility would be to call ;; (appt-activate 1) at top-level. However, this goes against the ;; convention that just loading an Emacs package should not activate ;; it. Instead, we make appt-make-list activate the package (after a ;; suggestion from rms). This means that one has to call diary in ;; order to get it to work, but that is in line with the old (weird, ;; IMO) documented behavior for activating the package. ;; Actually, since (diary 0) does not run diary-hook, I don't think ;; the documented behavior in Emacs-21.3 would ever have worked. ;; Oh well, at least with the changes to appt-make-list it will now ;; work as well as it ever did. ;; The new method is just to use (appt-activate 1). ;; -- gmorris ;;;###autoload (defun appt-activate (&optional arg) "Toggle checking of appointments. With optional numeric argument ARG, turn appointment checking on if ARG is positive, otherwise off." (interactive "P") (let ((appt-active appt-timer)) (setq appt-active (if arg (> (prefix-numeric-value arg) 0) (not appt-active))) (remove-hook 'write-file-functions 'appt-update-list) (or global-mode-string (setq global-mode-string '(""))) (delq 'appt-mode-string global-mode-string) (when appt-timer (cancel-timer appt-timer) (setq appt-timer nil)) (when appt-active (add-hook 'write-file-functions 'appt-update-list) (setq appt-timer (run-at-time t 60 'appt-check) global-mode-string (append global-mode-string '(appt-mode-string))) (appt-check t)))) ;;; Test functions ;; two helper functions for tests ;; (defun appt-test-add (min-from-now msg warntime) ;; (appt-add ;; (format-time-string ;; "%H:%M" ;; (let ((time (current-time))) ;; (cons (nth 0 time) ;; (+ (* 60 min-from-now) (nth 1 time))))) msg warntime)) ;; (defun appt-test-init () ;; (setq appt-display-count 0) ;; (setq appt-display-interval 1) ;; (setq appt-time-msg-list nil)) ;; appointment in a minute ;; (progn ;; (appt-test-init) ;; (add-appt 1 "one minute" 1)) ;; two appointment one after the other, it should display: ;; 1 first ;; 2 first and second ;; 3 second ;; (progn ;; (appt-test-init) ;; (add-appt 1 "first" 1) ;; (add-appt 2 "second" 1)) ;; typical shadowing problem solved by multiple appointments. The ;; second appointment has warning time that precedes the first. I have ;; actually missed an appointment because of this! It should display: ;; 1 second ;; 2 first and second ;; 3 first and second ;; 4 second ;; (progn ;; (appt-test-init) ;; (add-appt 2 "first" 1) ;; (add-appt 3 "second" 3)) (provide 'appt) ;; arch-tag: bf5791c4-8921-499e-a26f-772b1788d347 ;;; appt.el ends here --=-=-=--