From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id qLYYCypVbWdMGAEA62LTzQ:P1 (envelope-from ) for ; Thu, 26 Dec 2024 13:07:54 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id qLYYCypVbWdMGAEA62LTzQ (envelope-from ) for ; Thu, 26 Dec 2024 14:07:54 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Bvph4iCs; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1735218474; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=7LwuWuJOby4BzLDuM9rrNHibUMJxj7TIojFJT3gh3ok=; b=ukciLX9w1bOtyMGwQMGFOey5WICFEJUJjH609T+bfX0V22VahYuZDVe3XB3NoPMQqxURsN qx38LRwCVsm41HC6tPW1AROG1G27eMof8IQgn9zqHSiv7F5wTRMgeNivieoh9g29v6yvUN uHfgVwbC/SvXx3e5IDTqSuGFp+J3hgaZSky31u5cCmxv6so1lozkPhqlY6gaKCgYgtRrNR JWk5yBbi4Lfea+5l47rF5Gbe7iUcIkXsnzVcmWtgfcfXkhOxMKuJiwG90BjswzP9Lov2tJ +06pIQ3xxSpDG08rMycJdGgU4iyqYQ+WglzNCNQN4fxXJetTkMewNZjzaytSig== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Bvph4iCs; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1735218474; a=rsa-sha256; cv=none; b=p3/xPbTVidv4O6rGyldMO71ZkqfL64TcVEr4RXfAjEYDloT4AzYJiiT0y7mYlAkE0RQJ8O PNSutiVr7aYIjBlRMPyDh5cpF8pq3wD0qsERZU/lESH+f4WAZoIr04waBecDSBQvyLqB0g ns008FTmvO4PMebd0FT8uth46wYNyL7uijBvRTEQsWp/ER6jwGTiG3odQt4/1Zh79lthXd hWM78S2mpJKfrrKCPDzWHbwijxmF4IiiVZeQhmpIlnSEBJ7RO/2b481X3piwr2UsJcrJSw qsO/vpIhjpleudH60BS1Uz7zW/nDeN5whCA5cJf64dkl/dF10K2srA41laDfVQ== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D9E6487EDA for ; Thu, 26 Dec 2024 14:07:53 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQna0-0001HN-Jt; Thu, 26 Dec 2024 08:07:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQnZz-0001HE-Dp for emacs-orgmode@gnu.org; Thu, 26 Dec 2024 08:07:07 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tQnZx-0002yA-Bj for emacs-orgmode@gnu.org; Thu, 26 Dec 2024 08:07:07 -0500 Received: by mail-pl1-x642.google.com with SMTP id d9443c01a7336-2161eb95317so76676275ad.1 for ; Thu, 26 Dec 2024 05:07:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735218423; x=1735823223; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=7LwuWuJOby4BzLDuM9rrNHibUMJxj7TIojFJT3gh3ok=; b=Bvph4iCsXr9RRMp1r7ofbyBpB7djqw1pulzEwLvrfGAawye3e2nj8lxcEuuXZgeTk4 +ViEHgNguDSFPM9U2NFNe6kdxL/wzRciAnIqMwgZpfTCnsDk50kZhhszlbh5gcUyxCMu OE+qOeapYBDevWRZpVHmM+/2r66z8VTtDFH49YlFsWT8XlY6zgABXSPhMEooPOsNSYeW vyS5uRFnuHbpoMBF714Zz4rFZyM+Y9uvThOCJJa1hLsYIfMkiSXCFVxLDAyjMX0Ggr8L duVazc009sd+6zyIXeVA3BCDJyLnXL9aM4Ao5cWayGuEQc9JEE39TTn26/s1Ro/gDi5S FAmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735218423; x=1735823223; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7LwuWuJOby4BzLDuM9rrNHibUMJxj7TIojFJT3gh3ok=; b=eWGP5ZeudioTUQmlsP65oI2hV+JlW8PwOkgbOYYZKw5wFrTS82I3+2gQ4alq3AA3eL LDWdbCqcyHU81YyzmGKHmK9uZac6c9sIAeQRUdXVEYaP3twbE8zgIMHqgU33x8dmYpXP JAZD6IAZdcvNtMZIaumfs7sGiRvbe5tCfpPAEGDs1+InFyKd+MjRSuHXpE8BNfGYUDrk zeTBzl7brUEl50SxRZkulBnQKOsu3tCNFTlI6w/WM0hvrdyqX58g1pgvtMN/EFciJ9jF iR/8uy0gogFuu0lua9e+14wOmnlySECFpSy01mvzMy0b4lb+8yu1lPofGxw2KDlu/PuI yvQA== X-Gm-Message-State: AOJu0YwzMNMktllaHPCtfo5x+l+6iYkdISEvKdRsOsJDWS65wwCdW1Z/ LnM2f+bxsl20iGTeDwP98vrP5qQrDnsS6LYiymL6jztUKIkLpydS3OEdE33V X-Gm-Gg: ASbGncvT1GBB0V4JZuUxUXQQODwoIaoyjynOXZXMq6Xurd7+kyrmPFoPe1WCmStqicl fgaxjLj1XC/VYlueenUCJnaCcwJZXOGH2IpptlZS12qs3AL4yiPFyreKu57hB6DTYnTgbcZ8duO AzANu7ISHthrXLMXlrqUbHpjl6EpSCwweN2/Z1GfIeUTuSQ7ZJFTmbSSZtpF101VAvRPIY5bgwW kbfz7daNnT0UyVJLavbIqoaH4sY0le+dRHlibvK92ZhDSeLOAM= X-Google-Smtp-Source: AGHT+IFBBUg0+6gXSH5qjxQzW8+h8hhWSW0HOCpbC+11BGcDZmABAkK0kKhwD8xadmQI/k1EofhPsw== X-Received: by 2002:a17:902:dac6:b0:216:2426:7666 with SMTP id d9443c01a7336-219e6e89559mr286110555ad.12.1735218422623; Thu, 26 Dec 2024 05:07:02 -0800 (PST) Received: from localhost ([49.205.85.12]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dca02e3dsm116553155ad.282.2024.12.26.05.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Dec 2024 05:07:01 -0800 (PST) From: Visuwesh To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] ob-calc: Format vector and matrix results as Org table In-Reply-To: <877c7pibzv.fsf@localhost> (Ihor Radchenko's message of "Tue, 24 Dec 2024 10:58:12 +0000") References: <878qsj1kjl.fsf@gmail.com> <877c7pibzv.fsf@localhost> Date: Thu, 26 Dec 2024 18:36:58 +0530 Message-ID: <8734iaegp9.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::642; envelope-from=visuweshm@gmail.com; helo=mail-pl1-x642.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -7.77 X-Spam-Score: -7.77 X-Migadu-Queue-Id: D9E6487EDA X-TUID: koE4j8GmI56n --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [=E0=AE=9A=E0=AF=86=E0=AE=B5=E0=AF=8D=E0=AE=B5=E0=AE=BE=E0=AE=AF=E0=AF=8D = =E0=AE=9F=E0=AE=BF=E0=AE=9A=E0=AE=AE=E0=AF=8D=E0=AE=AA=E0=AE=B0=E0=AF=8D 24= , 2024] Ihor Radchenko wrote: > Visuwesh writes: > >> Attached patch formats vector and matrix results from a Calc source >> block as Org table. To test, try >> ... >> now. The patch passes the old tests, and I added three new tests to >> check the correctness of this conversion. > > Thanks! > > etc/ORG-NEWS entry seems to be displaced. It should be under Org 9.8 > heading. > > Also, the patch does not apply onto the latest main. > >> -#+BEGIN_SRC calc :results silent :var a=3Dob-calc-table-1 >> +#+BEGIN_SRC calc :results silent verbatim :var a=3Dob-calc-table= -1 > > You had to change the tests, so we have a breaking change. > > The change can be viewed as a bug fix since ob-calc previously did not > conform to babel conventions, so I do not object changing the defaults. > However, we need to inform the affected users and put the announcement > into "breaking changes" section. We should also recommend changing > org-babel-default-header-args:calc to restore the old behavior. Thanks, these should be fixed in the attached patch. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ob-calc-Format-vector-and-matrix-results-as-Org-tabl.patch >From 8ab27ec0c0732648d9c684decf8eda0e5e0ef1b5 Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Thu, 26 Dec 2024 18:36:24 +0530 Subject: [PATCH] ob-calc: Format vector and matrix results as Org tables * lisp/ob-calc.el: (org-babel-execute:calc): Format vector and matrix results as Org tables using the raw Calc object. * testing/lisp/test-ob-calc.el (ob-calc/matrix-inversion) (ob-calc/matrix-algebra, ob-calc/matrix-correct-conv-column) (ob-calc/matrix-correct-conv-row): Use ':results verbatim' for the old tests. (ob-calc/conv-scalar, ob-calc/conv-vector, ob-calc/conv-matrix): Add new tests to verify correct conversion of vector, matrix, and scalar results with ':results replace'. * etc/ORG-NEWS: Announce the new feature. Link: https://list.orgmode.org/878qsj1kjl.fsf@gmail.com --- etc/ORG-NEWS | 16 ++++++++++++++ lisp/ob-calc.el | 29 ++++++++++++++++++++----- testing/lisp/test-ob-calc.el | 42 ++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index f932c4ea2..f0112f33c 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -83,6 +83,22 @@ This should have minimal impact on non-iCalendar exporters, since users who manually set ~org-export-with-timestamps~ to ~active~ will now have diary timestamps included as well. +*** =ob-calc.el=: Vector and matrix are now inserted as Org tables by default + +~ob-calc~ now formats vector and matrix results as Org tables. This +conservation can be overriden using the ~:results verbatim~ keyword on +a per source block basis. + +To get back the old behaviour, add + +#+BEGIN_SRC emacs-lisp +(with-eval-after-load 'ob-calc + (setq org-babel-header-args:calc + (append '(:results . "verbatim") org-babel-header-args:calc))) +#+END_SRC + +to your configuration. + ** New features # We list the most important features, and the features that may diff --git a/lisp/ob-calc.el b/lisp/ob-calc.el index 171fd1b04..222c1f9be 100644 --- a/lisp/ob-calc.el +++ b/lisp/ob-calc.el @@ -114,11 +114,30 @@ (defun org-babel-execute:calc (body params) )))))) (mapcar #'org-trim (split-string (org-babel-expand-body:calc body params) "[\n\r]")))) - (save-excursion - (with-current-buffer "*Calculator*" - (prog1 - (calc-eval (calc-top 1)) - (calc-pop 1))))) + (let ((result (prog1 + ;; Cannot use 'top' as SEPARATOR reliably when the + ;; top of the stack has a vector. + (calc-eval (calc-top 1) 'raw) + (calc-eval 1 'pop))) + (calc-line-numbering) + lisp-table) + (org-babel-reassemble-table + (org-babel-result-cond (cdr (assq :result-params params)) + (calc-eval result) + (if (Math-vectorp result) + (progn + (dolist (r (if (math-matrixp result) + (cdr result) ; Ignore the 'vec item. + (list result))) + (setq r (cdr r)) ; Ignore the 'vec item. + (push (mapcar (lambda (x) (math-format-stack-value (list x 1 nil))) r) + lisp-table)) + (setq lisp-table (nreverse lisp-table))) + (calc-eval result))) + (org-babel-pick-name + (cdr (assq :colname-names params)) (cdr (assq :colnames params))) + (org-babel-pick-name + (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))) (defun org-babel-calc-maybe-resolve-var (el) "Resolve user variables in EL. diff --git a/testing/lisp/test-ob-calc.el b/testing/lisp/test-ob-calc.el index f6e8a5a2f..de6656a4e 100644 --- a/testing/lisp/test-ob-calc.el +++ b/testing/lisp/test-ob-calc.el @@ -63,7 +63,7 @@ (ert-deftest ob-calc/matrix-inversion () | 5 | 6 | 7 | | 9 | 14 | 11 | -#+BEGIN_SRC calc :results silent :var a=ob-calc-table-1 +#+BEGIN_SRC calc :results silent verbatim :var a=ob-calc-table-1 inv(a) #+END_SRC " (should (equal "[[-1, 0.625, -0.125], [0.25, -0.5, 0.25], [0.5, 0.125, -0.125]]" @@ -82,7 +82,7 @@ (ert-deftest ob-calc/matrix-algebra () #+NAME: ob-calc-table-2 | 1 | 2 | 3 | 4 | 5 | -#+BEGIN_SRC calc :results silent :var a=ob-calc-table-2 +#+BEGIN_SRC calc :results silent verbatim :var a=ob-calc-table-2 a*2 - 2 #+END_SRC" (should (equal "[0, 2, 4, 6, 8]" @@ -108,7 +108,7 @@ (ert-deftest ob-calc/matrix-correct-conv-column () | 2 | | 3 | -#+BEGIN_SRC calc :results silent :var a=ob-calc-table-3 +#+BEGIN_SRC calc :results silent verbatim :var a=ob-calc-table-3 a #+END_SRC" (should (equal "[[1], [2], [3]]" @@ -120,11 +120,45 @@ (ert-deftest ob-calc/matrix-correct-conv-row () #+NAME: ob-calc-table-2 | 1 | 2 | 3 | 4 | 5 | -#+BEGIN_SRC calc :results silent :var a=ob-calc-table-2 +#+BEGIN_SRC calc :results silent verbatim :var a=ob-calc-table-2 a #+END_SRC" (should (equal "[1, 2, 3, 4, 5]" (org-babel-execute-src-block))))) +(ert-deftest ob-calc/conv-scalar () + "Test of conversion of scalar for :result replace." + (org-test-with-temp-text "\ +#+BEGIN_SRC calc :results silent + 4 * 4 +#+END_SRC" + (should (equal "16" + (org-babel-execute-src-block))))) + +(ert-deftest ob-calc/conv-vector () + "Test of conversion of vector for :result replace." + (org-test-with-temp-text "\ +#+NAME: ob-calc-table +| 1 | 2 | 3 | 4.1 | 5 | 6 | + +#+BEGIN_SRC calc :results silent :var a=ob-calc-table + a * 2 +#+END_SRC" + (should (equal '(("2" "4" "6" "8.2" "10" "12")) + (org-babel-execute-src-block))))) + +(ert-deftest ob-calc/conv-matrix () + "Test of conversion of matrix for :result replace." + (org-test-with-temp-text "\ +#+NAME: ob-calc-table +| 1 | 2 | +| 2.2 | 4.2 | + +#+BEGIN_SRC calc :results silent table :var a=ob-calc-table + a * 2 +#+END_SRC" + (should (equal '(("2" "4") ("4.4" "8.4")) + (org-babel-execute-src-block))))) + (provide 'test-ob-calc) ;;; test-ob-calc.el ends here -- 2.45.2 --=-=-=--