[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org edb5eaaac3 2/2: org-babel-read: Allow reading multi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org edb5eaaac3 2/2: org-babel-read: Allow reading multi-line strings |
Date: |
Sat, 4 May 2024 09:58:35 -0400 (EDT) |
branch: externals/org
commit edb5eaaac3484195bfb391e65f9c678d5d3d123a
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
org-babel-read: Allow reading multi-line strings
* lisp/ob-core.el (org-babel-read): Fix regexp for detecting
string-like CELLs. Avoid calling `read' twice. Recover gracefully if
`read' errs.
* testing/lisp/test-ob.el (test-ob/org-babel-read): Add more tests.
Reported-by: Max Nikulin <manikulin@gmail.com>
Link: https://orgmode.org/list/v155g2$ncm$1@ciao.gmane.io
---
lisp/ob-core.el | 27 +++++++++++++++++----------
testing/lisp/test-ob.el | 3 +++
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index d7f6241cbe..082e9bd9e9 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -3360,16 +3360,23 @@ situations in which is it not appropriate."
(string= cell "*this*")))
;; FIXME: Arbitrary code evaluation.
(eval (read cell) t))
- ((save-match-data
- (and (string-match "^[[:space:]]*\"\\(.*\\)\"[[:space:]]*$" cell)
- ;; CELL is a single string
- (with-temp-buffer
- (insert cell)
- (goto-char 1)
- (read (current-buffer))
- (skip-chars-forward "[:space:]")
- (eobp))))
- (read cell))
+ ((let (read-val)
+ (save-match-data
+ (and (string-match
+ (rx bos (0+ space)
+ ?\" (0+ anychar) ?\"
+ (0+ space) eos)
+ cell)
+ ;; CELL is a single string
+ (with-temp-buffer
+ (insert cell)
+ (goto-char 1)
+ (when (setq read-val
+ (ignore-errors
+ (read (current-buffer))))
+ (skip-chars-forward "[:space:]")
+ (eobp)))
+ read-val))))
(t (org-no-properties cell))))
(defun org-babel--string-to-number (string)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index da11258f2d..30ce2875c6 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -2599,6 +2599,9 @@ abc
;; Special case: data inside quotes
(should (equal "foo" (org-babel-read " \"foo\" " inhibit)))
(should (equal "foo with\" inside" (org-babel-read " \"foo with\\\"
inside\" " inhibit)))
+ (should (equal "abc\nsdf" (org-babel-read "\"abc\nsdf\"" inhibit)))
+ (should (equal "foo" (org-babel-read "\"foo\"" inhibit)))
+ (should (equal "\"foo\"(\"bar\"" (org-babel-read "\"foo\"(\"bar\""
inhibit)))
;; Unpaired quotes
(should (equal "\"foo\"\"bar\"" (org-babel-read "\"foo\"\"bar\""
inhibit)))))