From c6142346888d43fc0d2f828818bc15dbccd59b72 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 16 Dec 2021 11:14:59 +0800 Subject: [PATCH 1/2] ob-gnuplot: Use org backend when assigning table to variable * lisp/ob-gnuplot.el (org-babel-gnuplot-table-to-data): Switch to 'org backend when exporting table data to plain text table. ascii backend incorrectly handles quote transcoders that change the column width and sometimes throws an error. (ascii backend simply ignores transcoded table cells and calculates width based on the initial cell text). --- lisp/ob-gnuplot.el | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index 8c4a5957b..b72126ae5 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -287,11 +287,21 @@ Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE." (with-temp-file data-file (insert (let ((org-babel-gnuplot-timestamp-fmt (or (plist-get params :timefmt) "%Y-%m-%d-%H:%M:%S"))) - (orgtbl-to-generic - table - (org-combine-plists - '(:sep "\t" :fmt org-babel-gnuplot-quote-tsv-field :raw t :backend ascii) - params))))) + (replace-regexp-in-string + ;; org export backend adds "|" at the beginning/end of + ;; the table lines. Strip those. + "^|\\(.+\\)|$" + "\\1" + (orgtbl-to-generic + table + (org-combine-plists + '( :sep "\t" :fmt org-babel-gnuplot-quote-tsv-field + ;; Two setting below are needed to make :fmt work. + :raw t + ;; Use `org', not `ascii' because `ascii' may + ;; sometimes mishandle quoted strings. + :backend org) + params)))))) data-file) (provide 'ob-gnuplot) From eb9f34222a20d1c614c2b7fc7696bfcad248118d Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 17 Dec 2021 10:17:40 +0800 Subject: [PATCH 2/2] ob-gnuplot: Fix regression from 23d8d59df when ox-org is not loaded * lisp/ob-gnuplot.el (org-babel-gnuplot-table-to-data): Require ox-org, making sure that org export backend is available. --- lisp/ob-gnuplot.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/ob-gnuplot.el b/lisp/ob-gnuplot.el index b72126ae5..17af2ae5b 100644 --- a/lisp/ob-gnuplot.el +++ b/lisp/ob-gnuplot.el @@ -284,6 +284,7 @@ then create one. Return the initialized session. The current (defun org-babel-gnuplot-table-to-data (table data-file params) "Export TABLE to DATA-FILE in a format readable by gnuplot. Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE." + (require 'ox-org) (with-temp-file data-file (insert (let ((org-babel-gnuplot-timestamp-fmt (or (plist-get params :timefmt) "%Y-%m-%d-%H:%M:%S")))