Ihor,

Attached is a patch to fix the problem that Benjamin has encountered.

Best regards,
Leo

From acc099ca608b59c60f941d8dbff25a17e7adbf8c Mon Sep 17 00:00:00 2001
From: Leo Butler <leo.but...@umanitoba.ca>
Date: Sun, 15 Dec 2024 21:20:26 -0600
Subject: [PATCH] lisp/ob-maxima.el: fix Mac-related bug

* ob-maxima.el (org-babel-maxima--output-filter-regexps): Filter out
lines that include the literal string "(linenum:0,".  Benjamin
McMillan reports that, on his Mac, this string is appearing in the
Maxima output.  Maxima is echoing part of the command-line arguments
passed to it (but it should not), which appears to be a Mac-specific
problem.  Benjamin reports that the additional regexp removes the
errant strings and that all tests are passed.

Reported-By: Benjamin McMillan
Link: https://list.orgmode.org/87plm2e50v.fsf@localhost/
---
 lisp/ob-maxima.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el
index afd615f8d..19d530179 100644
--- a/lisp/ob-maxima.el
+++ b/lisp/ob-maxima.el
@@ -110,7 +110,8 @@ output.  See `org-babel-maxima-expand'.")
 	       "\n")))
 
 (defvar org-babel-maxima--output-filter-regexps
-  '("batch"                     ;; remove the `batch' or `batchload' line
+  '("(linenum:0,"               ;; remove fragment from command-line (see `org-babel-execute:maxima')
+    "batch"                     ;; remove the `batch' or `batchload' line
     "^rat: replaced .*$"        ;; remove notices from `rat'
     "^;;; Loading #P"           ;; remove notices from the lisp implementation
     "^read and interpret"       ;; remove notice from `batch'
-- 
2.45.2

On Sun, Dec 15 2024, Benjamin McMillan <mcmilla...@gmail.com> wrote:

