From 80865bab6464e9830ecb43a3023e470418ec77af Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 27 Apr 2020 23:31:05 +0200 Subject: [PATCH] Improve SETUPFILE error handling * lisp/org.el (org-file-contents): Return nil when NOERROR is non-nil and an error is raised. (org--collect-keywords-1): Do not raise an error when an invalid SETUPFILE keyword is met. --- lisp/org.el | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 2b0c18e5b..a14e2c379 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4497,13 +4497,15 @@ directory." (with-temp-buffer (unless uri-is-url (setq default-directory (file-name-directory uri))) - (insert (org-file-contents uri 'noerror)) - (let ((org-inhibit-startup t)) (org-mode)) - (setq alist - (org--collect-keywords-1 - keywords unique directory - (cons uri files) - alist))))))) + (let ((contents (org-file-contents uri :noerror))) + (when contents + (insert contents) + (let ((org-inhibit-startup t)) (org-mode)) + (setq alist + (org--collect-keywords-1 + keywords unique directory + (cons uri files) + alist))))))))) (keyword (let ((entry (assoc keyword alist)) (final @@ -4631,7 +4633,7 @@ already cached in the `org--file-cache' hash table, the download step is skipped. If NOERROR is non-nil, ignore the error when unable to read the FILE -from file or URL. +from file or URL, and return nil. If NOCACHE is non-nil, do a fresh fetch of FILE even if cached version is available. This option applies only if FILE is a URL." @@ -4655,7 +4657,8 @@ is available. This option applies only if FILE is a URL." org--file-cache) (funcall (if noerror #'message #'user-error) "Unable to fetch file from %S" - file)))) + file) + nil))) (t (with-temp-buffer (condition-case nil @@ -4665,7 +4668,8 @@ is available. This option applies only if FILE is a URL." (file-error (funcall (if noerror #'message #'user-error) "Unable to read file %S" - file)))))))) + file) + nil))))))) (defun org-extract-log-state-settings (x) "Extract the log state setting from a TODO keyword string.