From 0db972ad63859c3220ecc9d236003071bc474d6f Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 10 Dec 2022 21:36:58 +0800 Subject: [PATCH 1/6] ox: Handle failure to localize link * lisp/ox.el (org-export-link-localise): When no local copy of the link resource could be fetched, produce a warning message and do nothing instead of setting the link :path to nil. --- lisp/ox.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lisp/ox.el b/lisp/ox.el index c14eafe44..737703f11 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4612,12 +4612,17 @@ If LINK refers to a remote resource, modify it to point to a local downloaded copy. Otherwise, return unchanged LINK." (when (org-export-link-remote-p link) (let* ((local-path (org-export-link--remote-local-copy link))) - (setcdr link - (thread-first (cadr link) - (plist-put :type "file") - (plist-put :path local-path) - (plist-put :raw-link (concat "file:" local-path)) - list)))) + (if local-path + (setcdr link + (thread-first (cadr link) + (plist-put :type "file") + (plist-put :path local-path) + (plist-put :raw-link (concat "file:" local-path)) + list)) + (display-warning + '(org export) + (format "unable to obtain local copy of %s" + (org-element-property :raw-link link)))))) link) ;;;; For References From 88329143c86b34195af68a8e5d5fd3d00a5dcae6 Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 10 Dec 2022 21:38:21 +0800 Subject: [PATCH 2/6] org: Use buffer-base-buffer in safe resource fns * lisp/org.el (org--confirm-resource-safe, org--safe-remote-resource-p): Replace instances of buffer-file-name with (buffer-file-name (buffer-base-buffer)) so these functions work in indirect buffers. --- lisp/org.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 641720001..6aa2a1621 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4597,8 +4597,8 @@ is available. This option applies only if FILE is a URL." This checks every pattern in `org-safe-remote-resources', and returns non-nil if any of them match." (let ((uri-patterns org-safe-remote-resources) - (file-uri (and buffer-file-name - (concat "file://" (file-truename buffer-file-name)))) + (file-uri (and (buffer-file-name (buffer-base-buffer)) + (concat "file://" (file-truename (buffer-file-name (buffer-base-buffer)))))) match-p) (while (and (not match-p) uri-patterns) (setq match-p (or (string-match-p (car uri-patterns) uri) @@ -4609,7 +4609,8 @@ returns non-nil if any of them match." (defun org--confirm-resource-safe (uri) "Ask the user if URI should be considered safe, returning non-nil if so." (unless noninteractive - (let ((current-file (and buffer-file-name (file-truename buffer-file-name))) + (let ((current-file (and (buffer-file-name (buffer-base-buffer)) + (file-truename (buffer-file-name (buffer-base-buffer))))) (domain (and (string-match (rx (seq "http" (? "s") "://") (optional (+ (not (any "@/\n"))) "@") From 6a126e40a7c65d6a7644939029a140d47ecb8f79 Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 10 Dec 2022 23:58:55 +0800 Subject: [PATCH 3/6] org-persist: Ensure index instantiated before read * lisp/org-persist.el (org-persist-read): If the index is empty at the start of `org-persist-read', load it before continuing. --- lisp/org-persist.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/org-persist.el b/lisp/org-persist.el index 1a32ed010..fe339505c 100644 --- a/lisp/org-persist.el +++ b/lisp/org-persist.el @@ -771,6 +771,7 @@ ASSOCIATED can be a plist, a buffer, or a string. A buffer is treated as (:buffer ASSOCIATED). A string is treated as (:file ASSOCIATED). When LOAD? is non-nil, load the data instead of reading." + (unless org-persist--index (org-persist--load-index)) (setq associated (org-persist--normalize-associated associated)) (setq container (org-persist--normalize-container container)) (unless (and org-persist-disable-when-emacs-Q From 402d2421d92be0a3c6b6960f1eb7c605e384ff53 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 11 Dec 2022 01:41:39 +0800 Subject: [PATCH 4/6] org-persist: Do not re-download url files on write * lisp/org-persist.el (org-persist-write:url): Since the url write function is called as part of `org-persist-write-all', it is worth adding a check to avoid re-downloading the file if a file already exists in the expected location. --- lisp/org-persist.el | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lisp/org-persist.el b/lisp/org-persist.el index fe339505c..30c5e17d4 100644 --- a/lisp/org-persist.el +++ b/lisp/org-persist.el @@ -662,12 +662,13 @@ COLLECTION is the plist holding data collection." (file-copy (org-file-name-concat org-persist-directory (format "%s-%s.%s" persist-file (md5 path) ext)))) - (unless (file-exists-p (file-name-directory file-copy)) - (make-directory (file-name-directory file-copy) t)) - (if (org--should-fetch-remote-resource-p path) - (url-copy-file path file-copy 'overwrite) - (error "The remote resource %S is considered unsafe, and will not be downloaded." - path)) + (unless (file-exists-p file-copy) + (unless (file-exists-p (file-name-directory file-copy)) + (make-directory (file-name-directory file-copy) t)) + (if (org--should-fetch-remote-resource-p path) + (url-copy-file path file-copy 'overwrite) + (error "The remote resource %S is considered unsafe, and will not be downloaded." + path))) (format "%s-%s.%s" persist-file (md5 path) ext))))) (defun org-persist-write:index (container _) From fec15dedb942eacd0a7684de71d319f751fd74c5 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Tue, 6 Dec 2022 08:31:32 +0100 Subject: [PATCH 5/6] test-ob-R.el: New function to test for :result output * test-ob-R.el (ob-session-R-result-output): This test will check if output is printed to buffer in a session with :results output. This test is to prevent the bug mentioned in https://list.orgmode.org/877czca7oj.fsf@u-bordeaux.fr/ does not happen again. --- testing/lisp/test-ob-R.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/testing/lisp/test-ob-R.el b/testing/lisp/test-ob-R.el index f6143b994..da142fb3c 100644 --- a/testing/lisp/test-ob-R.el +++ b/testing/lisp/test-ob-R.el @@ -246,8 +246,20 @@ log10(10) (string= (concat src-block result) (buffer-string))))))) - - +; add test for :result output +(ert-deftest ob-session-R-result-output () + (let (ess-ask-for-ess-directory + ess-history-file + org-confirm-babel-evaluate + (org-babel-temporary-directory "/tmp") + (src-block "#+begin_src R :session R :results output \n 1:3\n#+end_src") + (result "\n\n#+RESULTS:\n: [1] 1 2 3\n" )) + (org-test-with-temp-text + src-block + (should (progn (org-babel-execute-src-block) + (sleep-for 0 200) + (string= (concat src-block result) + (buffer-string))))))) (provide 'test-ob-R) From 662e814bc067153c74aeba5f882d547e327db8b4 Mon Sep 17 00:00:00 2001 From: Jeremie Juste Date: Wed, 7 Dec 2022 21:25:19 +0100 Subject: [PATCH 6/6] ob-R.el: Restore the handling of org-list in as var * ob-R.el (org-babel-R-assign-elisp): Use the patch from ccberry@health.ucsd.edu, to print org-list as a one column table as it was the case in release_9.5. The break in R is due commit b4e437f96 * ob-core: Resolve named list references to simple lists. * test-ob-R.el (ob-R-nested-list): New function to test that org list with multiple level are handled as expected in R. see https://list.orgmode.org/87bkofh0ir.fsf@localhost/ for context. --- lisp/ob-R.el | 4 ++-- testing/lisp/test-ob-R.el | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index f68b5b44e..b7f96a179 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -241,11 +241,11 @@ This function is called by `org-babel-execute-src-block'." (defun org-babel-R-assign-elisp (name value colnames-p rownames-p) "Construct R code assigning the elisp VALUE to a variable named NAME." (if (listp value) - (let* ((lengths (mapcar 'length (cl-remove-if-not 'sequencep value))) + (let* ((lengths (mapcar 'length (cl-remove-if-not 'listp value))) (max (if lengths (apply 'max lengths) 0)) (min (if lengths (apply 'min lengths) 0))) ;; Ensure VALUE has an orgtbl structure (depth of at least 2). - (unless (listp (car value)) (setq value (list value))) + (unless (listp (car value)) (setq value (mapcar 'list value))) (let ((file (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field))) (header (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE")) diff --git a/testing/lisp/test-ob-R.el b/testing/lisp/test-ob-R.el index da142fb3c..cbd5a36a2 100644 --- a/testing/lisp/test-ob-R.el +++ b/testing/lisp/test-ob-R.el @@ -261,6 +261,41 @@ log10(10) (string= (concat src-block result) (buffer-string))))))) + +;; test for printing of (nested) list +(ert-deftest ob-R-nested-list () + "List are printed as the first column of a table and nested lists are ignored" + (let (ess-ask-for-ess-directory + ess-history-file + org-confirm-babel-evaluate + (org-babel-temporary-directory "/tmp") + (text " +#+NAME: example-list +- simple + - not + - nested +- list + +#+BEGIN_SRC R :var x=example-list +x +#+END_SRC +") +(result " +#+RESULTS: +| simple | +| list | +")) +(org-test-with-temp-text-in-file + text + (goto-char (point-min)) + (org-babel-next-src-block) + (should (progn + (org-babel-execute-src-block) + (sleep-for 0 200) + (string= (concat text result) + (buffer-string))))))) + + (provide 'test-ob-R) ;;; test-ob-R.el ends here