emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Philippe Crama <phcrama.ebiz@gmx.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db
Date: Wed, 10 Jun 2015 11:25:46 +0200	[thread overview]
Message-ID: <7za8w7j4o5.wl-phcrama.ebiz@gmx.com> (raw)

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

===File c:/msys64/tmp/org-mode/0001-org-contacts.el-Catch-nextfile-in-org-contacts-db.patch===
From 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 (length 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 here
+                ;; and skip processing the file.
+                ;;
+                ;; TODO: suppose that the user has set an org-contacts-files
+                ;; list that contains an element that doesn't exist in the
+                ;; file system: in that case, the org-agenda-files list could
+                ;; be updated (and saved to the customizations of the user) if
+                ;; it contained the same file even though the org-agenda-files
+                ;; 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))
-- 
2.3.5

============================================================

             reply	other threads:[~2015-06-10  9:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10  9:25 Philippe Crama [this message]
2015-06-21 16:14 ` [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db Daimrod
2015-06-23 21:49 ` Nicolas Goaziou
     [not found] <trinity-55a13834-abf3-4572-9c5a-fd0b5f8c5cd6-1435130389011@3capp-mailcom-bs13>
2015-06-25 11:01 ` phcrama.ebiz
2015-07-01 15:39   ` Daimrod
2015-07-04 21:12     ` phcrama.ebiz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7za8w7j4o5.wl-phcrama.ebiz@gmx.com \
    --to=phcrama.ebiz@gmx.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).