From mboxrd@z Thu Jan  1 00:00:00 1970
From: Philippe Crama <phcrama.ebiz@gmx.com>
Subject: [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db
Date: Wed, 10 Jun 2015 11:25:46 +0200
Message-ID: <7za8w7j4o5.wl-phcrama.ebiz@gmx.com>
Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue")
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org>
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35615)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <phcrama.ebiz@gmx.com>) id 1Z2cGg-00086v-OD
	for emacs-orgmode@gnu.org; Wed, 10 Jun 2015 05:25:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <phcrama.ebiz@gmx.com>) id 1Z2cGc-0006Eo-Mh
	for emacs-orgmode@gnu.org; Wed, 10 Jun 2015 05:25:54 -0400
Received: from mout.gmx.net ([212.227.15.19]:58649)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <phcrama.ebiz@gmx.com>) id 1Z2cGc-0006E3-DJ
	for emacs-orgmode@gnu.org; Wed, 10 Jun 2015 05:25:50 -0400
Received: from localhost ([109.134.218.131]) by mail.gmx.com (mrgmx003) with
	ESMTPSA (Nemesis) id 0LsCAp-1ZBOQF1Mdj-013uex for
	<emacs-orgmode@gnu.org>; Wed, 10 Jun 2015 11:25:48 +0200
List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode>
List-Post: <mailto:emacs-orgmode@gnu.org>
List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>,
	<mailto:emacs-orgmode-request@gnu.org?subject=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

Hi,

This is a small patch to catch the 'nextfile thrown by
`org-check-agenda-file' in `org-contacts-db'.

I don't know how to fix the TODO in the comment myself, sorry.  At
least, with the patch, the execution doesn't abort anymore.

Regards,
--
Philippe Crama

=3D=3D=3DFile c:/msys64/tmp/org-mode/0001-org-contacts.el-Catch-nextfile-in=
-org-contacts-db.patch=3D=3D=3D
=46rom 6f9679f2118fa8990386a0ed27a34d329cfc579f Mon Sep 17 00:00:00 2001
From: "U-mathilde\\philippe" <phcrama.ebiz@gmx.com>
Date: Wed, 10 Jun 2015 11:05:47 +0200
Subject: [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db

* org-contacts.el (org-contacts-db): Catch 'nextfile in org-contacts-db
(org-contacts-db): when a file in the list returned by the
`org-contacts-files' function doesn't exist and the user selects the
option to attempt to remove it from the `org-agenda-files' list, 'nextfile
is thrown.  Catch it and skip processing that file instead of failing.

TINYCHANGE
---
 contrib/lisp/org-contacts.el | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index bc07fc1..edc09fe 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -261,16 +261,37 @@ to dead or no buffer."
 	     (make-progress-reporter "Updating Org Contacts Database..." 0 (lengt=
h org-contacts-files)))
 	    (i 0))
 	(dolist (file (org-contacts-files))
-	  (org-check-agenda-file file)
-	  (with-current-buffer (org-get-agenda-file-buffer file)
-	    (unless (eq major-mode 'org-mode)
-	      (error "File %s is not in `org-mode'" file))
-	    (setf result
-		  (append result
-			  (org-scan-tags
-			   'org-contacts-at-point
-			   contacts-matcher
-			   todo-only))))
+	  (if (catch 'nextfile
+                ;; if file doesn't exist and the user agrees to removing it
+                ;; from org-agendas-list, 'nextfile is thrown.  Catch it h=
ere
+                ;; and skip processing the file.
+                ;;
+                ;; TODO: suppose that the user has set an org-contacts-fil=
es
+                ;; list that contains an element that doesn't exist in the
+                ;; file system: in that case, the org-agenda-files list co=
uld
+                ;; be updated (and saved to the customizations of the user=
) if
+                ;; it contained the same file even though the org-agenda-f=
iles
+                ;; list wasn't actually used.  I don't think it is normal =
that
+                ;; org-contacts updates org-agenda-files in this case, but
+                ;; short of duplicating org-check-agenda-files and
+                ;; org-remove-files, I don't know how to avoid it.
+                ;;
+                ;; A side effect of the TODO is that the faulty
+                ;; org-contacts-files list never gets updated and thus the
+                ;; user is always queried about the missing files when
+                ;; org-contacts-db-need-update-p returns true.
+                (org-check-agenda-file file))
+              (message "Skipped %s removed from org-agenda-files list."
+                       (abbreviate-file-name file))
+	    (with-current-buffer (org-get-agenda-file-buffer file)
+	      (unless (eq major-mode 'org-mode)
+		(error "File %s is not in `org-mode'" file))
+	      (setf result
+		    (append result
+			    (org-scan-tags
+			     'org-contacts-at-point
+			     contacts-matcher
+			     todo-only)))))
 	  (progress-reporter-update progress-reporter (setq i (1+ i))))
 	(setf org-contacts-db result
 	      org-contacts-last-update (current-time))
--=20
2.3.5

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D