> Dear Leo,
> Ah right, good idea. That works!
> Best,
> Ben
>
> On Sun, Dec 15, 2024 at 12:11 PM Leo Butler <leo.but...@umanitoba.ca> wrote:
>
>> Benjamin,
>>
>> What if you remove the anchor at the beginning of the regexp? Does the
>> following work with the other tests?
>>
>> (add-to-list 'org-babel-maxima--output-filter-regexps "(linenum:0,")
>>
>> Best regards,
>> Leo
>>
>> On Fri, Dec 13 2024, Benjamin McMillan <mcmilla...@gmail.com> wrote:
>>
>> > Hi Leo,
>> > The first suggestion, to add to org-babel-maxima--output-filter-regexps
>> > does fix the src block you ask about here.
>> > However, the regexp doesn't match for other maxima tests. For example:
>> >
>> > #+name: ob-maxima/batch+verbatim
>> > #+begin_src maxima :results verbatim :batch batch :cmdline --quiet
>> >
>> > (assume(z>0),
>> > integrate(exp(-t)*t^z, t, 0, inf));
>> > #+end_src
>> >
>> > #+RESULTS: ob-maxima/batch+verbatim
>> > #+begin_example
>> >
>> > (%i1) (linenum:0,
>> > (%i1) (assume(z > 0),integrate(exp(-t)*t^z,t,0,inf))
>> > (%o1)                            gamma(z + 1)
>> > #+end_example
>> >
>> > Best,
>> > Ben
>> >
>> > On Wed, Dec 11, 2024 at 7:02 AM Leo Butler <leo.but...@umanitoba.ca>
>> wrote:
>> >
>> >> On Tue, Dec 10 2024, Benjamin McMillan <mcmilla...@gmail.com> wrote:
>> >>
>> >> > Hi Leo,
>> >> > I get the following output:
>> >> >
>> >> > #+RESULTS:
>> >> >
>> >> > #+begin_example
>> >> > (linenum:0,
>> >> > #+end_example
>> >> >
>> >> > and from *messages*:
>> >> >
>> >> > Executing Maxima source code block
>> >> > maxima -r \(linenum\:0\,\
>> >> >
>> >>
>> batchload\(\"/var/folders/f5/6nrph1812wdf0nlg4ddcs_580000gn/T/babel-wImUPJ/maxima-Swf2M2.max\"\)\)\$
>> >> >  --very-quiet
>> >> > Wrote
>> >> >
>> >>
>> /var/folders/f5/6nrph1812wdf0nlg4ddcs_580000gn/T/babel-wImUPJ/ob-input-Rbgtzp
>> >> > Code block evaluation complete (took 0.1s).
>> >> >
>> >> > The contents of that file (which I also attach) are:
>> >> >
>> >> > build_info();
>> >> >
>> >> > If there's more information I can give, just let me know.
>> >> > Thanks,
>> >> > Benjamin
>> >> >
>> >> > On Tue, Dec 10, 2024 at 9:17 AM Leo Butler <leo.but...@umanitoba.ca>
>> >> wrote:
>> >> >
>> >> >> On Mon, Dec 09 2024, Leo Butler <leo.but...@umanitoba.ca> wrote:
>> >> >>
>> >> >> > On Sun, Dec 08 2024, Ihor Radchenko <yanta...@posteo.net> wrote:
>> >> >> >
>> >> >> >> Benjamin McMillan <mcmilla...@gmail.com> writes:
>> >> >> >>
>> >> >> >>> This outputs
>> >> >> >>> #+RESULTS:
>> >> >> >>> | (linenum:0, |
>> >> >> >>> |           4 |
>> >> >> >>>
>> >> >> >>> I suppose the issue is the "linenum:0". In fact, running any of
>> the
>> >> >> test
>> >> >> >>> src blocks does that, e.g.
>> >> >> >>> #+begin_src maxima :results verbatim :batch batch
>> >> >> >>> (assume(z>0),
>> >> >> >>> integrate(exp(-t)*t^z, t, 0, inf));
>> >> >> >>> #+end_src
>> >> >> >>>
>> >> >> >>> #+RESULTS:
>> >> >> >>> #+begin_example
>> >> >> >>> (linenum:0,
>> >> >> >>> (assume(z > 0),integrate(exp(-t)*t^z,t,0,inf))
>> >> >> >>>                                  gamma(z + 1)
>> >> >> >>> #+end_example
>> >> >> >>> This does not match the (should (equal ...)) in test-ob-maxima.el
>> >> >> >>>
>> >> >> >>> I don't know maxima, and haven't made any explicit modifications
>> >> >> regards
>> >> >> >>> it, so I don't know why my setup would be outputting linenum:0
>> >> >>
>> >> >> Benjamin,
>> >> >> When you execute your source code block, ob-maxima prints the shell
>> >> >> command as a message. Could you copy that shell command from
>> *Messages*
>> >> >> and send it, along with the batch file that ob-maxima creates?
>> >> >>
>> >> >> Thanks,
>> >> >> Leo
>> >> >>
>> >> >> >>
>> >> >> >> Setting linenum was introduced in
>> >> >> >> https://list.orgmode.org/orgmode/87jzsrai3x.fsf@localhost/
>> >> >> >>
>> >> >> >> It clearly does not affect Linux, but Maxima on MacOS appears to
>> have
>> >> >> >> slightly different behavior.
>> >> >> >>
>> >> >> >> I am CCing the author of the original patch that introduced this
>> >> >> setting.
>> >> >> >> Leo, maybe you have some insight?
>> >> >> >>
>> >> >> >> Unless we can do something to solve the problem on Mac, I am
>> >> tentatively
>> >> >> >> inclined to revert the linenum part of the patch, so that
>> ob-maxima
>> >> is
>> >> >> >> not broken on MacOS.
>> >> >> >
>> >> >> > Benjamin,
>> >> >> > Could you include the output of
>> >> >> >
>> >> >> > #+begin_src maxima :results verbatim
>> >> >> > build_info();
>> >> >> > #+end_src
>> >> >> >
>> >> >> > , please? I think the bug is in the Mac build of Maxima, but I need
>> >> more
>> >> >> > information to figure it out.
>> >> >> >
>> >> >> > Best,
>> >> >> > Leo
>> >>
>> >> Hi Benjamin,
>> >>
>> >> Let me preface my requests by saying that I do not have access to a Mac,
>> >> and the problem you are seeing seems to be Mac-specific, so I am
>> >> searching in the dark for a solution to the problem.
>> >>
>> >> I have a couple ideas.
>> >>
>> >> * First idea
>> >> ** Add the regexp =^(linenum:0,= to
>> >> =org-babel-maxima--output-filter-regexps=
>> >>
>> >> #+begin_src elisp :exports none :results raw
>> >>   (add-to-list 'org-babel-maxima--output-filter-regexps "^(linenum:0,")
>> >> #+end_src
>> >>
>> >> ** Evaluate your Maxima code block
>> >>
>> >> #+name: max
>> >> #+begin_src maxima :results raw :batch batch
>> >>   (assume(z>0), integrate(exp(-t)*t^z, t, 0, inf));
>> >> #+end_src
>> >>
>> >> If all goes well, you should see the output:
>> >>
>> >> #+RESULTS: max
>> >> (assume(z > 0),integrate(exp(-t)*t^z,t,0,inf))
>> >>                                  gamma(z + 1)
>> >>
>> >> Please evaluate these code blocks in an Org buffer and tell us how it
>> >> goes.
>> >>
>> >> * Second idea
>> >>
>> >> We could introduce a customization variable, e.g.
>> >> org-babel-maxima-batch/load-format-string, whose default is the current
>> >> value is "(linenum:0, %s(%S))$". You could change that to "%s(%S)$".
>> >>
>> >> I would prefer to see if the first idea works for you, though, before
>> >> pursuing this.
>> >>
>> >> TIA,
>> >> Leo

Reply via email to