From: phcrama.ebiz@gmx.com
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db
Date: Thu, 25 Jun 2015 13:01:56 +0200 [thread overview]
Message-ID: <395DF5E7-3C6F-4CDD-8A88-8D1525BBE5AC@gmx.com> (raw)
In-Reply-To: <trinity-55a13834-abf3-4572-9c5a-fd0b5f8c5cd6-1435130389011@3capp-mailcom-bs13>
[-- Attachment #1.1: Type: text/plain, Size: 390 bytes --]
Hi Nicolas and Greg,
Thank you for applying my initial patch.
Inspired by Greg's improvements to my patch, I'd like to propose the attached (presumptuously named) better-patch that I believe fixes the TODO of my initial patch.
Sorry it isn't quite in the format of the previous one/recommended by the project but I'm not on my main machine now.
Best regards,
--
Philippe Crama
[-- Attachment #1.2: Type: text/html, Size: 446 bytes --]
[-- Attachment #2: 0001-org-contacts.el-Handle-missing-files-in-org-contacts(1).patch --]
[-- Type: application/octet-stream, Size: 1967 bytes --]
From b3bb252c6e2138fa65b7c960060d68ea8c260873 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gregoire.jadi@univ-nantes.fr>
Date: Mon, 15 Jun 2015 09:36:36 +0200
Subject: [PATCH] org-contacts.el: Handle missing files in `org-contacts-files'
gracefully
* contrib/lisp/org-contacts.el (org-contacts-files): Catch 'nextfile
From `org-check-agenda-file' and update `org-contacts-files' if
modified.
(org-contacts-db): Don't call `org-check-agenda-file' now called in
`org-contacts-files'.
When `org-agenda-files' contains non-existent files, remove them if
the user asks for it instead of failing.
Modified from a patch proposal by Philippe Crama
---
contrib/lisp/org-contacts.el | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index bc07fc1..3e14c7e 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -227,7 +227,12 @@ A regexp matching strings of whitespace, `,' and `;'.")
(defun org-contacts-files ()
"Return list of Org files to use for contact management."
- (or org-contacts-files (org-agenda-files t 'ifmode)))
+ (org-remove-if (lambda (file)
+ (when (catch 'nextfile
+ (org-check-agenda-file file))
+ (customize-save-variable 'org-contacts-files
+ (delete file org-contacts-files))))
+ (or org-contacts-files (org-agenda-files t 'ifmode))))
(defun org-contacts-db-need-update-p ()
"Determine whether `org-contacts-db' needs to be refreshed."
@@ -261,7 +266,6 @@ 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))
--
1.9.1
[-- Attachment #3: better-patch --]
[-- Type: application/octet-stream, Size: 2648 bytes --]
--- org.el Fri Jun 19 12:07:26 2015
+++ org-modif.el Wed Jun 24 09:13:10 2015
@@ -18097,17 +18097,28 @@
(defun org-file-menu-entry (file)
(vector file (list 'find-file file) t))
-(defun org-check-agenda-file (file)
- "Make sure FILE exists. If not, ask user what to do."
+(defun org-check-agenda-file-1 (file)
+ "Make sure FILE exists. If not, ask user what to do.
+
+Possible outcomes:
+1. File exists -> return NIL.
+2. File doesn't exist and user requests to remove it -> throws 'nextfile.
+3. File doesn't exist and user requests to remove it -> raise error \"Abort\".
+
+You probably want `org-check-agenda-file'."
(when (not (file-exists-p file))
(message "Non-existent agenda file %s. [R]emove from list or [A]bort?"
(abbreviate-file-name file))
(let ((r (downcase (read-char-exclusive))))
(cond
((equal r ?r)
- (org-remove-file file)
(throw 'nextfile t))
(t (error "Abort"))))))
+
+(defun org-check-agenda-file (file)
+ "Make sure FILE exists, else if user agrees, remove FILE from `org-agenda-files'."
+ (when (catch 'nextfile (org-check-agenda-file-1 file))
+ (org-remove-file file)))
(defun org-get-agenda-file-buffer (file)
"Get a buffer visiting FILE. If the buffer needs to be created, add
--- org-contacts.el Fri Jun 19 12:07:20 2015
+++ org-contacts-modif.el Wed Jun 24 09:13:56 2015
@@ -216,7 +216,18 @@
(defun org-contacts-files ()
"Return list of Org files to use for contact management."
- (or org-contacts-files (org-agenda-files t 'ifmode)))
+ (if org-contacts-files
+ (org-remove-if (lambda (file)
+ (when (catch 'nextfile
+ (org-check-agenda-file-1 file))
+ (customize-save-variable 'org-contacts-files
+ (delete file org-contacts-files))))
+ org-contacts-files)
+ (let (result)
+ (dolist (file (org-agenda-files t 'ifmode) (nreverse result))
+ (unless (catch 'nextfile
+ (org-check-agenda-file file))
+ (push file result))))))
(defun org-contacts-db-need-update-p ()
"Determine whether `org-contacts-db' needs to be refreshed."
@@ -250,7 +261,6 @@
(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 no in `org-mode'" file))
next parent reply other threads:[~2015-06-25 11:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <trinity-55a13834-abf3-4572-9c5a-fd0b5f8c5cd6-1435130389011@3capp-mailcom-bs13>
2015-06-25 11:01 ` phcrama.ebiz [this message]
2015-07-01 15:39 ` [PATCH] org-contacts.el: Catch 'nextfile in org-contacts-db Daimrod
2015-07-04 21:12 ` phcrama.ebiz
2015-06-10 9:25 Philippe Crama
2015-06-21 16:14 ` Daimrod
2015-06-23 21:49 ` Nicolas Goaziou
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=395DF5E7-3C6F-4CDD-8A88-8D1525BBE5AC@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).