From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?Q?=C3=98yvind?= Stegard Subject: [PATCH] org-contacts: Update contacts cache if it contains markers with no buffer Date: Fri, 12 Jul 2013 13:07:13 +0200 Message-ID: <878v1cdoke.fsf.rednorrock@ifi.uio.no> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxbC9-00035R-Lk for emacs-orgmode@gnu.org; Fri, 12 Jul 2013 07:07:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UxbC4-0005ri-69 for emacs-orgmode@gnu.org; Fri, 12 Jul 2013 07:07:25 -0400 Received: from mail-out1.uio.no ([129.240.10.57]:36577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UxbC3-0005r4-Rf for emacs-orgmode@gnu.org; Fri, 12 Jul 2013 07:07:20 -0400 Received: from mail-mx2.uio.no ([129.240.10.30]) by mail-out1.uio.no with esmtp (Exim 4.75) (envelope-from ) id 1UxbBz-0005Bw-GL for emacs-orgmode@gnu.org; Fri, 12 Jul 2013 13:07:15 +0200 Received: from 1x-193-157-194-194.uio.no ([193.157.194.194] helo=rednorrock.local) by mail-mx2.uio.no with esmtpsa (TLSv1.2:DHE-RSA-AES128-SHA:128) user oyvinst (Exim 4.80) (envelope-from ) id 1UxbBy-0007lN-TU for emacs-orgmode@gnu.org; Fri, 12 Jul 2013 13:07:15 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi list, In contrib/lisp/org-contacts.el: The function `org-contacts-db-need-update-p' does two checks to determine if the contacts cache should be updated: 1. If the variable `org-contacts-last-update' is nil. 2. If modification time of any file containing contacts is more recent than timestamp recorded in `org-contacts-last-update'. There is another case where an update is required: when marker objects contained in the contact cache `org-contacts-db' suddenly point to no buffer. If a buffer containing contacts is killed, but underlying file is not modified, org-contacts will not detect this, and cached markers that pointed to the now killed buffer will become dead (have no buffer associated with them). This seems to cause problems at least in `org-contacts-anniversaries', which if used as diary sexp in an agenda file, will cause "Bad sexp" errors. I have not done any thorough analysis of `org-contacts-anniversaries' itself, but it seems to work OK whenever the markers in `org-contacts-db' are OK. And it looks like the markers are used in that code. To reproduce: 1. Load up org-contacts and do a query with "M-x org-contacts". 2. Kill at least one org-buffer containing a contact with BIRTHDAY property set (but do not save underlying file). 3. Make sure to use %%(org-contacts-anniversaries) in some agenda file. 4. Opening agenda should produce a "Bad sexp" error. I've attached a patch (against git master) which I am currently using. It will cause org-contacts to re-load if a marker is found in cache that points to no buffer. This looked to me like the quickest approach for fixing it without getting to know org-contacts.el better. Regards, =C3=98yvind --=20 < =C3=98yvind Stegard < http://stegard.net/ --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-org-contacts-Ensure-contacts-cache-updated-on-dead-markers.patch >From e8d5f9ab71f75e5f5087d47e2e86115584db4a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Stegard?= Date: Fri, 12 Jul 2013 12:17:12 +0200 Subject: [PATCH] org-contacts: Ensure contacts cache is updated if it contains markers with no buffer * contrib/lisp/org-contacts.el (org-contacts-db-need-update-p): Check if org-contacts-db cache contains markers with no buffer as well, when determining if cache should be updated from files. The function `org-contacts-db-need-update-p' does two checks to determine if the contacts cache should be updated: 1. If the variable `org-contacts-last-update' is nil. 2. If modification time of any file containing contacts is more recent than timestamp recorded in `org-contacts-last-update'. There is another case where an update is required: when marker objects contained in the contact cache `org-contacts-db' suddenly point to no buffer. If a buffer containing contacts is killed, but underlying file is not modified, org-contacts will not detect this, and cached markers that pointed to the now killed buffer will become "dead" (e.g. have no buffer associated with them). This seems to cause problems for instance in `org-contacts-anniversaries', which if used as diary sexp in agenda file, will cause "Bad sexp" errors. --- contrib/lisp/org-contacts.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 71f7bf4..a220993 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -224,7 +224,20 @@ A regexp matching strings of whitespace, `,' and `;'.") (org-find-if (lambda (file) (or (time-less-p org-contacts-last-update (elt (file-attributes file) 5)))) - (org-contacts-files)))) + (org-contacts-files)) + (org-contacts-db-has-dead-markers-p org-contacts-db))) + +(defun org-contacts-db-has-dead-markers-p (org-contacts-db) + "Returns t if at least one dead marker is found in +ORG-CONTACTS-DB. A dead marker in this case is a marker pointing +to dead or no buffer." + ;; Scan contacts list looking for dead markers, and return t at first found. + (catch 'dead-marker-found + (while org-contacts-db + (unless (marker-buffer (nth 1 (car org-contacts-db))) + (throw 'dead-marker-found t)) + (setq org-contacts-db (cdr org-contacts-db))) + nil)) (defun org-contacts-db () "Return the latest Org Contacts Database." -- 1.8.1.2 --=-=-=--