Re: [BUG] #+CALL - permission error -bash

2024-05-02 Thread Leo Butler
On Thu, May 02 2024, vita...@gmx.com wrote:

> in org-babel-sh-evaluate
>  file:~/.emacs.d/elpa/org-9.6.28/ob-shell.el::300
>
> this do apply: (process-file "/tmp/babel-NfRG9P/sh-script-jmKNA4"
>  "/tmp/babel-NfRG9P/sh-stdin-o3CEm5" # nil nil)
>
> I don't allow executables in /tmp folder!

How about:

(setq org-babel-temporary-directory
  (let ((temporary-file-directory "/path/you/prefer"))
(make-temp-file "babel-" t)))

Leo


[PATCH] updating org-plot.org on worg, was Re: Can we add PLOT to org-element-multiple-keywords?

2024-04-24 Thread Leo Butler
I looked at the documentation on worg for org-plot and much of it is
out-of-date and/or no longer works (e.g. dead links, non-working
examples). Attached is a patch for the first half of the documentation.
The patch ends at the end of the section on 2d graphs.

Comments are appreciated. I also ask for advice on later sections, below.

From 4e262898feb349dad2f5b5afe8960c8e09723862 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Wed, 24 Apr 2024 12:57:58 -0500
Subject: [PATCH] org-tutorials/org-plot.org: update documentation and examples

- Replace dead link to org-plot.el with link to it on the Org
repository.
- Put discussion of keybinding into a subsection distinct from
installation.  Replace instructions about an idiosyncratic keybinding
with mention of the established keybinding for org-plot/gnuplot.
- Restructure ``2d plots'' section.
   - Put lines example in one subsection, histogram example in a
   second.
   - Show the #+PLOT options that are used to create each example.
   - Fix internal link.
   - Add names/captions to tables.
   - Remove the second histogram example, because the instructions are
 incorrect and it does not work.
---
 org-tutorials/org-plot.org | 70 +-
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/org-tutorials/org-plot.org b/org-tutorials/org-plot.org
index a0f3564b..98401fd3 100644
--- a/org-tutorials/org-plot.org
+++ b/org-tutorials/org-plot.org
@@ -43,38 +43,46 @@ following
 First we need to make sure that org-plot is on your system and
 available to emacs.  If you have a recent version of org-mode (version
 6.07 or later) then org-plot is already included.  Otherwise you can
-grab the latest org-plot.el from [[http://github.com/eschulte/org-plot/tree/master][github/eschulte/org-plot]].  Once you
-have org-plot loaded it may be useful to bind the main plotting
-command =org-plot/gnuplot= to a key chord, I use =C-M-g= for the
-mnemonic "graph" which can be done by executing the following elisp
-snippet.  This command will be the only org-plot command needed for
-the remainder of this tutorial.
+grab the latest ~org-plot.el~ from the [[https://git.sr.ht/~bzg/org-mode/tree/main/item/lisp/org-plot.el][Org repository]].
 
-[[elisp:(local-set-key "\M-\C-g" 'org-plot/gnuplot)]]
-
-Alright, we're now ready to start generating some graphs.
+** Keybinding
+The main plotting command, =org-plot/gnuplot=, is bound to the
+key-chord =C-c " g=.  This is the only org-plot command used in this
+tutorial.
 
 * Examples
 ** 2d plots (lines and histograms)
+*** Lines
 
-First, to plot the following table use the key sequence defined above
-=C-M-g=.  This will call =org-plot/gnuplot= which finds and plots the
-nearest table.  The options specified in any =#+PLOT= lines above the
-table are read and applied to the plot.  Notice that the second
-=#+PLOT:= line specifies labels for each column, if this line is
-removed the labels will default to the column headers in the table,
-try removing this line and re-plotting.
+To plot [[org-plot-example-1][Table 1]], execute the =org-plot/gnuplot= command.  This command
+finds and plots the nearest table.  The result, saved as a =png= file,
+is displayed in [[org-plot-example-1-plot][Figure 1]].
 
+#+NAME: org-plot-example-1-plot
+#+CAPTION: Plot of Table 1.
 [[file:../images/org-plot/example-1.png]]
 
+The options specified in any =#+PLOT= lines above the table are read
+and applied to the plot.  Notice that the second =#+PLOT= line
+specifies labels for each column; if this line is removed the labels
+will default to the column headers in the table. Here are the =#+PLOT=
+lines used to create Figure 1.
+
+#+NAME: org-plot-example-1-plot-options
+#+BEGIN_EXAMPLE
+#+PLOT: title:"example table" ind:1 type:2d with:lines
+#+PLOT: labels:("first new label" "second column" "last column")
+#+END_EXAMPLE
+
 For a complete list of all of the options and their meanings see the
-[[options]] section at the end of this file.  For more information on
+[[options][options]] section at the end of this file.  For more information on
 gnuplot options see [[http://gnuplot.sourceforge.net/documentation.html][the gnuplot documentation]], nearly all gnuplot
 options should be accessible through org-plot.
 
+#+NAME: org-plot-example-1
+#+CAPTION: Data used to plot Figure 1.
 #+PLOT: title:"example table" ind:1 type:2d with:lines
 #+PLOT: labels:("first new label" "second column" "last column")
-#+TBLNAME:org-plot-example-1
 | independent var | first dependent var | second dependent var |
 |-+-+--|
 | 0.1 |   0.425 |0.375 |
@@ -107,14 +115,22 @@ options should be accessible through org-plot.
 | 2.8 |   0.1598214 |   0.18928565 |
 | 2.9 |  0.15603453 |0.1844828 |
 

Re: orgmode tables

2024-04-22 Thread Leo Butler

Beyond what Mark and Ihor have written, you can insert the column in the
table as you did, and then use M- or M- to move it. That
works for me with:

(insert (emacs-version))
GNU Emacs 29.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo 
version 1.18.0)
 of 2024-02-26, modified by Debian

(insert (org-version))
9.6.23

and either terminal emacs (in an xterm) or gui emacs.

Leo

‘M-’ (‘org-table-move-column-left’)
 Move the current column left.

‘M-’ (‘org-table-move-column-right’)
 Move the current column right.

‘M-S-’ (‘org-table-delete-column’)
 Kill the current column.

‘M-S-’ (‘org-table-insert-column’)
 Insert a new column at point position.  Move the recent column and
 all cells to the right of this column to the right.


On Mon, Apr 22 2024, Jude DaShiell  wrote:

> m-s-right is meta-shift-rightarrow if I have that correct.  Now if I put
> point in the last column of the table and do that, I'll get a column to
> the left which will be blank.  What I tried to ask is if I put point in
> the last column of the table what can I do to have a new column appear to
> the right of where point exists?
>
>
> --
>  Jude 
>  "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo.
>  Please use in that order."
>  Ed Howdershelt 1940.
>
> On Mon, 22 Apr 2024, Leo Butler wrote:
>
>> (info "(org)Built-in Table Editor")
>>
>> ‘M-S-’ (‘org-table-insert-column’)
>>  Insert a new column at point position.  Move the recent column and
>>  all cells to the right of this column to the right.
>>
>> Leo
>>
>> On Mon, Apr 22 2024, Jude DaShiell  wrote:
>>
>> > when making a table in orgmode, I forgot to add three columns to the
>> > table.  What command or commands would I use to add columns to a table?
>> >
>> >
>> > --
>> >  Jude 
>> >  "There are four boxes to be used in defense of liberty:
>> >  soap, ballot, jury, and ammo.
>> >  Please use in that order."
>> >  Ed Howdershelt 1940.

Re: orgmode tables

2024-04-22 Thread Leo Butler
(info "(org)Built-in Table Editor")

‘M-S-’ (‘org-table-insert-column’)
 Insert a new column at point position.  Move the recent column and
 all cells to the right of this column to the right.

Leo

On Mon, Apr 22 2024, Jude DaShiell  wrote:

> when making a table in orgmode, I forgot to add three columns to the
> table.  What command or commands would I use to add columns to a table?
>
>
> --
>  Jude 
>  "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo.
>  Please use in that order."
>  Ed Howdershelt 1940.

Re: MathML and ODT export: inline possible?

2024-04-18 Thread Leo Butler
On Thu, Apr 18 2024, "Fraga, Eric"  wrote:

> Hello all,
>
> I am having (for my sins) to write some Word documents.  I don't even
> have Word on my system but that's by the by.  The documents have some
> mathematical expressions.  In the past, I have used LaTeX to create
> images of these expressions (and hence my earlier post today).  But I'm
> told this is no longer good enough.  Sigh.
>
> So I've started playing with MathML and ODT export.  This is actually
> working quite nicely although writing equations in MathML is ponderous
> [1].
>
> The question I have is: can I replace the link to a Math ML file (which
> does work, as noted in the org info manual) with the actual Math ML code
> inline within the org file?  If so, how?  I would rather not have
> separate files lying around.
>
> Thank you,
> eric
>
> Footnotes:
> [1] exporting LaTeX fragments directly, via latexmlmath, does not
>  actually work very well at all.  The text passed by org is wrong
>  basically.  And latexmlmath gets easily confused, it seems.  I'd
>  rather work with the MathML directly in the end. 

Eric,
I think there is a bug in the way the exporter handles odt fragments.

Explanation: Maxima can print output in mathml. Your question inspired
me to try to craft an example. I came up with the attached org file.

The first two subsections of it exports fine to html (replace "export
odt" with "export html"). But when I export to odt, something weird
happens: contents.xml contains the fragment of mathml, but it is not
displayed in libreoffice. On the other hand, the snippet in the third
sub-section, that is saved to file, is handled correctly (the somewhat
mangled formatting is a bug in Maxima's mathml printer).

Leo

#+TITLE: Demo of mathml and maxima

* An example

** Set up of the printer
If you have version =5.46+= of Maxima, this Maxima code can be used.

#+name: startup
#+begin_src maxima :tangle ./startup.mac :exports code :results none
  (load("alt-display"),
set_alt_display(1,lambda([x],false)),
set_alt_display(2,mathml_display),
display2d:true, linenum:0);
#+end_src

Otherwise, for older versions, this Lisp-ified Maxima code can be used.

#+begin_src maxima :tangle ./startup.lisp  :exports code :results none :noweb yes
  #$
  <>
  #$
#+end_src

The code loads the =alt-display= package.
It sets the 1d printer to print nothing, so input is not echoed; it sets the 2d printer to use the =mathml_display= function, which is provided by =alt-display=.

** A simple example

The code block

#+name: example.org
#+begin_src org :exports code :results replace
  ,#+name: example.mac
  ,#+header: :exports both
  ,#+header: :results raw
  ,#+header: :wrap "export odt"
  ,#+header: :batch batch
  ,#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
  ,#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
  ,#+end_src
#+end_src

#+RESULTS: example.org
#+name: example.mac
#+header: :exports both
#+header: :results raw
#+header: :wrap "export odt"
#+header: :batch batch
#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
#+begin_src maxima
  genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
#+end_src

produces the following output:

#+RESULTS: example.mac
#+begin_export odt
http://www.w3.org/1998/Math/MathML;> mlabel 
 %o 1 ,
 6 
 2  5  
 4  91  
 29  85 
   98 
  3  7 
  13  
 20  13  
 39  20  
  19  4 
  97  6 
  1 43 
  39   
 23  13  
 36  53 
  60  
 71  4  
 3 
#+end_export

A small amount of hand-editing will give something better.

** A re-think
The code seems correct, so let's save the results of the code block to file and use the exporter to correctly handle it.

#+name: rethink.org
#+begin_src org :exports code :results replace
  ,#+name: rethink.mac
  ,#+header: :exports both
  ,#+header: :results file
  ,#+header: :file ./snippet.mml
  ,#+header: :batch batch
  ,#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
  ,#+begin_src maxima
genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
  ,#+end_src
#+end_src

#+RESULTS: rethink.org
#+name: rethink.mac
#+header: :exports both
#+header: :results file
#+header: :file ./snippet.mml
#+header: :batch batch
#+header: :cmdline --no-init --very-quiet --preload ./startup.lisp
#+begin_src maxima
  genmatrix(lambda([i,j], random(100)/random(100)), 4,4);
#+end_src

produces the following output:

#+RESULTS: rethink.mac
[[file:./snippet.mml]]





mathml.odt
Description: mathml.odt


Re: [BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-17 Thread Leo Butler
On Sun, Mar 17 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>> I'd prefer to keep this information in the INFO channel.
>>>> It will be more consistent.
>>
>> Apologies, I messed up the patch in the previous email.
>>
>> Attached is a patch that compiles cleanly and uses INFO.
>
> Thanks!
>
>> + (frame (let ((selection
>> +   (or (and fragilep
>> +(or (string-search "\\begin{frame}" 
>> contents)
>> +(string-search "\\end{frame}" contents))
>
> Please use `string-match-p'. `string-search' is not available in Emacs
> 27, which we still support.

Done.

>
>> +org-beamer-frame-environment)
>> +   "frame")))
>> +  (unless (string= selection "frame")
>> +(setq info (plist-put info :define-frame t)))
>
> Let's use "beamer" prefix to indicate that this plist entry is
> beamer backend-specific. Something like :beamer-define-frame.

Done.

Attached is the updated patch. In addition, I have written three
regression tests that are attached in a separate patch.

Leo

From 3b10e0013ba98cbc2b441507da359996e3d8701c Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH 1/2] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", add the property :beamer-define-frame to INFO and
set it to t.  When that property is t, `org-beamer-template' emits a
definition of the alternative frame environment.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..8bae93c11 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,8 +429,21 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
- (frame (or (and fragilep org-beamer-frame-environment)
-"frame")))
+ ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
+ ;; of \begin{frame} or \end{frame}, then set the FRAME
+ ;; environment to be `org-beamer-frame-environment';
+ ;; otherwise, use "frame". If the selected environment is not
+ ;; "frame", then add the property :beamer-define-frame to
+ ;; INFO and set it to t.
+ (frame (let ((selection
+   (or (and fragilep
+(or (string-match-p "begin{frame}" contents)
+(string-match-p "end{frame}" contents))
+org-beamer-frame-environment)
+   "frame")))
+  (unless (string= selection "frame")
+(setq info (plist-put info :beamer-define-frame t)))
+  selection)))
 (concat "\\begin{" frame "}"
 	;; Overlay specification, if any. When surrounded by
 	;; square brackets, consider it as a default
@@ -851,8 +864,8 @@ holding export options."
  (org-latex--insert-compiler info)
  ;; Document class and packages.
  (org-latex-make-preamble info)
- ;; Define the alternative frame environment.
- (unless (equal "frame" org-beamer-frame-environment)
+ ;; Define the alternative frame environment, if needed.
+     (when (plist-get info :beamer-define-frame)
(format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
org-beamer-frame-environment))
  ;; Insert themes.
-- 
2.43.0

From 4377c4a55d1fe879b92f268edebcf03d72821703 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Sun, 17 Mar 2024 08:14:54 -0500
Subject: [PATCH 2/2] testing/lisp/test-ox-beamer.el: New regression tests for
 ox-beamer.

* testing/lisp/test-ox-beamer.el (ox-beamer/orgframe,
ox-beamer/orgframe-in-example, ox-beamer/orgframe-in-one-example): New
file.  Regression tests for ox-beamer.  Test that the
`org-beamer-frame-environment' is defined only when used.
---
 testing/lisp/test-ox-beamer.el | 110 +
 1 file changed, 110 insertions(+)
 create mode 100644 testing/lisp/te

Re: [BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-16 Thread Leo Butler
On Sat, Mar 16 2024, Leo Butler  wrote:

> On Fri, Mar 15 2024, Ihor Radchenko  wrote:
>
>> Leo Butler  writes:
>>
>>>> Leo, may you improve the patch to avoid defining
>>>> `org-beamer-frame-environment' when it is not used in all the frames?
>>>
>>> "all the" should be "any of" in that last sentence.
>>
>> Indeed.
>>
>>> How about the attached patch?
>>> ...
>>> +(defvar org-beamer--frame-environment-used nil
>>> +  "Nil unless `org-beamer-frame-environment' is used.
>>> +See `org-beamer--frame-environment'.")
>>
>> I'd prefer to keep this information in the INFO channel.
>> It will be more consistent.

Apologies, I messed up the patch in the previous email.

Attached is a patch that compiles cleanly and uses INFO.

Leo

From 003cf1d417fe8f5d1a9f8fe20980f7f4b7c5d3c4 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", add the property :define-frame to INFO and set it to
t.  When that property is t, `org-beamer-template' emits a definition
of the alternative frame environment.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..090d3d9ab 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,8 +429,21 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
- (frame (or (and fragilep org-beamer-frame-environment)
-"frame")))
+ ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
+ ;; of \begin{frame} or \end{frame}, then set the FRAME
+ ;; environment to be `org-beamer-frame-environment';
+ ;; otherwise, use "frame". If the selected environment is not
+ ;; "frame", then add the property :define-frame to INFO and
+ ;; set it to t.
+ (frame (let ((selection
+   (or (and fragilep
+(or (string-search "\\begin{frame}" contents)
+(string-search "\\end{frame}" contents))
+org-beamer-frame-environment)
+   "frame")))
+  (unless (string= selection "frame")
+(setq info (plist-put info :define-frame t)))
+  selection)))
 (concat "\\begin{" frame "}"
 	;; Overlay specification, if any. When surrounded by
 	;; square brackets, consider it as a default
@@ -851,8 +864,8 @@ holding export options."
  (org-latex--insert-compiler info)
  ;; Document class and packages.
  (org-latex-make-preamble info)
- ;; Define the alternative frame environment.
- (unless (equal "frame" org-beamer-frame-environment)
+ ;; Define the alternative frame environment, if needed.
+ (when (plist-get info :define-frame)
(format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
org-beamer-frame-environment))
  ;; Insert themes.
-- 
2.43.0



Re: [BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-16 Thread Leo Butler
On Fri, Mar 15 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> Leo, may you improve the patch to avoid defining
>>> `org-beamer-frame-environment' when it is not used in all the frames?
>>
>> "all the" should be "any of" in that last sentence.
>
> Indeed.
>
>> How about the attached patch?
>> ...
>> +(defvar org-beamer--frame-environment-used nil
>> +  "Nil unless `org-beamer-frame-environment' is used.
>> +See `org-beamer--frame-environment'.")
>
> I'd prefer to keep this information in the INFO channel.
> It will be more consistent.

See attached.

Leo

From 1df8520f2a4cfc7a7d8d971adc82cbd95d97735c Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH 1/2] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", add the property :define-frame to INFO and set it to
t.  When that property is t, `org-beamer-template' emits a definition
of the alternative frame environment.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..713978477 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,8 +429,21 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
- (frame (or (and fragilep org-beamer-frame-environment)
-"frame")))
+ ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
+ ;; of \begin{frame} or \end{frame}, then set the FRAME
+ ;; environment to be `org-beamer-frame-environment';
+ ;; otherwise, use "frame". If the selected environment is not
+ ;; "frame", then add the property :define-frame to INFO and
+ ;; set it to t.
+ (frame (let ((selection
+   (or (and fragilep
+(or (string-search "\\begin{frame}" contents)
+(string-search "\\end{frame}" contents))
+org-beamer-frame-environment)
+   "frame")))
+  (unless (string= selection "frame")
+(setq into (plist-put info :define-frame t)))
+  selection)))
 (concat "\\begin{" frame "}"
 	;; Overlay specification, if any. When surrounded by
 	;; square brackets, consider it as a default
@@ -851,8 +864,9 @@ holding export options."
  (org-latex--insert-compiler info)
  ;; Document class and packages.
  (org-latex-make-preamble info)
- ;; Define the alternative frame environment.
- (unless (equal "frame" org-beamer-frame-environment)
+ ;; Define the alternative frame environment, if needed.
+ (when (plist-get info :define-frame)
+   (setq org-beamer--frame-environment-used nil)
(format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
org-beamer-frame-environment))
  ;; Insert themes.
-- 
2.43.0



Re: [BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-14 Thread Leo Butler
On Wed, Mar 13 2024, Ihor Radchenko  wrote:

> Pedro Andres Aranda Gutierrez  writes:
>
>> I really don't have anything to object to the original patch. I support the
>> need to circumvent the "\begin-or-end{frame} inside frame" problem and
>> using orgframe is a clean way of doing so.
>> My only concern is the _default_ value for `org-beamer-frame-environment'.
>> If we set it to "frame", we only need to customise it in the file local
>> variables in files where it needs to be changed and we catch all flies in a
>> stroke:
>>
>> Situation 1: presentation has no "\begin-or-end{frame} inside frame" -> no
>> extra stuff in file local variables AND newenvironment is not generated AND
>> frames are between \begin{frame} and \end{frame}
>> Situation 2: presentation needs to circumvent "\begin-or-end{frame} inside
>> frame" -> set local variable in file AND newenvironment is generated AND
>> frame is changed where it is strictly necessary,
>
> I do not like that users would need to do manual action in situation 2.
> For situation 1, Leo's patch will ensure that all the frames are between
> \begin{frame}..\end{frame}, but newenvironment is still generated.
>
> Leo, may you improve the patch to avoid defining
> `org-beamer-frame-environment' when it is not used in all the frames?

"all the" should be "any of" in that last sentence.

--

How about the attached patch?

The previous org file exports in the same way, and exporting just the
final heading shows that no newenvironment is emitted.

Leo

From 22d829089fc2ca153f1541abe1d5415d311b33d3 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame, org-beamer-template):
Only use `org-beamer-frame-environment' when a frame is marked as
fragile and the frame's contents include either \begin{frame} or
\end{frame}.  When `org-beamer-frame-environment' is used and not
equal to "frame", set `org-beamer--frame-environment-used' to t.  When
`org-beamer--frame-environment-used' is t, `org-beamer-template' emits
a definition of the alternative frame environment.

* lisp/ox-beamer.el (org-beamer--frame-environment-used): New
variable.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 26 ++
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..a79490194 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -167,6 +167,10 @@ used inside beamer slides."
 
 ;;; Internal Variables
 
+(defvar org-beamer--frame-environment-used nil
+  "Nil unless `org-beamer-frame-environment' is used.
+See `org-beamer--frame-environment'.")
+
 (defconst org-beamer-column-widths
   "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.0 :ETC"
   "The column widths that should be installed as allowed property values.")
@@ -429,8 +433,21 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
- (frame (or (and fragilep org-beamer-frame-environment)
-"frame")))
+ ;; If FRAGILEP is non-nil and CONTENTS contains an occurrence
+ ;; of \begin{frame} or \end{frame}, then set the FRAME
+ ;; environment to be `org-beamer-frame-environment';
+ ;; otherwise, use "frame". If the selected environment is not
+ ;; "frame", then set `org-beamer--frame-environment-used' to
+ ;; t.
+ (frame (let ((selection
+   (or (and fragilep
+(or (string-search "\\begin{frame}" contents)
+(string-search "\\end{frame}" contents))
+org-beamer-frame-environment)
+   "frame")))
+  (unless (string= selection "frame")
+(setq org-beamer--frame-environment-used t))
+  selection)))
 (concat "\\begin{" frame "}"
 	;; Overlay specification, if any. When surrounded by
 	;; square brackets, consider it as a default
@@ -851,8 +868,9 @@ holding export options."
  (org-latex--insert-compiler info)
  ;; Document class and packages.
  (org-latex-make-preamble info)
- ;; Define the alternative frame environment.
- (unless (equal "frame" org-beamer-frame-environment)
+ ;; Define the alternative frame environment, if needed.
+ (when org-beamer--frame-environment-used
+   (setq org-beamer--frame-environment-used nil)
(format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
org-beamer-frame-environment))
  ;; Insert themes.
-- 
2.43.0



Re: [BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-12 Thread Leo Butler
On Tue, Mar 12 2024, Ihor Radchenko  wrote:

> Pedro Andres Aranda Gutierrez  writes:
>
>> Jup, of course. If you look in org-lint.el, one of the cases that would
>> trigger a message is when the frame environment uses "frame" directly and
>> there is a \begin{frame} in the org.
>> Line 1522 onwards in org-lint.el
>
> (1)
> Sure, but we should not demand users to run org-lint. Ideally, exporting
> any valid Org file should work.
> The fact that the presence of \begin{frame} breaks beamer is a technical
> detail users should better not be bothered with. That's why we added the
> orgframe construct.
>
> (2)
> On the other hand, it is clear that Org mode users are unwilling to
> tolerate too much of machine generated latex output. So, going further
> and trying to generate unique orgframe environments might not be ideal.
>
> The current approach is a balance between the above considerations.
>
> AFAIU, what you propose is reverting the orgframe code; that goes
> against the first point.

Current git HEAD allows a user like Pedro to effectively turn off the
orgframe code via

(setq org-beamer-frame-environment "frame")

or an equivalent. 

>
> What I proposed is to reduce the amount of machine-generated code by
> using `org-beamer-frame-environment' only when strictly necessary.

Attached is a patch that limits the use of
`org-beamer-frame-environment' to those frames that contain either
\begin{frame} or \end{frame} in their body.

This has the nice side-effect that one can include example frames
generated by Org without causing an error (previously, Org exported
latex that would not compile). See the attachments.

Leo

From cab7cd149868be86f80d2c7bb52e2c09c028d4b1 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Mar 2024 15:11:27 -0500
Subject: [PATCH] lisp/ox-beamer.el: constrain use of
 org-beamer-frame-environment

* lisp/ox-beamer.el (org-beamer--format-frame): Only use
`org-beamer-frame-environment' when a frame is marked as fragile and
the frame's contents include either \begin{frame} or \end{frame}.

Refs: https://list.orgmode.org/orgmode/87bk7jeik8.fsf@localhost/
https://list.orgmode.org/87a5nux3zr@t14.reltub.ca/T/
---
 lisp/ox-beamer.el | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 4fad37b59..f7e39dde4 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -429,7 +429,10 @@ used as a communication channel."
 	  ;; among `org-beamer-verbatim-elements'.
 	  (org-element-map headline org-beamer-verbatim-elements 'identity
 			   info 'first-match))
- (frame (or (and fragilep org-beamer-frame-environment)
+ (frame (or (and fragilep
+ (or (string-search "\\begin{frame}" contents)
+ (string-search "\\end{frame}" contents))
+ org-beamer-frame-environment)
 "frame")))
 (concat "\\begin{" frame "}"
 	;; Overlay specification, if any. When surrounded by
-- 
2.43.0

#+startup: beamer
#+LaTeX_CLASS: beamer

* A frame with =orgframe= sample code
#+begin_example
\begin{orgframe}
  Here is a beamer frame.
\end{orgframe}
#+end_example
This is exported in a =frame= environment, although it is marked as fragile.

* A frame with =frame= sample code
#+begin_example
\begin{frame}
  Here is a beamer frame.
\end{frame}
#+end_example
This is exported in an =orgframe= environment, since contains =\begin{frame}= and =\end{frame}=.

* An ordinary frame
\[ z^n = x^n + y^n \]
This is exported in a =frame= environment.

% Created 2024-03-12 Tue 15:28
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\newenvironment<>{orgframe}[1][]{\begin{frame}#2[environment=orgframe,#1]}{\end{frame}}
\usetheme{default}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 29.1 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\begin{frame}{Outline}
\tableofcontents
\end{frame}

\begin{frame}[label={sec:org5fbeeef},fragile]{A frame with \texttt{orgframe} sample code}
 \begin{verbatim}
\begin{orgframe}
  Here is a beamer frame.
\end{orgframe}
\end{verbatim}
This is exported in a \texttt{frame} environment, although it is marked as fragile.
\end{frame}
\begin{orgframe}[label={sec:org500e0c5},fragile]{A frame with \texttt{frame} sample code}
 \begin{verbatim}
\begin{frame}
  Here is a beamer frame.
\end{frame}
\end{verbatim}
This is exported in an \texttt{orgframe} environment, since contains \texttt{\textbackslash{}begin\{

[BUG] Re: The orgframe construct in the Beamer exporter as a default needs a rethink

2024-03-01 Thread Leo Butler
Hello,

Thanks for the bug report. The definition of the orgframe environment
did not pass the overlay spec to the underlying frame environment. I
believe the attached patch fixes that.

Attached is an org file that appears to exercise the patch and show that
it is doing the right thing. Could you confirm this, please?


Incidentally, I did propose that we introduce a BEAMER_FRAME property so
that it could be manually set, but Ihor did not like that idea so it got
scrapped.

Thanks,
Leo

From 4fef88ac31272a39e948fcd334bee28e444a7535 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Fri, 1 Mar 2024 17:06:57 -0600
Subject: [PATCH] lisp/ox-beamer.el: fix orgframe environment definition

* (org-beamer-template):  pass the frame overlay specification to the
frame in the definition of the orgframe environment.

Bug reported by Pedro Andres Aranda Gutierrez.

Ref: https://list.orgmode.org/orgmode/cf58e7a4-233d-4f9d-bbe2-fc1a67e31...@gmail.com/T/
---
 lisp/ox-beamer.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 998810a28..56e7e06ed 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -852,7 +852,7 @@ holding export options."
  ;; Document class and packages.
  (org-latex-make-preamble info)
  ;; Define the alternative frame environment.
- (format "\\newenvironment<>{%s}[1][]{\\begin{frame}[environment=%1$s,#1]}{\\end{frame}}\n"
+ (format "\\newenvironment<>{%s}[1][]{\\begin{frame}#2[environment=%1$s,#1]}{\\end{frame}}\n"
  org-beamer-frame-environment)
  ;; Insert themes.
  (let ((format-theme
-- 
2.43.0

#+STARTUP: beamer

* Slide A
:PROPERTIES:
:BEAMER_act: 
:END:

I use
#+begin_example
:PROPERTIES:
:BEAMER_act: 
:END:
#+end_example

For slides I only want in the presentation and

* Handout
:PROPERTIES:
:BEAMER_act: 
:END:

For slides I only want in the handout. With the new orgframe
environment as of now, the argument between the <> is not passed to
the frame and therefore lost.

* Slide B
I don’t know how often the orgframe is needed (I haven’t needed it in
the last years of making my presentations with org-mode), but wouldn’t
it be more sensible to write
#+begin_example
:PROPERTIES:
:BEAMER_env: orgframe
:END:
#+end_example
When you really do need it?

* Slide C
:PROPERTIES:
:BEAMER_act: 
:END:

This slide is included, too.

* Handout
:PROPERTIES:
:BEAMER_act: 
:END:

This frame is exported as an =orgframe= with the correct =BEAMER_act=:

#+begin_example
:PROPERTIES:
:BEAMER_act: 
:END:
#+end_example
% Created 2024-03-01 Fri 17:06
% Intended LaTeX compiler: pdflatex
\documentclass[presentation]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\newenvironment<>{orgframe}[1][]{\begin{frame}#2[environment=orgframe,#1]}{\end{frame}}
\usetheme{default}
\date{\today}
\title{}
\hypersetup{
 pdfauthor={},
 pdftitle={},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 29.1 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\begin{frame}{Outline}
\tableofcontents
\end{frame}

\begin{orgframe}[label={sec:org0d8497b},fragile]{Slide A}
 I use
\begin{verbatim}
:PROPERTIES:
:BEAMER_act: 
:END:
\end{verbatim}

For slides I only want in the presentation and
\end{orgframe}
\begin{frame}[label={sec:org50260e7}]{Handout}
For slides I only want in the handout. With the new orgframe
environment as of now, the argument between the <> is not passed to
the frame and therefore lost.
\end{frame}
\begin{orgframe}[label={sec:org79072fa},fragile]{Slide B}
 I don’t know how often the orgframe is needed (I haven’t needed it in
the last years of making my presentations with org-mode), but wouldn’t
it be more sensible to write
\begin{verbatim}
:PROPERTIES:
:BEAMER_env: orgframe
:END:
\end{verbatim}
When you really do need it?
\end{orgframe}
\begin{frame}[label={sec:org3036752}]{Slide C}
This slide is included, too.
\end{frame}
\begin{orgframe}[label={sec:org3be6ccc},fragile]{Handout}
 This frame is exported as an \texttt{orgframe} with the correct \texttt{BEAMER\_act}:

\begin{verbatim}
:PROPERTIES:
:BEAMER_act: 
:END:
\end{verbatim}
\end{orgframe}
\end{document}


ox-beamer-bug.pdf
Description: ox-beamer-bug.pdf


On Fri, Mar 01 2024, Pedro Andres Aranda Gutierrez  wrote:

> Hi,
>
> I needed to go back to stock org-mode (as included in Emacs) because
> the ‘orgframe’ as defined right now kills my slide decks.
> I have been using the construct
>
> ** Title
>:PROPERTIES:
>:BEAMER_act: 
>:END:
>
> For slides I only want in the presentation and
>
> ** Title
>:PROPERTIES:
>:BEAMER_act: 
>:END:
>
> For slides I only want in the handout. With the new orgframe
>

Re: [BUG] beamer export

2024-02-20 Thread Leo Butler
On Mon, Feb 19 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> What about not adding BEAMER_FRAME, but instead adding org-lint checker
>>> that will detect when frame text contains the problematic \end{orgframe}?
>>
>> Ok, thanks for your feedback. I have modified the patch along the lines
>> you suggested. It is attached.
>
> Thanks!
> It looks like you left over some parts from the previous patch version.
>
>> (org-beamer--format-frame): Introduce the new property, :BEAMER_FRAME.
>
> ... like this.
>
>> (org-beamer--frame-environments): New variable and function.  The
>> variable holds a list of names of frame environments found while
>> formatting frames.  The function generates the LaTeX code to define
>> each new frame environment.
>> (org-beamer-template): Add a call to `org-beamer--frame-environments'
>> to insert the environment definitions into the beamer document.
>
> And since we only have a single alternative environment in this version
> of the patch, `org-beamer--frame-environments' does not appear to be
> necessary.
>
>> +(defcustom org-beamer-frame-environment "orgframe"
>> +  "Name of the beamer frame environment."
>> +  :group 'org-export-beamer
>> +  :type '(string :tag "Beamer frame"))
>
> It would be nice to provide a mode detailed explanation about the
> purpose of this custom option.
>
>> +(defun org-lint-beamer-frame (ast)
>> +  "Check for occurrences of begin or end frame."
>> +  (org-with-point-at ast
>> +(goto-char (point-min))
>> +(let (result)
>> +  (while (re-search-forward
>> +  (concat "\\(begin\\|end\\){" org-beamer-frame-environment 
>> "}") nil t)
>> +(push (list (match-beginning 0) "Beamer frame name may cause error 
>> when exporting.") result))
>> +  result)))
>
> ... and to link this org-lint warning to the
> `org-beamer-frame-environment' docstring.

Thanks for your comments.

I think the attached patch addresses each of your points. It's not clear
to me what you mean by "link(ing) this org-lint warning to the
`org-beamer-frame-environment' docstring", but I have expanded the
warning include mention of this variable.

Leo

From 70262bc2469536eeb3aaec926ec71530cfaeca79 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 25 Jan 2024 09:48:20 -0600
Subject: [PATCH] lisp/ox-beamer.el:  customize the beamer frame environment
 name

* lisp/ox-beamer.el (org-beamer-frame-environment): A new customize
variable.  It contains the name of an environment that serves as an
alias for the beamer frame environment.

(org-beamer-template): Add a call to `org-beamer--frame-environments'
to insert the environment definitions into the beamer document.

* lisp/org-lint.el (org-lint-beamer-frame): Check the body of each
frame for an occurrence of \begin{orgframe} or \end{orgframe}, or
whatever environment name is in `org-beamer-frame-environment' [4].
The warning includes advice to see `org-beamer-frame-environment'.

Rationale: Code with \begin{frame} or \end{frame} cannot be embedded
in a verbatim environment inside a beamer frame due to a design
decision made by the beamer developers [1].  As suggested in that
report, defining an alias for the beamer frame environment will allow
such verbatim examples to compile correctly [2].

This solution also works with instances of \againframe.

Refs:
[1] https://github.com/josephwright/beamer/issues/360
[2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
[3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/
[4] https://list.orgmode.org/orgmode/87il38i5tb.fsf@localhost/T/
---
 lisp/org-lint.el  | 15 +++
 lisp/ox-beamer.el | 28 
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index 4d2a55d15..91ee2eb2a 100644
--- a/lisp/org-lint.el
+++ b/lisp/org-lint.el
@@ -1507,6 +1507,17 @@ AST is the buffer parse tree."
  ((memq (org-element-property :type deadline) '(inactive inactive-range))
   (list (org-element-begin planning) "Inactive timestamp in DEADLINE will not appear in agenda."))
  (t nil))
+
+(defun org-lint-beamer-frame (ast)
+  "Check for occurrences of begin or end frame."
+  (org-with-point-at ast
+(goto-char (point-min))
+(let (result)
+  (while (re-search-forward
+  (concat "\\(begin\\|end\\){" org-beamer-frame-environment "}") nil t)
+(push (list (match-beginning 0) "Beamer frame name may cause error when exporting.  See `org-beamer--frame-environment'.") result))
+  result)))
+
 
 ;;; Checkers declaration
 
@@ -1787,6 +1798,10 @@ AST 

Re: [BUG] beamer export

2024-02-14 Thread Leo Butler
On Thu, Feb 01 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Replying to self: Attached is a patch that adds a property,
>> BEAMER_FRAME, that lets the frame environment name be set on a
>> frame-by-frame basis. In addition, it typesets any fragile frame in the
>> `orgframe' environment. I am not sure if the latter is really needed,
>> given the former.
>
> Thanks!
>
>> Comments?
>
> I am not a big fan of introducing a new BEAMER_FRAME option.
> We already have BEAMER_ENV.
>
> However, BEAMER_ENV is somewhat tricky for frame headings - ox-beamer
> allows special values of frame and fullframe (the latter is not fully
> documented) to allow frames nesting different from
> `org-beamer-frame-level'.

I experimented with BEAMER_ENV, but my impression is that that the code
for extracting a label is quite brittle. I may re-visit this option, but
not at this time.

>
> What about not adding BEAMER_FRAME, but instead adding org-lint checker
> that will detect when frame text contains the problematic \end{orgframe}?

Ok, thanks for your feedback. I have modified the patch along the lines
you suggested. It is attached.

Best,
Leo

From cc3e1572e354d18ce57c6a7b89b7fdd96b7fe1a8 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 25 Jan 2024 09:48:20 -0600
Subject: [PATCH] lisp/ox-beamer.el:  customize the beamer frame environment
 name

* lisp/ox-beamer.el (org-beamer-frame-environment): A new customize
variable.  It contains the name of an environment that serves as an
alias for the beamer frame environment.

(org-beamer--format-frame): Introduce the new property, :BEAMER_FRAME.
If set in the headline, use that as name of the frame environment.
Otherwise, in frames marked as fragile, the name of the frame
environment is taken from `org-beamer--frame-environment'.  In all
other frames, the default name is frame.  Unless the frame name is
"frame", the name is added to the list
`org-beamer--frame-environments'.

(org-beamer--frame-environments): New variable and function.  The
variable holds a list of names of frame environments found while
formatting frames.  The function generates the LaTeX code to define
each new frame environment.

(org-beamer-template): Add a call to `org-beamer--frame-environments'
to insert the environment definitions into the beamer document.

* lisp/org-lint.el (org-lint-beamer-frame): Check the body of each
frame for an occurrence of \begin{orgframe} or \end{orgframe}, or
whatever environment name is in `org-beamer-frame-environment' [4].

Rationale: Code with \begin{frame} or \end{frame} cannot be embedded
in a verbatim environment inside a beamer frame due to a design
decision made by the beamer developers [1].  As suggested in that
report, defining an alias for the beamer frame environment will allow
such verbatim examples to compile correctly [2].

This solution also works with instances of \againframe.

Refs:
[1] https://github.com/josephwright/beamer/issues/360
[2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
[3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/
[4] https://list.orgmode.org/orgmode/87il38i5tb.fsf@localhost/T/
---
 lisp/org-lint.el  | 15 +++
 lisp/ox-beamer.el | 43 ---
 2 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/lisp/org-lint.el b/lisp/org-lint.el
index f68aeab01..7248f687d 100644
--- a/lisp/org-lint.el
+++ b/lisp/org-lint.el
@@ -1446,6 +1446,17 @@ AST is the buffer parse tree."
  ((memq (org-element-property :type deadline) '(inactive inactive-range))
   (list (org-element-begin planning) "Inactive timestamp in DEADLINE will not appear in agenda."))
  (t nil))
+
+(defun org-lint-beamer-frame (ast)
+  "Check for occurrences of begin or end frame."
+  (org-with-point-at ast
+(goto-char (point-min))
+(let (result)
+  (while (re-search-forward
+  (concat "\\(begin\\|end\\){" org-beamer-frame-environment "}") nil t)
+(push (list (match-beginning 0) "Beamer frame name may cause error when exporting.") result))
+  result)))
+
 
 ;;; Checkers declaration
 
@@ -1711,6 +1722,10 @@ AST is the buffer parse tree."
   "Report $ that might be treated as LaTeX fragment boundary."
   #'org-lint-LaTeX-$-ambiguous
   :categories '(markup) :trust 'low)
+(org-lint-add-checker 'beamer-frame
+  "Report that frame text contains beamer frame environment."
+  #'org-lint-beamer-frame
+  :categories '(export) :trust 'low)
 (org-lint-add-checker 'timestamp-syntax
   "Report malformed timestamps."
   #'org-lint-timestamp-syntax
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 82c8841aa..65d8b06ef 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -149,9 +149,17 @@ which is replaced with the subtitle."
   :p

Re: [BUG] Unsolicited download of remote resources

2024-02-06 Thread Leo Butler
On Mon, Feb 05 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Q: if #+setupfile points to a real file available to download, does Org
>> evaluate that file?
>
> keywords and startup options are taken from there. No Elisp code present
> in #+SETUPFILE is evaluated.
>
> That said, if the file defines babel header arguments with elisp or
> "eval" macros, they may be used later, during export or when src block
> evaluation is requested by the user.

So, it is *possible* to have the setupfile set-up arbitrary elisp code
that would be evaluated at some later time (during export or src block
evaluation, as you wrote)? Is that correct?

Leo


Re: [BUG] Unsolicited download of remote resources

2024-02-05 Thread Leo Butler
On Sun, Feb 04 2024, Max Nikulin  wrote:

> On 03/02/2024 02:04, Leo Butler wrote:
>> When I opened your email in Gnus, I was greeted with the same
>> (bewildering) message. Given that Org still tried to download the
>> setupfile after being told not to, I think this is a majour security
>> hole.
>> This is also related to another thread concerning Org and email.
>> https://list.orgmode.org/orgmode/87cyteyhif.fsf@localhost/
>
> Sorry for sending a message with this kind of attachment, but from the
> discussion of that Emacs bug I expected that almost no Gnus users
> should be affected since their media type handler is set for
> text/x-org while Thunderbird uses "Content-Type: text/org".
>
> I would not classify this kind of issues as security ones. I am
> unaware of Org features that may make content of "#+setupfile:" more
> dangerous than the same snippet is included into attachment
> directly. (OK, antivirus might have a chance to detect something as
> dangerous code and "#+setupfile:" would bypass such protection.)
>
> I consider it as a privacy issue. It may allow spammers to track if
> their messages are delivered successfully.

There's no need to apologize--I was surprised at the whole episode.

Q: if #+setupfile points to a real file available to download, does Org
evaluate that file?

Leo


Re: [BUG] Unsolicited download of remote resources

2024-02-02 Thread Leo Butler
On Fri, Feb 02 2024, Max Nikulin  wrote:

> Hi,
>
> Org git main HEAD, try to open the following file:
>
> --- 8< ---
>
> #+setupfile: http://localhost:8000/setup-1234567890.org
>
> test
> --- >8 ---
>
> I am trying to decline attempts to download the remote resource by 
> hitting "n" (skip), but Org still tries to fetch that file and does it 
> twice. I see in the *Messages*
>
> Please type y, n, d, or !: n
> Contacting host: localhost:8000
> Org couldn’t download "http://localhost:8000/setup-1234567890.org": 
> file-error ("make client process failed" "Connection refused" :name 
> "localhost" :buffer # :host "localhost" :service 8000 
> :nowait nil :tls-parameters nil :coding nil)
>
> Please type y, n, d, or !: n
> Contacting host: localhost:8000
> Org couldn’t download "http://localhost:8000/setup-1234567890.org": 
> file-error ("make client process failed" "Connection refused" :name 
> "localhost" :buffer # :host "localhost" :service 8000 
> :nowait nil :tls-parameters nil :coding nil)
>
>  From my point of view Org should not do it. Assume it is not a file I 
> created myself, but it is downloaded from some web server or received in 
> a e-mail message.

When I opened your email in Gnus, I was greeted with the same
(bewildering) message. Given that Org still tried to download the
setupfile after being told not to, I think this is a majour security
hole.

This is also related to another thread concerning Org and email.

https://list.orgmode.org/orgmode/87cyteyhif.fsf@localhost/

Leo

Re: [BUG] beamer export

2024-01-29 Thread Leo Butler
On Fri, Jan 26 2024, Leo Butler  wrote:

> On Fri, Jan 26 2024, Ihor Radchenko  wrote:
>
>> Leo Butler  writes:
>>
>>>> Apparently, LaTeX has really hard time processing verbatim code inside
>>>> beamer frames.
>>>
>>> I looked again at the solution here:
>>> https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim
>>>
>>> and it errors out with a recent version of pdflatex:
>>>
>>>This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) 
>>> (preloaded format=pdflatex)
>>>
>>> This is, apparently, a known problem:
>>>
>>> https://github.com/josephwright/beamer/issues/360
>>>
>>> The end of that issue report includes a work-around that we might apply
>>> in org. I have attached a patch for your feedback. The example that
>>> stimulated this discussion compiles with the patch and the testsuite
>>> shows no errors related to it.
>>
>> Thanks!
>> I have concerns about your approach though.
>>
>> You are replacing all the frame environments with custom environment
>> unconditionally. However, custom environment has downsides. For example,
>> \againframe will stop working, as pointed earlier in the linked beamer
>> thread
>> https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
>
> The comment that you are citing shows how to define the custom
> environment so that \againframe works correctly. See the attachment
> `beamer-example-againframe.tex' and pdf. You can see that \againframe
> works with the custom environment.
>
>>
>> Since the problem appears only when the frame contents contains
>> \end{frame}, it may be sufficient to replace the standard frame
>> environment with the workaround only in such scenario.
>
> Yes, that might be true. But my feeling is that it would be simpler and
> more robust to use the custom frame environment in most cases.

Replying to self: Attached is a patch that adds a property,
BEAMER_FRAME, that lets the frame environment name be set on a
frame-by-frame basis. In addition, it typesets any fragile frame in the
`orgframe' environment. I am not sure if the latter is really needed,
given the former.

Comments?

Leo

From d0117ca35405654c6adc003252eff5a1f629b67a Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 25 Jan 2024 09:48:20 -0600
Subject: [PATCH] lisp/ox-beamer.el:  customize the beamer frame environment
 name

* lisp/ox-beamer.el (org-beamer-frame-environment): A new customize
variable that contains the name of an environment that serves as an
alias for the beamer frame environment.

(org-beamer--format-frame): Introduce the new property, :BEAMER_FRAME.
If set in the headline, use that as name of the frame environment.
Otherwise, in frames marked as fragile, the name of the frame
environment is taken from `org-beamer--frame-environment'.  In all
other frames, the default name is frame.  Unless the frame name is
"frame", the name is added to the list
`org-beamer--frame-environments'.

(org-beamer--frame-environments): New variable and function.  The
variable holds a list of names of frame environments found while
formatting frames.  The function generates the LaTeX code to define
each new frame environment.

(org-beamer-template): Add a call to `org-beamer--frame-environments'
to insert the environment definitions into the beamer document.

Rationale: Code with \begin{frame} or \end{frame} cannot be embedded
in a verbatim environment inside a beamer frame due to a design
decision made by the beamer developers [1].  As suggested in that
report, defining an alias for the beamer frame environment will allow
such verbatim examples to compile correctly [2].  Since the frame
environment name is customize-able, beamer code generated by ox-beamer
can be included inside the verbatim environment, simply by changing
the frame environment name via the :BEAMER_FRAME property.

This solution also works with instances of \againframe.

Refs:
[1] https://github.com/josephwright/beamer/issues/360
[2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
[3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/
---
 lisp/ox-beamer.el | 44 +---
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 82c8841aa..4a1e09b85 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -149,9 +149,17 @@ which is replaced with the subtitle."
   :package-version '(Org . "8.3")
   :type '(string :tag "Format string"))
 
+(defcustom org-beamer-frame-environment "orgframe"
+  "Name of the beamer frame environment."
+  :group 'org-export

Re: [BUG] beamer export

2024-01-26 Thread Leo Butler
On Fri, Jan 26 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> Apparently, LaTeX has really hard time processing verbatim code inside
>>> beamer frames.
>>
>> I looked again at the solution here:
>> https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim
>>
>> and it errors out with a recent version of pdflatex:
>>
>>This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) 
>> (preloaded format=pdflatex)
>>
>> This is, apparently, a known problem:
>>
>> https://github.com/josephwright/beamer/issues/360
>>
>> The end of that issue report includes a work-around that we might apply
>> in org. I have attached a patch for your feedback. The example that
>> stimulated this discussion compiles with the patch and the testsuite
>> shows no errors related to it.
>
> Thanks!
> I have concerns about your approach though.
>
> You are replacing all the frame environments with custom environment
> unconditionally. However, custom environment has downsides. For example,
> \againframe will stop working, as pointed earlier in the linked beamer
> thread
> https://github.com/josephwright/beamer/issues/360#issuecomment-708705250

The comment that you are citing shows how to define the custom
environment so that \againframe works correctly. See the attachment
`beamer-example-againframe.tex' and pdf. You can see that \againframe
works with the custom environment.

>
> Since the problem appears only when the frame contents contains
> \end{frame}, it may be sufficient to replace the standard frame
> environment with the workaround only in such scenario.

Yes, that might be true. But my feeling is that it would be simpler and
more robust to use the custom frame environment in most cases.

>
>> +;; Needed to set-up Beamer export.
>> +(defconst org-beamer--frame-environment
>> +  (concat "orgframe" (org-id-uuid))
>> +  "Name of the beamer frame environment.
>> +This is randomized to prevent collisions.")
>
> Please use constant name. (org-id-uuid) makes export randomized for no
> good reason.

There is a good reason to randomize (or at least make customize-able)
the environment name: so that beamer code generated by ox-beamer can be
safely inserted into org files and exported by ox-beamer. With a fixed
name for the environment, we will have just recreated the original
source of the bug report. As a compromise, in the attached patch, I have
made the environment name customize-able.

>
>>  ;; Install a default set-up for Beamer export.
>>  (unless (assoc "beamer" org-latex-classes)
>>(add-to-list 'org-latex-classes
>> -   '("beamer"
>> - "\\documentclass[presentation]{beamer}"
>> +   `("beamer"
>> + ,(concat "\\documentclass[presentation]{beamer}\n"
>> +  ;; Define an alias for the beamer frame 
>> environment
>> + "\\newenvironment<>{"
>> + org-beamer--frame-environment
>> + "}[1][]{\\begin{frame}[environment="
>> + org-beamer--frame-environment
>> + ",#1]}{\\end{frame}}")
>
> Please use `org-beamer-template' rather than modifying the class.
> Modifying the class may confuse users.

Ok, I have done so.

The docstring of `org-latex-classes' says:

The HEADER-STRING is the header that will be inserted into the
LaTeX file.  It should contain the \documentclass macro, and
anything else that is needed for this setup.

>From that, I figured that would be the correct place to put that
\newenvironment command. I have moved it, as requested.

Please see the revised patch. I believe that I have taken into account
your suggestions.

Leo

% Created 2024-01-26 Fri 11:42
% Intended LaTeX compiler: lualatex
\documentclass[bigger]{beamer}
\newenvironment<>{OrgFrame}[1][]{\begin{frame}[environment=OrgFrame,#1]}{\end{frame}}
\usetheme{default}

\begin{document}
\begin{OrgFrame}[label=repeatit,fragile]{Verbatim inside a Special Frame Environment}
\tiny
\begin{verbatim}
\begin{frame}[label={sec:org8bc49cc}]{Two columns}
\begin{columns}
\begin{column}{0.4\columnwidth}
\begin{itemize}
\item this slide consists of two columns
\item the first (left) column has no heading and consists of text
\item the second (right) column has an image and is enclosed in an
\alert{example} block
\end{itemize}
\end{column}
\end{verbatim}
\end{OrgFrame}

\againframe<2>{repeatit}
\end{document}


beamer-example-againframe.pdf
Description: beamer-example-againframe.pdf
F

Re: [BUG] beamer export

2024-01-25 Thread Leo Butler
On Wed, Jan 24 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I think the documentation and example needs to be corrected. I have
>> attached a patch.
>
> Thanks! Applied.
> https://git.sr.ht/~bzg/worg/commit/aedea59f

Attached is a second patch to de-lint the ox-beamer tutorial.

Leo

From 7a52949ce25c7576896785ba185f9bd6afc7f12b Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 23 Jan 2024 11:23:18 -0600
Subject: [PATCH] exporters/beamer/tutorial.org: clean lint warnings

* exporters/beamer/tutorial.org:  convert the informal footnote
markers to Org footnotes.
---
 exporters/beamer/tutorial.org | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/exporters/beamer/tutorial.org b/exporters/beamer/tutorial.org
index f40425ed..ae1ec751 100644
--- a/exporters/beamer/tutorial.org
+++ b/exporters/beamer/tutorial.org
@@ -33,7 +33,7 @@ keybindings]].
 
 * First steps
 ** The export template
-Starting with an empty file called =presentation.org= [1], say, the
+Starting with an empty file called =presentation.org= [fn:1], say, the
 first step is to insert the default org export template (=C-c C-e #=
 with the default keybindings). This will generate something that looks
 like this (some specific entries will vary):
@@ -74,7 +74,7 @@ Beamer specific options.  The following options are what I use:
 
 The first line enables the Beamer specific commands for org-mode (more
 on this below); the next two tell the LaTeX exporter to use the
-Beamer class and to use the larger font settings[2].  
+Beamer class and to use the larger font settings[fn:2].
 
 ** Outline levels for frames (slides)
 
@@ -178,7 +178,7 @@ org-mode has a special beamer sub-mode which provides an easy to use
 method for specifying block types (and columns as well, as we shall
 [[*Column view for slide and block customisation][see in the next section]]).
 
-To specify the type of block, you can type =C-c C-b= [3].  This brings up
+To specify the type of block, you can type =C-c C-b= [fn:3].  This brings up
 a keyboard driven menu in which you type a single letter to select the
 option you wish to apply to this headline.  For the above example, I
 typed =C-c C-b t=.  The options selected in this manner are also shown
@@ -348,10 +348,10 @@ changed easily.  Please read [[https://orgmode.org/manual/Beamer-Export.html#Bea
 
 * Footnotes
 
-[1] [[https://orgmode.org/worg/sources/org-tutorials/org-beamer/presentation.org][A previously created example presentation]] is available.
+[fn:1] [[https://orgmode.org/worg/sources/org-tutorials/org-beamer/presentation.org][A previously created example presentation]] is available.
 
-[2] I am a firm believer in using the largest font possible to
+[fn:2] I am a firm believer in using the largest font possible to
 encourage less text on slides. This is obviously a personal view.
 
-[3] org-beamer-mode must be turned on for this keybinding to be available.
+[fn:3] org-beamer-mode must be turned on for this keybinding to be available.
 
-- 
2.43.0



Re: [BUG] beamer export

2024-01-25 Thread Leo Butler
On Wed, Jan 24 2024, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>> 1. ox-latex export bug for src blocks containing direct LaTeX when
>>>>org-latex-src-block-backend is set to its default 'verbatim value
>>>
>>> This appears to be Beamer-specific problem with verbatim environments:
>>> https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim
>>>
>>> The solution might be to use [fragile] frame parameter, but that might
>>> have its own drawbacks:
>>> https://tex.stackexchange.com/questions/136240/drawbacks-of-using-fragile-frames-in-beamer
>>
>> Yes, an *automatic* solution may create more problems than it solves.
>> Although, I do note that ox-beamer does mark some frames as fragile already.
>> I wonder how difficult it would be to add a property drawer to frames,
>> so (amongst other things), they could be marked fragile?
>
> Hmm. Actually, that frame is already marked fragile.
> Yet, it is not enough...



> Apparently, LaTeX has really hard time processing verbatim code inside
> beamer frames.

I looked again at the solution here:

https://tex.stackexchange.com/questions/140719/verbatim-in-beamer-showing-error-file-ended-while-scanning-use-of-xverbatim

and it errors out with a recent version of pdflatex:

   This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023/Debian) 
(preloaded format=pdflatex)

This is, apparently, a known problem:

https://github.com/josephwright/beamer/issues/360

The end of that issue report includes a work-around that we might apply
in org. I have attached a patch for your feedback. The example that
stimulated this discussion compiles with the patch and the testsuite
shows no errors related to it.

>
>>>> 2. ox-beamer export bug as described in the attached org file
>>>
>>> This is not a bug. When you specify ignoreheading environment, you imply
>>> that the contents of the heading is to be included as is.
>>> If you want the contents to become a column, you should specify column
>>> environment.
>>
>> I see. That is not now the ignoreheading property is described. It says
>> [1]:
>>
>> ... As the text in the slide says, the left column is a list and the
>> right one is an image. The left column's headline text is ignored,
>> specified by =C-c C-b i= which tells org to *ignore* the headline
>> text completely.
>>
>> I think the documentation and example needs to be corrected. I have
>> attached a patch.
>
> Thanks! Applied.
> https://git.sr.ht/~bzg/worg/commit/aedea59f

Thanks. I can see the commit on master in git, but the webpage seems to
be unchanged.

https://orgmode.org/worg/exporters/beamer/tutorial.html

Leo

From 9cb3489e3fe80fb2e3996b737f528aa4db9ba62d Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 25 Jan 2024 09:48:20 -0600
Subject: [PATCH] lisp/ox-beamer.el:  randomize the beamer frame environment

* lisp/ox-beamer.el (org-beamer--frame-environment): new variable that
contains the name of an environment that serves as an alias for the
beamer frame environment.  The environment's definition is appended to
the set-up for beamer export.

(org-beamer--format-frame):  Replace the occurrence of \begin{frame}
and \end{frame} with the new environment's name.

Rationale: Code with \begin{frame} or \end{frame} cannot be embedded
in a verbatim environment inside a beamer frame due to a design
decision made by the beamer developers [1].  As suggested in that
report, defining an alias for the beamer frame environment will allow
such verbatim examples to compile correctly [2].

Refs:
[1] https://github.com/josephwright/beamer/issues/360
[2] https://github.com/josephwright/beamer/issues/360#issuecomment-708705250
[3] https://list.orgmode.org/orgmode/87le8eg1hs.fsf@localhost/T/
---
 lisp/ox-beamer.el | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 82c8841aa..be3003835 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -36,11 +36,23 @@
 (require 'cl-lib)
 (require 'ox-latex)
 
+;; Needed to set-up Beamer export.
+(defconst org-beamer--frame-environment
+  (concat "orgframe" (org-id-uuid))
+  "Name of the beamer frame environment.
+This is randomized to prevent collisions.")
+
 ;; Install a default set-up for Beamer export.
 (unless (assoc "beamer" org-latex-classes)
   (add-to-list 'org-latex-classes
-	   '("beamer"
-		 "\\documentclass[presentation]{beamer}"
+	   `("beamer"
+		 ,(concat "\\documentclass[presentation]{beamer}\n"
+  ;; Define an alias for the beamer frame environment
+

Re: Developing Moodle resources/sites with Org Mode

2024-01-18 Thread Leo Butler
 beautiful compared to plot. A difficulty
> is how to get the {#maxima-variable#} out of the maxima results and
> into the JSXgraph block. I /think/​ that's just a minor issue with
> noweb.

Yes, that's right. If you have a small example, please feel free to share.

>
> One thing that I am not sure I understand about your thoughts: do you
> envision a Moodle emulator based on org-mode, or do you just want to be
> able to write Moodle questions or glossaries with org-mode?
> I think an emulator is a bridge too far for now. What I want to do is
> run Maxima blocks to get a paper version of the exam with an answer
> key (for graders) and complete solutions (as an "exam wrapper" to
> return to the students with their graded exams so they can learn from
> the correct answers). Both questions and answers will have to be
> generated (the variable parts anyway) by Maxima because I want the
> capability to generate multiple different paper versions of any
> question/exam, perhaps even one version of the exam per student. Then
> for versatility I want the questions to be in a form that can at least
> be cut-and-pasted into Moodle, so I can use last year's exam questions
> as this year's problem set questions. With some tweaks, I hope to
> eventually automate the procedure of getting the questions into
> Moodle. The hurdles are correct XML format, grading tree, "publishing"
> process to include correct image files, the whole randomization and
> quality control subsystem (what STACK calls "deployment of
> variants"). I don't know how the latter can be made sense of in Org
> Mode. Even things like the random number seeds that index different
> variants might be interpreted differently in Org and STACK, breaking
> the connection between Org and STACK variants of a question. So lots
> of work to do.
>
> An emulator is possible ... we can run a Moodle server on our local computers 
> and see how we can get it to talk to Emacs.  But that is beyond my skill set 
> for now.

Ok, that clarifies things somewhat for me.

Best,
Leo

>
> Edward
>
> (Apologies for any formatting awkwardness; my Windows computer wants me to 
> write all outgoing mail with Outlook.  Need to figure out how to send 
> directly from Emacs.)

Re: Developing Moodle resources/sites with Org Mode

2024-01-17 Thread Leo Butler
? Am I off the mark? Are there better ways to do
> this? Maybe even setting up my own personal Moodle server and
> connecting Emacs to it as an external editor would work reasonably
> well and save me some of the pain? But it would be nice to export some
> things to formats other than Moodle: a glossary in LaTeX might be
> nice, for example, and quiz questions in Org mode could be used to
> generate paper tests as well as online Moodle tests.
>
> I would appreciate any thoughts.
>
> Edward


Hi Edward,

Thanks for your extended thoughts. I have had similar, but much less
articulate, thoughts for a while.

I have used org-mode to do all my STACK question authoring for a few
years now [1]. I do all the writing in emacs and then copy/paste into the
STACK textareas, test, repeat. It is not elegant, but it is easier than
working in a web-browser. It would be really nice to be able to create
the entire question in emacs, because defining graders in STACK is
pretty tedious.

I agree that we need ob-maxima.el to properly handle sessions. Note that
you can use Maxima to create graphs, too.

One thing that I am not sure I understand about your thoughts: do you
envision a Moodle emulator based on org-mode, or do you just want to be
able to write Moodle questions or glossaries with org-mode?

Best regards,
Leo

[1] 
https://sourceforge.net/p/maxima/mailman/maxima-discuss/thread/87a6d4ajgk.fsf%40t14.reltub.ca/#msg37634141

Re: [PATCH] ob-C.el compile-only header argument, was Re: How to use mpirun with C or C++ Org-babel?

2024-01-04 Thread Leo Butler
On Fri, Dec 22 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> What will happen if we have something like :results value or :results
>>> output instead of :results file link?
>>
>> Originally, I felt that only ":results file" makes sense. I have adopted
>> your suggestion, though, and added test cases so that the compiler
>> stderr output is caught.
>
> Thanks! This makes sense, but now the default behaviour (when no :results
> type is specified) is unexpected.
>
> When you have something like
>
> #+begin_src C :compile-only t :file foo :includes "stdio.h"
> printf("This is test");
> #+end_src

It should be "yes" not "t".

>
>
> , executing should yield file link, even though it is not explicitly
> specified.

Ok. But, isn't it a responsibility of org-babel to ensure that if :file
is set and :results is not, then the parameter list that is passed to
org-babel-*-execute includes a correctly set :result-params field
(i.e. it includes "file")? I mean, the docs say [1]:

‘file’  
 Interpret as a filename.  Save the results of execution of the code
 block to that file, then insert a link to it.  

I would prefer not to fiddle in ob-*.el to implement a policy that
should be implemented at a higher level.

[1] (info "(org) Results of Evaluation"):

>
> And when you have compilation error,
>
> #+begin_src C :compile-only t :file foo :includes "stdio.h"
> printf("This is test")
> #+end_src
>
>
> the result may be empty - buffer displayed by `org-babel-eval' is
> probably enough.

Can you tell me what behaviour you expect? No #+RESULTS: ?

>
> Basically, Org babel promises DWIM behavior when :results type is not
> explicitly stated.

I am happy to modify the patch to make ob-C.el conform to the stated (or
implied) Org policies. But, "dwim" hurts my head.

>
> P.S. In my testing, I wrote
>
> #+begin_src C :compile-only t :file foo :includes "stdio.h"
> (printf "This is test")
> #+end_src
>
> and was staring at the compilation error for a good minute, trying to
> understand what the hell did I do wrongly 臘.

Ahhh! Lisp syntax is so much nicer to read.

Happy New Year,
Leo

Re: How to use mpirun with C or C++ Org-babel?

2023-12-20 Thread Leo Butler
On Thu, Dec 14 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> From 7d8e406bc4a92e2e2eab772b2671dcd72ca8c202 Mon Sep 17 00:00:00 2001
>> From: Leo Butler 
>> Date: Tue, 12 Dec 2023 12:32:41 -0600
>> Subject: [PATCH] lisp/ob-C.el: add :compile-only header to compile to a named
>>  target
>
> Thanks for the patch!
>
> You should also announce the new feature in ORG-NEWS and document it in
> WORG.
>

Attached is the patch to WORG that documents the change.

Leo

From 927a255e6c4abb34bf797f120c7a5186b7f113b7 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Wed, 20 Dec 2023 12:06:13 -0600
Subject: [PATCH] ob-doc-C.org: document compile-only header

* org-contrib/babel/languages/ob-doc-C.org: Add :compile-only to the
list of header arguments.  Add a subsection, Compiling to a named
binary, that describes its use.

Ref:
https://list.orgmode.org/orgmode/87h6kdyh52.fsf...@t14.reltub.ca/T/#u
---
 org-contrib/babel/languages/ob-doc-C.org | 114 +++
 1 file changed, 114 insertions(+)

diff --git a/org-contrib/babel/languages/ob-doc-C.org b/org-contrib/babel/languages/ob-doc-C.org
index 14d83135..89f6e91f 100644
--- a/org-contrib/babel/languages/ob-doc-C.org
+++ b/org-contrib/babel/languages/ob-doc-C.org
@@ -69,6 +69,31 @@ the results of evaluation inserted into the buffer.
 : #+results:
 : : 2
 
+With C and C++, =ob-C.el= can also compile code to a named binary.
+
+#+name: c++-compile-only.org
+#+begin_src org :exports code :results replace
+,#+name: c++-compile-only
+,#+header: :file ./hello-world
+,#+header: :results file
+,#+header:  :includes 
+,#+begin_src C++
+std::cout << "Hello World++\n";
+,#+end_src
+#+end_src
+
+#+RESULTS: c++-compile-only.org
+#+name: c++-compile-only
+#+header: :file ./hello-world
+#+header: :results file
+#+header:  :includes 
+#+begin_src C++
+std::cout << "Hello World++\n";
+#+end_src
+
+: #+RESULTS: c++-compile-only
+: [[file:./hello-world]]
+
 ** About C
 C dates back to the 1970's.
 It was devised by Kernighan and Ritchie.
@@ -167,6 +192,10 @@ It features:
  (C & C++ only) useful for linking with a library, may be given
  =-L/path/to/lib= and =-llibrary= instructions.
 
+- =:compile-only= ::
+ (C & C++ only) compile the code block. The compiled binary is
+ /not/ executed; this file is named by the =:file= header argument.
+
 ** Sessions
There is no support for sessions
 
@@ -256,6 +285,91 @@ When several libraries need to be included, =:includes= value should be set to a
 : Hello World!
 : 4
 
+** Compiling to a named binary
+:PROPERTIES:
+:ID:   0bf900ad-b1f3-4484-824b-cff84873e3d6
+:END:
+
+To compile source code to a dedicated binary, set the header argument
+~:compile-only~ to ~yes~. In this case, the binary file is /not/
+executed when the code block is evaluated. The results of the code
+block can also be inserted into the Org file.
+
+*** Compiling =hello-world=
+
+Set the ~:compile-only~ header argument to ~yes~ to produce the binary
+file =hello-world=. Note that an unset ~:file~ header argument throws
+an error.
+
+#+name: compile-only-insert-link.org
+#+begin_src org :exports code :results replace
+,#+name: compile-only-insert-link
+,#+header: :compile-only yes
+,#+header: :results file
+,#+header: :file ./hello-world
+,#+header: :includes 
+,#+begin_src C++
+std::cout << "Hello World!\n";
+,#+end_src
+#+end_src
+
+#+RESULTS: compile-only-insert-link.org
+#+name: compile-only-insert-link
+#+header: :compile-only yes
+#+header: :results file
+#+header: :file ./hello-world
+#+header: :includes 
+#+begin_src C++
+std::cout << "Hello World!\n";
+#+end_src
+
+With ~:results file~, evaluation of the code block inserts a link to
+the binary:
+
+: #+RESULTS: compile-only-insert-link
+: [[file:./hello-world]]
+
+*** Outputting compilation errors
+
+When ~:results output~ is set on the code block, compiler errors and
+warnings are inserted as results of the code block. In this example, a
+semi-colon is omitted, which throws a syntax error.
+
+#+name: compile-only-errors.org
+#+begin_src org :exports code :results replace
+,#+name: compile-only-errors
+,#+header: :compile-only yes
+,#+header: :results output
+,#+header: :file ./hello-world
+,#+header: :includes 
+,#+begin_src C++
+std::cout << "Hello World!\n"
+,#+end_src
+#+end_src
+
+#+RESULTS: compile-only-errors.org
+#+name: compile-only-errors
+#+header: :compile-only yes
+#+header: :results output
+#+header: :file ./hello-world
+#+header: :includes 
+#+begin_src C++
+std::cout << "Hello World!\n"
+#+end_src
+
+The result of evaluation of the code block is the compiler message
+(pathnames elided):
+
+#+RESULTS: compile-only-errors
+: ./hello-world.cpp: In function ‘int main()’:
+: ./hello-world.cpp:9:30: error: expected ‘;’ before ‘return’
+: 9 | std::cout << "Hello World!\n"
+:   |   

Re: org-ditaa woes

2023-12-20 Thread Leo Butler
On Tue, Oct 24 2023, Ihor Radchenko  wrote:

> Florin Boariu  writes:
>
>> I can offer to try my luck with writing a patch for ob-ditaa.el, but
>> I'm not knowledgeable enough (or have enough time on my hands) to
>> actually keep maintaining it :-p
>
> Writing a patch is also welcome.

Here is a patch to the documentation. It documents currently
undocumented *features* of ob-ditaa.

I have *removed* mention of work-arounds to execute scripts. I have also
taken the liberty of re-writing the two source blocks to use org src
blocks.

I will submit a patch to ob-ditaa.el (likely in January).

Leo

From 15cdaff68d3ecd1348ac8b3b3998cb146e6d5345 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 26 Oct 2023 20:49:41 -0500
Subject: [PATCH] org-contrib/babel/languages/ob-doc-ditaa.org: update
 documentation

* org-contrib/babel/languages/ob-doc-ditaa.org: Add a subsection,
Customization Options, that documents the four DEFCUSTOM variables.
Document the header arguments eps and pdf, which control how output is
created.  Modify the existing examples so that the org code that is
exported also creates the code-blocks that are executed.

Ref: https://list.orgmode.org/ZTEML8zWrB6kQflk@toolbox/T/
---
 org-contrib/babel/languages/ob-doc-ditaa.org | 48 +++-
 1 file changed, 36 insertions(+), 12 deletions(-)

diff --git a/org-contrib/babel/languages/ob-doc-ditaa.org b/org-contrib/babel/languages/ob-doc-ditaa.org
index 0ae949c2..f2c31a49 100644
--- a/org-contrib/babel/languages/ob-doc-ditaa.org
+++ b/org-contrib/babel/languages/ob-doc-ditaa.org
@@ -57,18 +57,34 @@ Activate evaluation of =ditaa= source code blocks by adding =ditaa= to
  '((ditaa . t))) ; this line activates ditaa
 #+END_SRC
 
+** Customization Options
+Org needs to know a few things about =ditaa= and the =java= executable in order to function. The following is a list of variables that can be customized.
+
+- org-ditaa-jar-path :: The path to the =ditaa= jar file.
+- org-babel-ditaa-java-cmd :: The name or path to the Java executable used to run the =ditaa= jar file.
+- org-ditaa-eps-jar-path :: The path to the =ditaaeps= jar file. [[https://ditaa-addons.sourceforge.net/][DitaaEps]] is maintained as part of the [[https://ditaa-addons.sourceforge.net/][ditaa-addons]] project.
+- org-ditaa-jar-option :: The prefix used before the =ditaa= jar path. The default is =-jar=.
+
 * Babel Features for ditaa Code Blocks
 ** Header Arguments
-   - file :: =ditaa= source code blocks require that an output file be specified
-   - cmdline :: specify [[http://ditaa.sourceforge.net/#usage][command line arguments]] for =ditaa=
-   - java :: arguments for the =java= runtimes (JRE) 
+   - file :: the output filename (mandatory)
+   - cmdline :: [[http://ditaa.sourceforge.net/#usage][command line arguments]] for =ditaa=
+   - java :: arguments for the =java= runtimes (JRE)
+   - eps :: produce an =eps= output file using =ditaaeps=
+   - pdf :: produce a =pdf= output file using =ditaaeps= followed by =epstopdf=
+
 ** Sessions
=ditaa= does not support sessions.
 ** Result Types
 =Ditaa= source code blocks return a link to a [[http://www.libpng.org/pub/png/][png]] bitmap file.
 * Examples of Use
+** Hello World
 The obligatory Hello World! example in =ditaa=:
-#+BEGIN_EXAMPLE
+
+#+NAME: hello-world.org
+#+BEGIN_SRC org :exports code :results replace
+,#+NAME: hello-world
+,#+HEADER: :exports results
 ,#+BEGIN_SRC ditaa :file images/hello-world.png
 +--+
 |  |
@@ -76,9 +92,11 @@ The obligatory Hello World! example in =ditaa=:
 |  |
 +--+
 ,#+END_SRC
-#+END_EXAMPLE
+#+END_SRC
 
-#+header: :exports results
+#+RESULTS: hello-world.org
+#+NAME: hello-world
+#+HEADER: :exports results
 #+BEGIN_SRC ditaa :file images/hello-world.png
 +--+
 |  |
@@ -87,23 +105,29 @@ The obligatory Hello World! example in =ditaa=:
 +--+
 #+END_SRC
 
-#+RESULTS:
+#+RESULTS: hello-world
 [[file:images/hello-world.png]]
+** Passing command-line options to =ditaa=
 
 Now, round all corners by passing =ditaa= the =-r,--round-corners=
 command line switch.
 
-#+BEGIN_EXAMPLE
-#+BEGIN_SRC ditaa :file images/hello-world-round.png :cmdline -r
+#+NAME: hello-world-round.org
+#+BEGIN_SRC org :exports code :results replace
+,#+NAME: hello-world-round
+,#+HEADER: :exports results
+,#+BEGIN_SRC ditaa :file images/hello-world-round.png :cmdline -r
 +--+
 |  |
 | Hello World! |
 |  |
 +--+
+,#+END_SRC
 #+END_SRC
-#+END_EXAMPLE
 
-#+header: :exports results
+#+RESULTS: hello-world-round.org
+#+NAME: hello-world-round
+#+HEADER: :exports results
 #+BEGIN_SRC ditaa :file images/hello-world-round.png :cmdline -r
 +--+
 |  |
@@ -112,6 +136,6 @@ command line switch.
 +--+
 #+END_SRC
 
-#+RESULTS:
+#+RESULTS: hello-world-round
 [[file:images/hello-world-round.png]]
 
-- 
2.42.0



[PATCH] ob-C.el compile-only header argument, was Re: How to use mpirun with C or C++ Org-babel?

2023-12-19 Thread Leo Butler
On Thu, Dec 14 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> From 7d8e406bc4a92e2e2eab772b2671dcd72ca8c202 Mon Sep 17 00:00:00 2001
>> From: Leo Butler 
>> Date: Tue, 12 Dec 2023 12:32:41 -0600
>> Subject: [PATCH] lisp/ob-C.el: add :compile-only header to compile to a named
>>  target
>
> Thanks for the patch!

Thank you for the feedback.

>
>> * lisp/ob-C.el (org-babel-C-execute): The new header argument,
>> `:compile-only', causes source and compiled binary files to be named
>> using the `:file' header argument.  When `:compile-only' is set,
>> execution of source block ends at compilation.  The naming of source
>> and binary filenames is factored out to `org-babel-C-src/bin-file'.
>
> What will happen if we have something like :results value or :results
> output instead of :results file link?

Originally, I felt that only ":results file" makes sense. I have adopted
your suggestion, though, and added test cases so that the compiler
stderr output is caught.

>
>> * lisp/ob-C.el (org-babel-C-src/bin-file): A new function that factors
>> out the setting of source and binary filenames.  It also signals an
>> error if `:compile-only' is set, but `:file' is not.
>> * testing/examples/ob-C-test.org: Add three example that exercise the
>> `:compile-only' header argument, including one that causes an error.
>> * testing/lisp/test-ob-C.el: Add three tests of the `:compile-only'
>> header argument.  New tests: ob-C/set-src+bin-file-name-{1,2,3}.
>
> You should also announce the new feature in ORG-NEWS and document it in
> WORG.

I have added the announcement in this patch. I will submit a separate
patch for worg.

>
>> +(compile-only . (nil no t yes)))
>
> Why nil/t? No other header argument allow "nil" or "t". Just yes/no.

Ok. I also noticed (in a separate thread) that it should be

(compile-only . ((no yes))

>
>> +(defun org-babel-C-src/bin-file (params src? compile-only?)
>> +  "Return the src or bin filename to `org-babel-C-execute'.
>> +
>> +If `SRC?' is T, a file extension is added to the filename.  By
>
> Just SRC?. You should only quote Elisp symbols and upcase the function
> arguments. See
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html
>
> Also, why upcase "T"?

Corrected.

>
>> +default, the filename is created by `org-babel-temp-file'. If
>> +`COMPILE-ONLY?' is T, the filename is taken from the `:file'
>
> I think quoting :file is not necessary.

Yes.

>
>> +field in `PARAMS'; if that is NIL, an error occurs."
>
> No need to upcase NIL.

Yes.

> Also, "if that is nil, throw an error" - this is more common style
> (saying what function does).

Done.

>
>> +  (let ((f (cdr (assq :file params
>
> Please avoid short variable names - they are harder to understand and
> search in code.

Done.

>
>> +(when (and compile-only? (null f))
>> +  (error "Error: When COMPILE-ONLY is T or YES, output FILE needs to be 
>> set"))
>
> t or "yes". Also, what does "output FILE" refer to? Upcasing implies
> function argument, but you are referring to :file header argument in PARAMS.

Ok, I think the current error message is consistent with Gnu
standards.

>
>> +(let* ((file (cond (compile-only? f) (src? "C-src-") (t "C-bin-")))
>> +   (ext (if src? (pcase org-babel-c-variant
>> +   (`c ".c") (`cpp ".cpp") (`d ".d"))
>
> We usually split `cond' and `case' into multiple lines for readability.
> Otherwise, it is confusing, especially in `let' forms where one can
> confuse `cond' forms with `let' bindings.

Ok. I guess, to paraphrase, that readability is in the eye of the beholder.

>
>> +(unless compile-only?
>> +  (let ((results
>> + (org-babel-eval
>> ...
>
> No return value at all? I'd expect file link to be returned, as we
> discussed in another thread. Also, see the above considerations about
> :results value/output.

See my comment above.

> We might want return the compiler output for
> :results output.

Done.

> Or maybe even arrange `org-babel-eval-error-notify' to
> display compile-mode window when there are compilation warnings.

Yes, this is already done by `org-babel-eval' in `org-babel-C-execute'.

>
>> --- a/testing/examples/ob-C-test.org
>> +++ b/testing/examples/ob-C-test.org
>> @@ -174,3 +174,29 @@ std::cout << "\"line 1\"\n";
>>  std::cout << "\"line 2\"\n";
>>  std::cout <&l

Re: How to use mpirun with C or C++ Org-babel?

2023-12-13 Thread Leo Butler
On Fri, Dec 08 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I submitted an imperfect patch some time ago [1] that targeted your use
>> case: allow ob-C.el to create a named binary.

> Note that I did not oppose the above behaviour when the result of
> evaluation is just compiling to :file. The problem was with compiling to
> a :file and _also_ executing it.
>
> If you want to propose a patch that will allow compile-only, I see no
> problem at all.

Ok, thank you for the clarification. I had gone on holidays after you
put up the poll and lost track.

Please see the attached patch.

Leo

From 7d8e406bc4a92e2e2eab772b2671dcd72ca8c202 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 12 Dec 2023 12:32:41 -0600
Subject: [PATCH] lisp/ob-C.el: add :compile-only header to compile to a named
 target

* lisp/ob-C.el (org-babel-C-execute): The new header argument,
`:compile-only', causes source and compiled binary files to be named
using the `:file' header argument.  When `:compile-only' is set,
execution of source block ends at compilation.  The naming of source
and binary filenames is factored out to `org-babel-C-src/bin-file'.
* lisp/ob-C.el (org-babel-C-src/bin-file): A new function that factors
out the setting of source and binary filenames.  It also signals an
error if `:compile-only' is set, but `:file' is not.
* testing/examples/ob-C-test.org: Add three example that exercise the
`:compile-only' header argument, including one that causes an error.
* testing/lisp/test-ob-C.el: Add three tests of the `:compile-only'
header argument.  New tests: ob-C/set-src+bin-file-name-{1,2,3}.

Refs: https://list.orgmode.org/87fs81egk5@t14.reltub.ca/
https://list.orgmode.org/87msukbadu.fsf@localhost/
---
 lisp/ob-C.el   | 83 --
 testing/examples/ob-C-test.org | 26 +++
 testing/lisp/test-ob-C.el  | 32 +
 3 files changed, 108 insertions(+), 33 deletions(-)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 0278fc02a..dd772dc97 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -53,7 +53,8 @@
 (main. :any)
 (flags   . :any)
 (cmdline . :any)
-(libs. :any))
+(libs. :any)
+(compile-only . (nil no t yes)))
   "C/C++-specific header arguments.")
 
 (defconst org-babel-header-args:C++
@@ -128,17 +129,32 @@ This function is called by `org-babel-execute-src-block'."
   "Expand C BODY according to its header arguments PARAMS."
   (let ((org-babel-c-variant 'c)) (org-babel-C-expand-C body params)))
 
+(defun org-babel-C-src/bin-file (params src? compile-only?)
+  "Return the src or bin filename to `org-babel-C-execute'.
+
+If `SRC?' is T, a file extension is added to the filename.  By
+default, the filename is created by `org-babel-temp-file'. If
+`COMPILE-ONLY?' is T, the filename is taken from the `:file'
+field in `PARAMS'; if that is NIL, an error occurs."
+  (let ((f (cdr (assq :file params
+(when (and compile-only? (null f))
+  (error "Error: When COMPILE-ONLY is T or YES, output FILE needs to be set"))
+(let* ((file (cond (compile-only? f) (src? "C-src-") (t "C-bin-")))
+   (ext (if src? (pcase org-babel-c-variant
+	   (`c ".c") (`cpp ".cpp") (`d ".d"))
+  org-babel-exeext)))
+  (org-babel-process-file-name
+   (if compile-only? (concat file ext)
+ (org-babel-temp-file file ext))
+
 (defun org-babel-C-execute (body params)
   "Execute C/C++/D BODY according to its header arguments PARAMS.
 This function should only be called by `org-babel-execute:C' or
 `org-babel-execute:C++' or `org-babel-execute:D'."
-  (let* ((tmp-src-file (org-babel-temp-file
-			"C-src-"
-			(pcase org-babel-c-variant
-			  (`c ".c") (`cpp ".cpp") (`d ".d"
-	 (tmp-bin-file			;not used for D
-	  (org-babel-process-file-name
-	   (org-babel-temp-file "C-bin-" org-babel-exeext)))
+  (let* ((compile-only? (let ((c (cdr (assq :compile-only params
+  (or (string= c "t") (string= c "yes"
+ (tmp-src-file (org-babel-C-src/bin-file params t compile-only?))
+	 (tmp-bin-file (org-babel-C-src/bin-file params nil compile-only?)) ;not used for D
 	 (cmdline (cdr (assq :cmdline params)))
 	 (cmdline (if cmdline (concat " " cmdline) ""))
 	 (flags (cdr (assq :flags params)))
@@ -170,31 +186,32 @@ This function should only be called by `org-babel-execute:C' or
 		libs)
 	""))
   (`d nil)) ;; no separate compilation for D
-(let ((results
-	   (org-babel-eval
-	(pcase org-babel-c-variant
-	  ((or `c `cpp)
-	   (concat tmp-bin-file cmdline))
-	  (`d
-	   (format "%s %s %s %s"
-		   org-babel-D-compiler
-		

Re: How to use mpirun with C or C++ Org-babel?

2023-12-08 Thread Leo Butler
On Fri, Dec 08 2023, tbanelwebmin  wrote:

> Caution: This message was sent from outside the University of Manitoba.
>
> On 23-12-08 00:10, Edgar Lux wrote:
>
> Hello, I found [1][2] that it is possible to change the compiler for C 
> and C++
> source blocks. I would like to know if there is a way to add =mpirun -np 
> 2=
> (where 2 can be any other number) to run the resulting executable. 
> Thanks! [1] 
> https://orgmode.org/worg//org-contrib/babel/languages/ob-doc-C.html [2] 
> https://github.com/gheber/literate-hdf5
>
> I guess you want to run the executable after it has been compiled, with a 
> command
> like this one:
>
> mpirun -np 2 /tmp/babel-ad2pdk/C-bin-JTvjS4
>
> Currently it is not possible.
>
> There is the :cmdline specifier which adds parameters to the executable, like 
> this:
>
> #+begin_src C++ :cmdline AAA BBB CCC
> int main (int nargs, char** argv)
> {
>// argv will be {
>//   "/tmp/babel-ad2pdk/C-bin-JTvjS4",
>//   "AAA",
>//   "BBB",
>//   "CCC"
>// }
> }
> #+end_src
>
> Those parameters come AFTER the executable, whereas mpirun should come BEFORE 
> the
> executable.
>
> An extension may be written in ob-C.el, in the org-babel-C-execute function.
> The relevant line is:
>   (concat tmp-bin-file cmdline)
>
> If you want to contribute...

If you are wanting to run jobs with mpirun, then I will guess that they
are relatively long-running. However, ob-C.el does not support
asynchronous (background) execution, so your emacs would be tied up for
the duration. I doubt you want that.

I submitted an imperfect patch some time ago [1] that targeted your use
case: allow ob-C.el to create a named binary. Unfortunately, Ihor
dropped the issue due to lack of interest from other users.

My goal was to enable something like this to work:

#+begin_src cpp :includes  :results none :file ./hello-world
std::cout << "Hello World!\n";
#+end_src

#+begin_src bash :async t
mpirun -np 4 ./hello-world
#+end_src

As I said, the patch I wrote was not perfect, but I am happy to re-visit
the issue. The ability to create named binaries would significantly
increase the usability of ob-C for projects where you want to compile
the source once and run the binary repeatedly for potentially long
periods of time.

Leo

[1] https://list.orgmode.org/87fs81egk5@t14.reltub.ca/


Re: Getting email from MS outlook into emacs

2023-12-07 Thread Leo Butler
On Thu, Nov 30 2023, "Fraga, Eric"  wrote:

> 
> Caution: This message was sent from outside the University of Manitoba.
> 
>
> On Wednesday, 29 Nov 2023 at 14:08, Presnell,Brett Douglas wrote:
>> I had to deal with this last spring.  I finally got things working again
>> with mbsync, msmtp, mu/mu4e, and for the oauth stuff, pizauth.  This
>> combination has worked well for me ever since.  Most of the details can
>> be found at
>
> Thank you for this.  Very useful.  I have davmail working for me for
> authentication so I'm going to stick to what's working.  However, it's
> nice to know that there is another route possible should davmail stop
> working.  But sad that we have to through these contortions just to
> access our email.

Aargh. Thanks for you post and webpage, Brett. It set me off to try to
get oath2.el working with gnus (failed effort #2).

But, I did learn several things, including this post:

https://sourceforge.net/p/davmail/mailman/davmail-users/thread/x2ey374g953.fsf%40vestur.ifi.uio.no/

At the bottom of the thread, the developer of davmail recommends setting

davmail.imapAlwaysApproxMsgSize=true

in the configuration file. That one change has made MS outlook + gnus as
fast (or slow) as it was before needing the davmail shim.

Leo


Re: What is the status of ob-maxima.el? Is this a bug?

2023-12-05 Thread Leo Butler
On Tue, Dec 05 2023, "Fraga, Eric"  wrote:

> On Tuesday,  5 Dec 2023 at 16:59, Leo Butler wrote:
>> You mentioned returning a value from a maxima code block. 
>
> By this, I mean the value of the last sexp as some other src blocks do
> (elisp? octave? Not sure which...).  It's what I would expect to see if
> I were to specify ":results value".

I think it should be easy to provide this for a few data types (matrix,
string, maybe list), but I think the conversion from a Lisp sexp to an
ELisp sexp will need a lot of assumptions. E.g. how to convert the
Maxima list:

[[a,b],[c,d,[e,f]]]

Or maybe such cases are not important?

Also, what would we do with an arbitrary mathematical expression? Return
a printed representation?

>
> And your improvements definitely look good!  Thanks.  I use maxima a lot
> for teaching so will need to reconsider the material on some of my
> slides (next year... :-)).
>
> I also use embedded Calc as it's easier to incorporate directly in text,
> especially in org, but Calc is not quite as capable as maxima as a
> computer algebra system.

Thanks.

I have used Calc, but never really got the hang of it.

Developing a working session for maxima would make it more feasible to
use it directly in text, as you are using Calc.

Leo


Re: What is the status of ob-maxima.el? Is this a bug?

2023-12-05 Thread Leo Butler
On Tue, Dec 05 2023, "Fraga, Eric"  wrote:

> On Tuesday,  5 Dec 2023 at 16:42, Leo Butler wrote:
>> With recent versions of ob-maxima.el, you can set header arguments to
>> get the behaviour Eduardo expected:
>
> Thank you.  This is great news.
>
> I'm going to have to upgrade as the version I'm currently using (from
> 1-2 months ago, I think) doesn't seem to pay attention to :cmdline
> --quiet and/or :results raw.

Yes, it is relatively recent work (see below).

You mentioned returning a value from a maxima code block. I wonder if
you could elaborate? I could imagine either the lisp sexp of the last
expression or the printed representation (e.g. in linear/1d form). But
maybe you have something else in mind?

Leo


#+begin_src elisp :exports results
  (org-version)
#+end_src

#+RESULTS:
: 9.7-pre

#+NAME: batch-quiet-maxima
#+HEADER: :batch batch
#+HEADER: :exports results
#+HEADER: :results raw
#+HEADER: :wrap example
#+HEADER: :cmdline --quiet
#+BEGIN_SRC maxima
  rat(1/(x+1) + x/(x-1));
#+END_SRC

#+RESULTS: batch-quiet-maxima
#+begin_example
(%i1) rat(1/(x+1)+x/(x-1))
  2
 x  + 2 x - 1
(%o1)/R/ 
 2
x  - 1
#+end_example


Re: What is the status of ob-maxima.el? Is this a bug?

2023-12-05 Thread Leo Butler
On Tue, Dec 05 2023, "Fraga, Eric"  wrote:

> I think ob-maxima will only output the actual explicit "output" of the
> script, so something like
>
> #+begin_src maxima
> print(2+3);
> #+end_src
>
> should work.

With recent versions of ob-maxima.el, you can set header arguments to
get the behaviour Eduardo expected:

#+NAME: batch-quiet-maxima
#+HEADER: :batch batch
#+HEADER: :results raw
#+HEADER: :wrap example
#+HEADER: :cmdline --quiet
#+BEGIN_SRC maxima
  rat(1/(x+1) + x/(x-1));
#+END_SRC

See "An example with line numbering" at
https://orgmode.org/worg//org-contrib/babel/languages/ob-doc-maxima.html

Leo


Re: bash source code block: problem after ssh commands

2023-11-17 Thread Leo Butler
On Fri, Nov 17 2023, Ihor Radchenko  wrote:

> I was only able to reproduce your problem with ssh asking a password.
> We are discussing the reproduced case.
>
> If you see problems with
>
>#+begin_src bash :results output
>ssh coch...@fruc.u-strasbg.fr "echo foo>foo_file"
>echo "bar"
>#+end_src
>
> even when ssh does not ask for a password, please provide more detailed
> reproducer that we can replicate locally without guessing your ssh config.

I think you are confused, Ihor. The bug was confirmed here:

https://list.orgmode.org/orgmode/87bkcmlor9@t14.reltub.ca/

I mis-identified the culprit; you corrected me by pointing out the bug
is in `process-file'. And you confirmed the bug:

https://list.orgmode.org/orgmode/87fs1xbis1.fsf@localhost/

Russell Adams and I suggested ssh-specific work-arounds that prevent ssh
from grabbing stdin (either -n or -f).

Leo


Re: [TASK] Allow customizeable ditaa executable in ob-ditaa.el

2023-11-13 Thread Leo Butler
On Sat, Nov 11 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> And even if we do want to add certain features in future (like
>>> supporting ditaa executable herein), it does not mean that we have to
>>> rush them by any cost.
>>
>> Ihor, I don't understand that sentence.
>>
>> The *documentation* patch was intended to show that ob-ditaa did not
>> need to be changed. A user can already run ditaa from a script file by
>> setting the customization variables appropriately (or, inappropriately,
>> as Max said ;-) ).
>
> Let me elaborate.
> The below explanation in your patch relies upon the implementation
> detail in `org-babel-execute:ditaa' - how the ditaa command is called.
> however, it can easily happen that we change that detail in future.

Thanks for your clarifications here and in a related email. 

> In fact, your explanation is already not correct for
> :file foo.eps - org-ditaa-jar-path value is ignored in such scenario:

You say `not correct', I say `mutatus mutandis'.

>
> (cmd (concat org-babel-ditaa-java-cmd
> " " java " " org-ditaa-jar-option " "
> (shell-quote-argument
>  (expand-file-name
>   (if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
> " " cmdline
> " " (org-babel-process-file-name in-file)
> " " (if pdf-cmd
> eps-file
>   (org-babel-process-file-name out-file
>
> Further, it won't help with the discussed problem -
> trying
> (setq org-ditaa-jar-path "flatpak-spawn --host toolbox run ditaa") will
> simply fail when passed through `shell-quote-argument'.

The patch says "Users may need to use a script to run ditaa." It does
not mention passing arbitrary command strings.

>
> And now imagine that we change how CMD is produced in future. (For
> example, there is a WIP branch that unifies escaping command arguments
> to avoid vulnerabilities). Your documentation patch may cease working
> any moment, causing damage to users who tried to follow it. Or we may
> have to constrain the ways we change the internal implementation details
> in order to not break the existing documentation. Either way is not good
> and that's why I am saying no to your proposed documentation change.

Ok, I have a clearer idea of how to proceed.

Leo


Re: [TASK] Allow customizeable ditaa executable in ob-ditaa.el

2023-11-10 Thread Leo Butler
On Fri, Nov 10 2023, Max Nikulin  wrote:

> On 10/11/2023 10:19, Leo Butler wrote:
>> On Thu, Nov 09 2023, Max Nikulin wrote:
>> 
>>> diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el
> [...]
>>> should allow to set :java to
>>>
>>>  flatpak-spawn --host toolbox run /usr/bin/ditaa
>>>
>>> without abusing of org-ditaa-jar-path. Untested.
>> 
>> Doesn't this abuse the `java' header argument, which is intended to pass
>> arguments to the java runtime?
>
> or `org-babel-ditaa-java-cmd'. My point is that requirement of non-empty 
> `org-ditaa-jar-path' confused Florin to the degree when workarounds 
> looked impossible. Notice that setting
>
>  org-ditaa-jar-path "/usr/bin/ditaa"
>
> still requires spreading of "flatpack-spawn ..." over 
> `org-babel-ditaa-java-cmd', :java, and `org-ditaa-jar-option'. 
> fortunately some of these options may be sent empty and other will not 
> quote spaces, etc. Whole "flatpack-spawn ... ditaa" command can not be 
> put to `org-ditaa-jar-path'

Hi Max,

Let me back up for a second: I wrote in the documentation patch

"Users may need to use a script to run ditaa."

That is a very circumspect statement. That is not saying that we can
throw any command at ob-ditaa and it will work.

>
>> I think that it would be best to implement the change to mirror that
>> done in ob-plantuml, as Ihor suggested earlier.
>
> Agree. I appreciate consistency in treatment of similar cases.

I am glad we agree. Now let me tell you my dilemma: a while ago, I
suggested a patch to implement similar functionality for ob-maxima. The
patch used customization variables, much like ob-plantuml does. Ihor's
feedback was that this was not a good approach (too much room for
accidental breakage, etc.). Eventually, the patch was amended to acheive
the same goals using new header arguments.

So, now, in my opinion, consistency would dictate that we re-visit the
changes made to ob-plantuml, re-fashion them and do something similar
with ob-ditaa. Except, users have likely become accustomed to using
ob-plantuml as it is...

Thoughts?

>
> I am not sure in the following idea. Perhaps a concept of "launcher" (or 
> "runner") may be introduced. Launchers may be stacked. So for a jar file 
> launcher is "java @:java -jar" that may be combined with "toolbox run" 
> and "flatpak-spawn --host" launchers.
>
>> My reading of the documentation and ob-plantuml.el is that it is not
>> possible to use the `java' header argument in the way you propose for
>> ob-ditaa.el.
>
> Since nobody has proposed a patch for ob-ditaa, I decided that making a 
> workaround easier is an improvement.

I am not in favour of a band-aid, it will hand-cuff us in the future.

I explained above why I haven't proposed a patch to ob-ditaa, yet.

Best,
Leo



Re: [TASK] Allow customizeable ditaa executable in ob-ditaa.el

2023-11-10 Thread Leo Butler
On Fri, Nov 10 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> While I was reviewing the documentation, ob-doc-ditaa.org, and the
>> source, ob-ditaa.el, I realized that there is a simple way to run a
>> script file instead of a jar file. The documentation patch includes such
>> an example.
>
> Org cannot support every possible feature.

Agreed.

> And even if we do want to add certain features in future (like
> supporting ditaa executable herein), it does not mean that we have to
> rush them by any cost.

Ihor, I don't understand that sentence.

The *documentation* patch was intended to show that ob-ditaa did not
need to be changed. A user can already run ditaa from a script file by
setting the customization variables appropriately (or, inappropriately,
as Max said ;-) ).

Leo


Re: [TASK] Allow customizeable ditaa executable in ob-ditaa.el

2023-11-09 Thread Leo Butler
On Thu, Nov 09 2023, Max Nikulin  wrote:

> On 09/11/2023 10:17, Leo Butler wrote:
>> While I was reviewing the documentation, ob-doc-ditaa.org, and the
>> source, ob-ditaa.el, I realized that there is a simple way to run a
>> script file instead of a jar file.
>
>
> It is better to avoid obstacles than to document them.

Ok, I figured that would be the response.

> diff --git a/lisp/ob-ditaa.el b/lisp/ob-ditaa.el
> index fa864c7bc..4a2b09cd9 100644
> --- a/lisp/ob-ditaa.el
> +++ b/lisp/ob-ditaa.el
> @@ -100,11 +100,13 @@ (defun org-babel-execute:ditaa (body params)
>  "epstopdf"
>  " " eps-file
>  " -o=" (org-babel-process-file-name out-file
> +(jar (org-string-nw-p (if eps org-ditaa-eps-jar-path
> org-ditaa-jar-path)))
>  (cmd (concat org-babel-ditaa-java-cmd
> - " " java " " org-ditaa-jar-option " "
> - (shell-quote-argument
> -  (expand-file-name
> -   (if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
> + " " java
> + (and jar
> +  (concat
> +" " org-ditaa-jar-option " "
> +(shell-quote-argument (expand-file-name jar
>   " " cmdline
>   " " (org-babel-process-file-name in-file)
>   " " (if pdf-cmd
>
> should allow to set :java to
>
> flatpak-spawn --host toolbox run /usr/bin/ditaa
>
> without abusing of org-ditaa-jar-path. Untested.

Doesn't this abuse the `java' header argument, which is intended to pass
arguments to the java runtime?

I think that it would be best to implement the change to mirror that
done in ob-plantuml, as Ihor suggested earlier. But, ob-plantuml uses a
customization switch: `org-plantuml-exec-mode'. Its documentation reads:

  Method to use for PlantUML diagram generation.
  `jar' means to use java together with the JAR.
  The JAR can be configured via `org-plantuml-jar-path'.
  
  `plantuml' means to use the PlantUML executable.
  The executable can be configured via `org-plantuml-executable-path'.
  You can also configure extra arguments via
  `org-plantuml-executable-args'.[fn:1] 

My reading of the documentation and ob-plantuml.el is that it is not
possible to use the `java' header argument in the way you propose for
ob-ditaa.el.

Leo

[fn:1] (Aside: `org-plantuml-executable-args' should be `org-plantuml-args';
Ihor missed it when he made the change in commit b5f0efc049).


Re: [TASK] Allow customizeable ditaa executable in ob-ditaa.el

2023-11-08 Thread Leo Butler
On Sat, Oct 21 2023, Ihor Radchenko  wrote:

> "Dr. Arne Babenhauserheide"  writes:
>
>>>> In my current source I see [...]
>>>>
>>>> (use C-h v org-babel-ditaa-java-cmd to see the value of the java
>>>> executable — you can then customize this to use a different command)
>>>
>>> As far as I understand that part of code it still kind-of assumes that
>>> I'm using a command line of type "java -jar ditaa.jar ...", just with
>>> more flexibility in choosing which "java" command I'm using, right?
>>
>> Yes, it does. ob-plantuml already migrated to allow a regular command,
>> but ob-ditaa still only enables using the jar directly.
>>
>> That is something which would be nice to fix — and ob-plantuml should
>> show the path forward.
>
> +1
> This is a relatively simple task.
> One can indeed use ob-plantuml as a reference to extend ob-ditaa.
> Patches welcome!

While I was reviewing the documentation, ob-doc-ditaa.org, and the
source, ob-ditaa.el, I realized that there is a simple way to run a
script file instead of a jar file. The documentation patch includes such
an example.

Leo

From 6424527dde6e487ce55dddae1260df3d84c2775e Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 26 Oct 2023 20:49:41 -0500
Subject: [PATCH] * org-contrib/babel/languages/ob-doc-ditaa.org: update
 documentation

* org-contrib/babel/languages/ob-doc-ditaa.org: Add a subsection that
documents the four DEFCUSTOM variables.  Modify the existing examples
so that the org code that is exported also creates the code-blocks
that are executed.  Add a subsection that documents how to use those
customization variables in order to run ditaa from a script, not
necessarily as a jar file.

* org-contrib/babel/languages/images/hello-world-from-script.png:
This is a new file created by the new example.

Ref: https://list.orgmode.org/ZTEML8zWrB6kQflk@toolbox/T/
---
 .../images/hello-world-from-script.png| Bin 0 -> 3314 bytes
 org-contrib/babel/languages/ob-doc-ditaa.org  |  86 --
 2 files changed, 77 insertions(+), 9 deletions(-)
 create mode 100644 org-contrib/babel/languages/images/hello-world-from-script.png

diff --git a/org-contrib/babel/languages/images/hello-world-from-script.png b/org-contrib/babel/languages/images/hello-world-from-script.png
new file mode 100644
index ..8a039e1bad997ebd31d8906cc1d1f234e9159e09
GIT binary patch
literal 3314
zcmchacQjn<8pcV8kQk!(8ex#lXzy7#|(_gZ`J_5HEm_xslOd!FyviDo7S%uIYtG
zMuxg@;Qbl6Q!btZo|w00qBJy@-x=vbET14Y3*C)5iNbLVb~e)IxEefsds>|opv_k9
zPE8Q{37)&3Qy<^oFLUp*Bu9@QK)ld=%yQFiy31UTQ#eu$Q!31msn~>zST1r@!fNBf
zS-z@s3&>ZV?cgZ}RmAdjI9I7l>BXY|Xo3G0go9r+tK_@P#ltZ(sF+|g+?ss{Qi9f1
zlaj~;L5<3y;cRQg|BqoQJ+2+OtZ!*)iT9r8a16+BUg6^*rj@}6(K
zDI)_*Hcnw`OtBMR9!L{>N~P3Hd(>1^R8&?@JRVnRsviO4`W?6T_f3tBrySXoB2uV_
zht7{4X+>mZWi>W7mZM(Ndzyfq939JzbFuVSzlw^9iK(fnNlLydF8(r-ue`dt8luV<
z$yK9@O98I*bmBR-T~=;xZa%({{U7ri8=g-R4N%U`xCIthxA8m+LU(sJ1B;LwZ6Ycn
z?Lk}69U~)%sIoF1m=a?&?pGP|>8lctE-k(GvAtBe%mmNWybG`8_ySuwE7;G<0
zMJIWt0N#YW*qp+E-dsFcPVX+Ii>Pzq_;Zla5GTx-4hw4}C4wJf84Ti;^yM
zJLL5EkW3C3mQ7Ah21=Cvj<%jqMukh^av>BJVT}R|29uMMlbvm4V^gu;%iCPil-2nM
zRR=tBxlveHxF{ndBQGy6H`l$vhWzhe3#!q98)hQWb%>4$>Qc&_nXS>{%1H^@B@Tdr
z74A{QWDea~`p=N`PQl;0Pkt>;*QmUIdNygc<>26OU|v>M_T7|+FWOM`$m$@clLSJTxsWZEbCBe}6y8m;8M^skKT^zF~Yy3z`JPX``$xcb74vi7PdiPF+uSqUvT2k@;8AbFL*uk5Xh`jEo=
zq?ntF%f;1o*>_{MA#J%>-p9x1SUuqT*zBy0xp+ujb@j${6*u4hpG0{Dg?a!oCY>_Tk~-
z=z`bQ^QMeG2t4advX1N
zHtsvern%Bnis!9?ljGyDOt)o`wDaJ80%N9(Wj(0`eE~gTy=(5MrA3n?V
zWpE?jk>_w`2gkdkdL8=r??%shb3TAESL=;xhX3b`oK(`Ej!gb3alBUW&u~*D}9OVN9-T8Wj}1qw@HGwKEEri
z2*0~DZ(SoKZg@B(-<4p>9Er!{@0`Tw;h6_|;tBzsU{kxg!U4}D*4zQ#ek-!u~_onY^XlU?cyN={JH`oL)|L!@<%E}r+T?1H16IA!~AS$^GcT2S3
z8=M9-LXW1b7X{ZfikMhf25zkYWc`@H!R+h=q|*gdqeMu~((B*s9nTE9!cLkNQX{XF
z9RsS%P}Mt`(?8xn@mlxnMb)Xh;YPEKat8+3bsq4XcKY|%EzIgMlWC?lSMKg_0PVTo_1
z*I9^R$#Evo2$$#A?o5DEBOP!}XF_$E{6RnK^*b=#ORna32`ej)EVUh{(uFlUYtb~~
zV#R)BO^I?ZTFs=C~iAz?)u{mD9pMgu{;`FD{1e7uINi6^**ZOx1t8P@d5U)GC1T
zva?4M0A^60t5Rmv*BZ0La7wa^esu#mu~*h0XRwe){(h>Fm%KR
zn^-7em>o3zC$X-1-ZZX<13t%xcNln$W@KcnAd|_LnVC1IUb9<|5xcEo?3=Mbh5^
z)MNWz)R@{=D=ZsO@6qFL?^#gwG(Hg5*QhTWF!$Cg|M~OiBLH4fy=jrg@`u#6u#+Re
z*nQMUqg6;or+%zowuD9uNad{0w*@bDg`Y*yUkZRKc+n=jyXK>I^@zG3>lS_X=!WQU!T6jg2XT__xAQa
zF6B8FZRoBbA`#~hTH{`fz5x#wxXFoz>q|-CuKN8`>F6v&2He$&|2`CbjRwxs>7bHC
zR7G`l01}yL4waXe-yXW&=gGmr0d&?O#Kh1U=H}*tlhKipk)%aYaQ%DR6y#
z{SN~JkAYk>+vq%$A*z!RYM7gs#{`z+O8#f|0mw-_i-^S}dF;s}_4M=vHJ+&`Dk{p!
z$;rr6)z_PC#Va*MjDRH;1OW18!qhV{F}ED|{5cfXCkdiBcH)fI?Wf1dcp
zan-Bh=p;=Fer|7nY;vFM%{xOB@nrAp>{Q*YyMC{+Z*tPVKZz5GL;@@ro0tH;8iYVB
ze8T(e`2i8?^DrC;Jis>S>FPclv`iS^rcgkPjE9HcikzIBHZ@rYqoeVRA*u!Aa5!n+
z!qO6*pZ^rFCp4Pl^XfKmSOF#i{weCHn{jW2`<{MnCUQ

Re: org-ditaa woes

2023-10-26 Thread Leo Butler
On Tue, Oct 24 2023, Max Nikulin  wrote:

> On 23/10/2023 18:18, Florin Boariu wrote:
>>
>>> sh-5.1$ flatpak-spawn --host toolbox run /usr/bin/ditaa
>>> /tmp/foo.txt -o /tmp/foo.png
>
> thanks
>
>> I really _need_ to generically execute a command.
>
> I hope, a couple of workarounds are still possible.
>
> 1. Get java command by adding bash -x (or /usr/bin/bash, or
> "/usr/bin/env bash")
>
> flatpak-spawn --host toolbox run bash -x /usr/bin/ditaa \
> /tmp/foo.txt -o /tmp/foo.png
>
> - set `org-babel-ditaa-java-cmd' to something like
> "flatpak-spawn --host toolbox run /usr/bin/java",
> - set `org-ditaa-jar-path' to path to ditaa.jar reported by the
>   command above,
> - add other options to either `org-babel-header-args:ditaa' :java
>   property or to `org-babel-ditaa-java-cmd'
> - perhaps add /usr/bin/env JAVA_HOME=... and other required
>   environment variables before java binary.
>
>
> 2.
> - set `org-babel-ditaa-java-cmd' to
>   "flatpak-spawn --host toolbox run /usr/bin/ditaa".
> - set `org-ditaa-jar-option' to empty string.
> - Call of `shell-quote-argument' makes it impossible to set
>   `org-ditaa-jar-path' to empty string, so set the following variables
>   to some harmless value, e.g. "-Dfile.encoding=UTF-8" (anything added
>   through :java babel header argument):
>   + `org-ditaa-jar-path'
>   + `org-ditaa-eps-jar-path'
>
>
> I agree that it should be possible to call ditaa executable
> directly. Perhaps it is not possible because for a long time ditaa.jar
> was a part of Org mode repository (there were a lot of messages
> against dropping of jar files from the repository). It seems, nobody
> is ready to take responsibility and to become maintainer of
> ob-ditaa.el while active users have no ability to install ditaa as a
> package, so they anyway have to download .jar from upstream.
>
> I find it tedious to add "flatpak-spawn ..." to every tool used by
> Emacs. Who is the publisher of the flatpak? I would expect a directory
> with symlinks named ditaa, java, git, gcc, cpp, etc to a script line
>
> #!/bin/sh
> exec flatpak-spawn --host toolbox run /usr/bin/env "$0" "$@"
>
> (or "$(basename "$0")")
>
> mounted to flatpak runtime and added to $PATH. Perhaps another
> approach exist and it should be discussed with the packager and Emacs
> developers.

Florin,

Max is right, there are work-arounds possible, although a bit different
from what he suggests. The attached org file shows how to do what you
want using the existing ob-ditaa.el code. I have also attached the
exported html document with the image created.

Tell us if it works for the version of Org that you are using.

Leo

#+author: Leo Butler
#+title: Executing ditaa from a script

* Executing =ditaa= from a script

Org assumes that =ditaa= is run as a java jar file.  Users may need to
use a script to run =ditaa=.  This example shows how.

First, set ~org-babel-ditaa-java-cmd~ and ~org-ditaa-jar-option~ to
empty strings and ~org-ditaa-jar-path~ to the script's path; here, it
is =/usr/bin/ditaa=.  This example uses ~setq-local~ to change only
the values in this buffer.

#+name: hello-world-from-script.el.org
#+begin_src org :exports code :results replace
,#+name: hello-world-from-script.el
,#+begin_src emacs-lisp :exports none :results none
(setq-local org-babel-ditaa-java-cmd ""
	org-ditaa-jar-option ""
	org-ditaa-jar-path "/usr/bin/ditaa")
,#+end_src
#+end_src

#+RESULTS: hello-world-from-script.el.org
#+name: hello-world-from-script.el
#+begin_src emacs-lisp :exports none :results none
(setq-local org-babel-ditaa-java-cmd ""
	org-ditaa-jar-option ""
	org-ditaa-jar-path "/usr/bin/ditaa")
#+end_src

Second, in the =ditaa= code-block, set the header argument =:java= to
the empty string =""=.  The =:cmdline= header argument can be used to
pass command-line options to =ditaa= via the script.

#+name: hello-world-from-script.org
#+begin_src org :exports code :results replace
,#+name: hello-world-from-script
,#+begin_src ditaa :file images/hello-world-from-script.png :java "" :cmdline -r -e UTF-8
++
||
| Hello World|
| from a script! |
||
++
,#+end_src
#+end_src

#+RESULTS: hello-world-from-script.org
#+name: hello-world-from-script
#+begin_src ditaa :file images/hello-world-from-script.png :java "" :cmdline -r -e UTF-8
++
||
| Hello World|
| from a script! |
||
++
#+end_src

#+RESULTS: hello-world-from-script
[[file:images/hello-world-from-script.png]]
Title: Executing ditaa from a script






Executi

Re: org-ditaa woes

2023-10-25 Thread Leo Butler
On Tue, Oct 24 2023, Ihor Radchenko  wrote:

> Florin Boariu  writes:
>
>> I can offer to try my luck with writing a patch for ob-ditaa.el, but
>> I'm not knowledgeable enough (or have enough time on my hands) to
>> actually keep maintaining it :-p
>
> Writing a patch is also welcome.

I am looking at ob-ditaa. Patching it looks within my reach.

Is there no testsuite for it?

Leo


Re: bash source code block: problem after ssh commands

2023-10-25 Thread Leo Butler
On Wed, Oct 25 2023, alain.coch...@unistra.fr wrote:

> Thanks much for the detailed explanations.
>
>  > It looks like an issue in comint-mode and the way that it is
>  > handling the temporary ssh session. This is not an issue with
>  > org-mode.
>
> So it is an issue with emacs, right?

Yes, that is my understanding. Perhaps you can report it to the
emacs-devel mailing list.

Leo


Re: bash source code block: problem after ssh commands

2023-10-25 Thread Leo Butler
On Wed, Oct 25 2023, alain.coch...@unistra.fr wrote:

> Hello.
>
> For me, 'C-c C-c' on the following group
>
>#+begin_src bash :results output
>echo "foo"
>echo "bar"
>#+end_src
>
>
> works as I expect: 'foo' and 'bar' are echo'ed.  But it fails on this
> one:
>
>#+begin_src bash :results output
>ssh coch...@fruc.u-strasbg.fr "echo foo>foo_file"
>echo "bar"
>#+end_src
>
>
> The file 'foo_file' is created on the remote machine, but 'bar' is not
> echo'ed.  I have tried to insert other commands between the ssh and
> echo commands, or append semicolons at the end of the commands,
> without success.
>
> By contrast, it works with this one:
>
>#+begin_src bash :results output
>ssh coch...@fruc.u-strasbg.fr "echo foo>foo_file" ; echo "bar"
>#+end_src
>
> Perhaps it is worth noting that I observe the same behavior if I
> simply copy/yank the commands (I mean: the two commands yank'ed at
> once) in an emacs terminal (obtained with 'M-x shell').  However,
> everything works as I expect if I copy/yank the commands (all at once)
> in a "regular" X terminal (xfce in my case).

It looks like an issue in comint-mode and the way that it is handling
the temporary ssh session. This is not an issue with org-mode.

Here are a couple work-arounds:

- add the -f to the ssh command
- add a semi-colon and line continuation to the first line.

Working examples:

#+begin_src bash :results output
  ssh -f SSH-HOST 'echo foo>/tmp/foo_file'
  echo $(uname -a) |tee /tmp/uname.txt
#+end_src

#+RESULTS:
: Linux t14 6.5.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.3-1 (2023-09-13) 
x86_64 GNU/Linux

#+begin_src bash :results output
  ssh pearce-120 'echo foo>/tmp/foo_file' &&\
  echo $(uname -a) | tee /tmp/uname.txt
#+end_src

#+RESULTS:
: Linux t14 6.5.0-1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.5.3-1 (2023-09-13) 
x86_64 GNU/Linux

Not working:

#+begin_src bash :results output
  ssh SSH-HOST 'echo foo>/tmp/foo_file'
  echo $(uname -a) |tee /tmp/uname1.txt
#+end_src

If you look at /tmp after running the third example, you see that that
second command line has not been executed.

Leo


Re: org-ditaa woes

2023-10-20 Thread Leo Butler
On Fri, Oct 20 2023, "Dr. Arne Babenhauserheide"  wrote:

> Leo Butler  writes:
>
>>>> [...]
>>>>(cmd (concat "java " java " " org-ditaa-jar-option " "
>>>>  (shell-quote-argument
>>>>   (expand-file-name
>>>>(if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
>>>>  " " cmdline
>>>>  " " (org-babel-process-file-name in-file)
>>>>  " " (org-babel-process-file-name out-file)))
>>>> [...]
>
> From the commit, this is an ancient version of ob-ditaa (11 years ago).
>
> In my current source I see
>
>(cmd (concat org-babel-ditaa-java-cmd
> " " java " " org-ditaa-jar-option " "
> (shell-quote-argument
>  (expand-file-name
>   (if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
> " " cmdline
> " " (org-babel-process-file-name in-file)
> " " (if pdf-cmd
> eps-file
>   (org-babel-process-file-name out-file)
>
> (use C-h v org-babel-ditaa-java-cmd to see the value of the java
> executable — you can then customize this to use a different command)
>
> Going forward we may want to adjust ob-ditaa to allow for an executable
> like ob-plantuml does it.
>
> Best wishes,
> Arne

Arne,
Thank you for the correction, you are right about the vintage (and
about the suggestion vis-a-vis ob-plantuml, imo).

Leo

Re: org-ditaa woes

2023-10-20 Thread Leo Butler
Hello Florin,

On Thu, Oct 19 2023, Florin Boariu  wrote:

> Hello everyone,
>
> I am not on the mailing list, so I'm hoping that some kind soul with
> moderator powers will have mercy and let my email through in a timely
> manner :-) Also, please CC me in on the answer. (I'll happily
> subscribe if you feel that I should, but this is likely to be my only
> encounter with the Org-mode list, so it's probably bogus...)

You can read (and post to?) this email list on gmane.

> But in the source code of org-ditaa.el
> (https://github.com/tkf/org-mode/blob/master/lisp/ob-ditaa.el) I can
> see something like this on lines 87 ff:
>
>> [...]
>>(cmd (concat "java " java " " org-ditaa-jar-option " "
>>(shell-quote-argument
>> (expand-file-name
>>  (if eps org-ditaa-eps-jar-path org-ditaa-jar-path)))
>>" " cmdline
>>" " (org-babel-process-file-name in-file)
>>" " (org-babel-process-file-name out-file)))
>> [...]
>

I think you have identified a bug in ob-ditaa.el. Your request is
perfectly reasonable and that CMD should not have such hard-coded
constants in it, imo.

> I suck at LISP, but I'm guessing this means that there simply
> is no way of just passing on a "/usr/bin/ditaa" command-line to
> "org-ditaa", or at least an alternative Java command like "flatpak
> spawn --host /usr/bin/java ...". Org-ditaa really *does* insist of
> glueing it together from "java -jar ..." pieces, and is stubbornly
> adamant on finding Java in the same FS namespace.

Can you give us the command-line you would like to use?
That would help to fix the problem you are confronting.

>
> Is there a deeper reason behind this? This pretty much breaks
> Flatpak, or any other sandboxing compatibility, as far as I
> understand. Can it be changed? Please? :-)

The deeper reason is likely that ob-ditaa worked for whomever wrote it,
and users have either accepted its limitations (if noted), worked around
them, or gave up.

>
> How can I make it accept a command line?
>
> Is there any "generic" way of making org-babel accept a command line,
> not necessarily going through "org-ditaa", as a workaround?

You could use ob-shell, but it would be preferable to fix the bug you
have identified.

>
> Thanks & cheers,
> Florin.

Leo


Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-10-04 Thread Leo Butler
On Wed, Oct 04 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Attached is:
>>
>> - my previous patch, rebased against the latest HEAD and only modified
>>   to include a patch to etc/ORG-NEWS
>> - a patch to the worg docs that corrects the urls
>> - a patch to the worg docs that documents the new header arguments and
>>   provides examples of usage (two new graphics files are included as
>>   part of that patch).
>
> Thanks!
> Applied, onto main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=2ba45fcb7
>
> Updated Worg as well:
> https://git.sr.ht/~bzg/worg/commit/16ef094a
> https://git.sr.ht/~bzg/worg/commit/525a1355

Thanks, Ihor, for your time and feedback.

Leo


Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-10-02 Thread Leo Butler
On Fri, Sep 22 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> What is the purpose of this `unwind-protect'?
>>> In its current form, it does nothing because no UNWINDFORMS are
>>> provided.
>>
>> I copied the forms from tests I had written for ob-octave, without
>> thinking about why those tests were wrapped in an `unwind-protect'
>> form. The attached patch removes them, otherwise it is identical to the
>> previous patch.
>
> Thanks! Now, may you also add etc/ORG-NEWS entry and update the WORG docs?

Attached is:

- my previous patch, rebased against the latest HEAD and only modified
  to include a patch to etc/ORG-NEWS
- a patch to the worg docs that corrects the urls
- a patch to the worg docs that documents the new header arguments and
  provides examples of usage (two new graphics files are included as
  part of that patch).

Best regards,
Leo

From 7288eb547aff1ad50c3782d9db22b1e2792d6634 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 19 Sep 2023 13:36:06 -0500
Subject: [PATCH] * lisp/ob-maxima.el: enable use of `batch' loader and `draw'

* (org-babel-header-args:maxima): Document the two new header
arguments (batch and graphics-pkg) that are specific to ob-maxima.
* (org-babel-maxima--command-arguments-default): A new variable
storing the default command-line argument(s).  This value was
hard-coded in `org-babel-maxima:execute'.
* (org-babel-maxima--graphic-package-options): A new variable that
stores an alist of Maxima graphics packages and the Maxima code to set
up that package.
* (org-babel-maxima--default-epilogue): A new variable that stores an
alist of the clean-up code that is run at end of a `graphical-output'
or `non-graphical-output' source block.
* (org-babel-maxima--output-filter-regexps): A new variable that
stores a list of regexps to identify "bad" output lines to be removed
from Maxima's output.  Source-code comments document each regexp's
purpose.  Two additional regexps have been added: one filters
un-wanted output from `batch' and the other removes empty input lines
that `batch'-ed output may spuriously produce (actual empty input
lines are syntax errors, see the new tests below).
* (org-babel-maxima--output-filter): A new function that takes a
single line of Maxima output.  It returns nil if the line has zero
length or matches a regexp in
`org-babel-maxima--output-filter-regexps'; otherwise, it returns the
line.  This function and regexp replace the hard-coded filter in
`org-babel-execute:maxima'.
* (org-babel-maxima-expand): Prepare the source block for execution,
depending on whether it is producing graphical output or not.  In case
of graphical output, use the `graphics-pkg' header to set the graphics
package and use `org-babel-maxima--graphic-package-options' to set-up
the package.  Grovel the graphics terminal from the output filename.
* (org-babel-execute:maxima): Use the :batch header argument and
`org-babel-maxima--command-arguments-default' to execute the source
block.  Replace the existing, in-line output filter and its regexps
with `org-babel-maxima--output-filter' and
`org-babel-maxima--output-filter-regexps'.

* testing/examples/ob-maxima-test.org: Add test examples.

Include examples of the batch-related tests from
testing/lisp/test-ob-maxima.el.  Provide an example of the
`:graphics-pkg' header argument with the `draw' package.

* testing/lisp/test-ob-maxima.el: Introduce six new, batch-related
test functions.  Each test exercises the :batch header argument.  The
response to unusual inputs is tested (empty strings, strings with just
whitespace, input with the `:lisp' reader, and two syntax-related
errors).

link: https://list.orgmode.org/87cyz1ivzw@t14.reltub.ca/
---
 etc/ORG-NEWS|  12 +++
 lisp/ob-maxima.el   | 115 +---
 testing/examples/ob-maxima-test.org |  54 +
 testing/lisp/test-ob-maxima.el  | 101 
 4 files changed, 254 insertions(+), 28 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 252c5a9f9..16f8a1c30 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -596,6 +596,18 @@ return a matplotlib Figure object to plot. For output results, the
 current figure (as returned by =pyplot.gcf()=) is cleared before
 evaluation, and then plotted afterwards.
 
+*** =ob-maxima.el=: Support for ~batch~ and ~draw~
+
+=ob-maxima= has two new header arguments: ~:batch~ and
+~:graphics-pkg~.
+
+The ~:batch~ header argument can be set to one of Maxima's file
+loaders (~batch~, ~load~ or ~batchload~); the default remains
+~batchload~. The ~:graphics-pkg~ header argument can be set to one of
+Maxima's graphics packages (~draw~ or ~plot~); the default remains
+~plot~.  The graphics terminal is now determined from the file-ending
+of the file-name set in the ~:file~ header argument.
+
 ** New functions and changes in function arguments
 *** =TYPES= argument in ~org-

[PATCH] update urls in ob-doc-maxima.org

2023-09-26 Thread Leo Butler
Hello,

The current project urls in ob-doc-maxima.org are out-of-date (the .net
urls redirect to the new .io ones). The project image file has moved and
no longer loads. This patch corrects those problems.

Best,
Leo

From dceb35854fcda3e467c3b1bd8f7f343434f7fb2f Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 26 Sep 2023 11:04:45 -0500
Subject: [PATCH] * org-contrib/babel/languages/ob-doc-maxima.org: correct urls

The old .net urls have been replaced by .io urls.  These pages are
served over https.

The location of the project banner has moved, so that is updated, too.
---
 org-contrib/babel/languages/ob-doc-maxima.org | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/org-contrib/babel/languages/ob-doc-maxima.org b/org-contrib/babel/languages/ob-doc-maxima.org
index a6b403dc..50438b3a 100644
--- a/org-contrib/babel/languages/ob-doc-maxima.org
+++ b/org-contrib/babel/languages/ob-doc-maxima.org
@@ -14,11 +14,12 @@
 #+begin_export html
   
   
-  Org Mode support for http://maxima.sourceforge.net/;>Maxima
+  Org Mode support for https://maxima.sourceforge.io/;>Maxima
   
   
-  http://maxima.sourceforge.net/;>
-  http://maxima.sourceforge.net/i/logo.png"/>
+  https://maxima.sourceforge.io/;>
+  https://maxima.sourceforge.io/img/maxima.svg"/>
+  https://maxima.sourceforge.io/img/maxima-banner.png"/>
   
   
   
@@ -73,7 +74,6 @@ You must activate Maxima by adding a line to
  '((maxima . t))) ; this line activates maxima
 #+END_SRC
 
-
 * Org Mode Features for Maxima Source Code Blocks
 ** Header Arguments
 There are no Maxima-specific default header argument values.
-- 
2.40.1



Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-09-21 Thread Leo Butler
On Thu, Sep 21 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>> +(defconst org-babel-header-args:maxima
>>>> +  '((batch   . :any)
>>>
>>> Why :any? Only two values are allowed here.
>>>
>>>> +(graphics-pkg. :any))
>>>
>>> Same. The value is a closed list.
>>
>> I have made the change requested.
>>
>> However, beyond the documentation value, I don't see this variable's
>> values being used.
>
> In completion. See `pcomplete/org-mode/block-option/src'.
> Also, in org-lint. See `org-lint-wrong-header-argument'.

Thanks.

>
>> Fixed. I don't use `apropos', so I didn't see the problem (and I had
>> failed to absorb everything in §D.6).
>
> M-x checkdoc checks for many of the §D.6 conventions.

Yes, I discovered that from the documentation. I must have done
something wrong, because it didn't work for me when I tried it, but
after re-starting emacs it is working.

>
>> Please see the attached, revised patch. It fixes the problems that you
>> have identified–except for the way that the gnuplot terminal is
>> determined. I would like to leave that for a subsequent patch, mainly
>> because this one has become quite large.
>
> Ok. Thanks!
>
> I have one more comment on the tests:
>
>> +(ert-deftest ob-maxima/batch+verbatim+eof-error ()
>> +  "Exercise the `:batch' header argument.  Send invalid input to
>> +Maxima."
>> +  (unwind-protect
>
> What is the purpose of this `unwind-protect'?
> In its current form, it does nothing because no UNWINDFORMS are
> provided.

I copied the forms from tests I had written for ob-octave, without
thinking about why those tests were wrapped in an `unwind-protect'
form. The attached patch removes them, otherwise it is identical to the
previous patch.

Leo

From 425ea8ed47af5bccfd9bc37f1e4de4c53cc9b1f1 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 19 Sep 2023 13:36:06 -0500
Subject: [PATCH] * lisp/ob-maxima.el: enable use of `batch' loader and `draw'

* (org-babel-header-args:maxima): Document the two new header
arguments (batch and graphics-pkg) that are specific to ob-maxima.
* (org-babel-maxima--command-arguments-default): A new variable
storing the default command-line argument(s).  This value was
hard-coded in `org-babel-maxima:execute'.
* (org-babel-maxima--graphic-package-options): A new variable that
stores an alist of Maxima graphics packages and the Maxima code to set
up that package.
* (org-babel-maxima--default-epilogue): A new variable that stores an
alist of the clean-up code that is run at end of a `graphical-output'
or `non-graphical-output' source block.
* (org-babel-maxima--output-filter-regexps): A new variable that
stores a list of regexps to identify "bad" output lines to be removed
from Maxima's output.  Source-code comments document each regexp's
purpose.  Two additional regexps have been added: one filters
un-wanted output from `batch' and the other removes empty input lines
that `batch'-ed output may spuriously produce (actual empty input
lines are syntax errors, see the new tests below).
* (org-babel-maxima--output-filter): A new function that takes a
single line of Maxima output.  It returns nil if the line has zero
length or matches a regexp in
`org-babel-maxima--output-filter-regexps'; otherwise, it returns the
line.  This function and regexp replace the hard-coded filter in
`org-babel-execute:maxima'.
* (org-babel-maxima-expand): Prepare the source block for execution,
depending on whether it is producing graphical output or not.  In case
of graphical output, use the `graphics-pkg' header to set the graphics
package and use `org-babel-maxima--graphic-package-options' to set-up
the package.  Grovel the graphics terminal from the output filename.
* (org-babel-execute:maxima): Use the :batch header argument and
`org-babel-maxima--command-arguments-default' to execute the source
block.  Replace the existing, in-line output filter and its regexps
with `org-babel-maxima--output-filter' and
`org-babel-maxima--output-filter-regexps'.

* testing/examples/ob-maxima-test.org: Add test examples.

Include examples of the batch-related tests from
testing/lisp/test-ob-maxima.el.  Provide an example of the
`:graphics-pkg' header argument with the `draw' package.

* testing/lisp/test-ob-maxima.el: Introduce six new, batch-related
test functions.  Each test exercises the :batch header argument.  The
response to unusual inputs is tested (empty strings, strings with just
whitespace, input with the `:lisp' reader, and two syntax-related
errors).
---
 lisp/ob-maxima.el   | 115 +---
 testing/examples/ob-maxima-test.org |  54 +
 testing/lisp/test-ob-maxima.el  | 101 
 3 files changed, 242 insertion

Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-09-20 Thread Leo Butler
On Wed, Sep 20 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>>> May you clarify the purpose of "linenum"?
>>> Do I understand correctly that the above will simply affect debug output
>>> when maxima references where a problematic line is located in the source?
>>
>> No, it affects how output labels are printed. With this value, the
>> "first" line in the source block receives the line number 1; without it,
>> it would get 2.
>
> Ok. This should be documented in the commit message and possibly in the
> code itself.

I think it makes most sense to put in a source-code comment, explaining
the why. That is what I have done.

>
>>>
>>>>>>(unless (or (string-match "batch" line)
>>>>>>(string-match "^rat: replaced 
>>>>>> .*$" line)
>>>>>>(string-match "^;;; Loading 
>>>>>> #P" line)
>>>>>> +  (string-match "^read and 
>>>>>> interpret" line)
>>>>>> +  (string-match 
>>>>>> "^(%\\([io]-?[0-9]+\\))[ ]+$" line)
>>>>>
>>>>> May you explain why you added these two conditions?
>>>>
>>
>> 
>>
>>>
>>> May empty lines be intentional in some maxima code?
>>
>> A blank line is simply skipped by the maxima reader; an empty input line
>> is a syntax error.
>>
>> However, "empty" output may appear, so I have modified that filter.
>
>+  (string-match 
> "^(%\\([io]-?[0-9]+\\))[ ]+$" line)
>
> It would be nice to add a comment line explaining what this regexp
> matches against.

Ok. I think it makes the most sense to explain the purpose of each
regexp, new and old, and to make this somewhat extensible.

What I have done is cut out that undocumented filter, put the regexps
into a new variable (`org-babel-maxima--output-filter-regexps'), added
source-code comments to explain what each one does and added a new
function (`org-babel-maxima--output-filter') that replaces the old
filter in `org-babel-execute:maxima'.


>
>> * (org-babel-maxima--graphic-package-options): an alist of Maxima
>> graphics packages and the Maxima code to set up that package.
>
> This is a bit confusing. I'd say "A new variable storing alist of Maxima ..."
>
>> * (org-babel-maxima--default-epilogue): an alist of the clean-up code
>> that is run at end of a `graphical-output' or `non-graphical-output'
>> source block.
>
> Same here.
> Basically, it should be clear from the commit message when you add new
> variables and when you modify existing.

Points taken.

>
>> * (org-babel-maxima-expand): prepare the source block for
>> execution.
>
> This is vague. Please explain what is changed in more details.

Done.

>
>> * (org-babel-execute:maxima): use the :batch header argument and
>> `org-babel-maxima--command-arguments-default' to execute the source
>> block.  Add a couple extra regexps to filter the output of a batch-ed
>> source block.
>
> This reads better compared to the above.
>
>> +(defconst org-babel-header-args:maxima
>> +  '((batch   . :any)
>
> Why :any? Only two values are allowed here.
>
>> +(graphics-pkg. :any))
>
> Same. The value is a closed list.

I have made the change requested.

However, beyond the documentation value, I don't see this variable's
values being used.

>
>> +(defvar org-babel-maxima--command-arguments-default
>> +  "--very-quiet"
>> +  "Command-line arguments sent to Maxima by default.  If the
>
> Please keep the first line as a single sentence.
> See 
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html
>
>> +(defvar org-babel-maxima--default-epilogue
>> +  '((graphical-output . "gnuplot_close ()$")
>> +(non-graphical-output . ""))
>> +  "The final Maxima code executed in a source block.  An alist with
>
> Same problem with the first line.

Fixed. I don't use `apropos', so I didn't see the problem (and I had
failed to absorb everything in §D.6).

Please see the attached, revised patch. It fixes the problems that you
have identified–except for the way that the gnuplot terminal is
determined. I would like to leave that for a subsequent patch, mainly
because this one has become quite large.

Best rega

Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-09-19 Thread Leo Butler
On Sat, Sep 16 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> Also, non-standard arguments should be defined in 
>>> `org-babel-header-args:maxima'.
>>>
>>
>> Ok. I see that some packages (e.g. ob-gnuplot.el) use a `defvar' form,
>> while others (e.g. ob-R.el) use a `defconst' form. Is there a preference?
>
> defconst I think. The value is not supposed to be changed.

Done.

>
>>>> I have also moved two defaults, that were embedded in the code, to
>>>> `defvar' forms.
>>>
>>> This is fine, although I would prefer to keep these variables private for
>>> now.

Done.

>>>> -  (format "batchload(%S)$" in-file))
>>>> +  (format "(linenum:0, %s(%S))$" batch/load 
>>>> in-file))
>>>
>>> May you clarify the purpose of "linenum"?
> Do I understand correctly that the above will simply affect debug output
> when maxima references where a problematic line is located in the source?

No, it affects how output labels are printed. With this value, the
"first" line in the source block receives the line number 1; without it,
it would get 2.

>
>>>>(unless (or (string-match "batch" line)
>>>>(string-match "^rat: replaced 
>>>> .*$" line)
>>>>(string-match "^;;; Loading #P" 
>>>> line)
>>>> +  (string-match "^read and 
>>>> interpret" line)
>>>> +  (string-match 
>>>> "^(%\\([io]-?[0-9]+\\))[ ]+$" line)
>>>
>>> May you explain why you added these two conditions?
>>



>
> May empty lines be intentional in some maxima code?

A blank line is simply skipped by the maxima reader; an empty input line
is a syntax error.

However, "empty" output may appear, so I have modified that filter. I
have included a number of test cases in the testsuite to make sure that
such corner cases are being handled correctly.

Please see the attached patch.

Thank you for your time and patience.

Leo

From d2934b38a28a8593554af69622be5b11bc13406d Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 19 Sep 2023 13:36:06 -0500
Subject: [PATCH] * lisp/ob-maxima.el: enable use of `batch' loader and `draw'

* (org-babel-header-args:maxima): document the two
new header arguments, specific to ob-maxima.
* (org-babel-maxima--command-arguments-default):
move the default command-line argument into this variable, from
`org-babel-maxima:execute'.
* (org-babel-maxima--graphic-package-options): an alist of Maxima
graphics packages and the Maxima code to set up that package.
* (org-babel-maxima--default-epilogue): an alist of the clean-up code
that is run at end of a `graphical-output' or `non-graphical-output'
source block.
* (org-babel-maxima-expand): prepare the source block for
execution.
* (org-babel-execute:maxima): use the :batch header argument and
`org-babel-maxima--command-arguments-default' to execute the source
block.  Add a couple extra regexps to filter the output of a batch-ed
source block.

* testing/examples/ob-maxima-test.org: add a draw test

Provide an example of the `:graphics-pkg' header argument with the
`draw' package.

* testing/lisp/test-ob-maxima.el: add batch-related tests

* testing/lisp/test-ob-maxima.el: introduce six new tests.  Each test
exercises the :batch header argument.  The response to unusual inputs
is tested (empty strings, strings with just whitespace, input with the
`:lisp' reader, and two syntax-related errors).
* testing/examples/ob-maxima-test.org: include examples of the
batch-related tests from testing/lisp/test-ob-maxima.el.
---
 lisp/ob-maxima.el   |  88 +--
 testing/examples/ob-maxima-test.org |  54 ++
 testing/lisp/test-ob-maxima.el  | 107 
 3 files changed, 227 insertions(+), 22 deletions(-)

diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el
index d1d7c7424..3814049ca 100644
--- a/lisp/ob-maxima.el
+++ b/lisp/ob-maxima.el
@@ -37,6 +37,11 @@
 
 (require 'ob)
 
+(defconst org-babel-header-args:maxima
+  '((batch   . :any)
+(graphics-pkg. :any))
+  "Maxima-specific header arguments.")
+
 (defvar org-babel-tangle-lang-exts)
 (add-to-list 'org-babel-tangle-lang-exts '("maxima" . "max"))
 
@@ -48,29 +53,59 @@
   :group 'org-babel
   :type 'string)
 
+(defvar org-babel-maxima--command-arguments-default
+  "--very-quiet"
+  "Command-line arguments sent to Maxima by default.  If the
+`:batch' header arg

Re: [PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-09-15 Thread Leo Butler
On Fri, Sep 15 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Attached is a patch that tries to address some of Ihor's concerns. I
>> have added two header arguments for maxima src blocks:
>
> Thanks!
>
>> - :graphics-pkg lets the user choose the graphics package to use;
>>
>> - :batch lets the user choose which source-code loader Maxima will use.
>
> We need to document the new header arguments in ORG-NEWS and in
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-maxima.html

Thanks for your feedback.

Yes, I will do the documentation once the patch has attained a
nearer-to-finished state.

>
> Also, non-standard arguments should be defined in 
> `org-babel-header-args:maxima'.
>

Ok. I see that some packages (e.g. ob-gnuplot.el) use a `defvar' form,
while others (e.g. ob-R.el) use a `defconst' form. Is there a preference?

>> I have also moved two defaults, that were embedded in the code, to
>> `defvar' forms.
>
> This is fine, although I would prefer to keep these variables private for
> now.

My understanding is that a special variable defined via `defvar' is one
that is intended to be "private", i.e. users should not change it unless
they really know what they are doing. Is that accurate?

Do you mean the names should be something like

org-babel-maxima--command-arguments

?

>
>> +(defvar org-babel-maxima-command-arguments
>> +  "--very-quiet"
>> + "A string containing the command-line arguments used when calling
>> the Maxima executable. See `org-babel-maxima-command',
>> `org-babel-maxima-batch/load' and `org-babel-execute:maxima'.")
>
> Here and in the other docstrings, please use a single short sentence in
> the first line. Also, please use double space between sentences and fill
> the docstring text to standard fill-column. See
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Documentation-Tips.html

Yes.

>
>> +(defvar org-babel-maxima-graphic-package-options
>> +  '((plot . "(set_plot_option ('[gnuplot_term, %s]), set_plot_option 
>> ('[gnuplot_out_file, %S]))$")
>> +(draw . "(load(draw), set_draw_defaults(terminal='%s,file_name=%S))$"))
>> + "An alist, each element of the form (PACKAGE-NAME
>> . FORMAT-STRING). The format string contains the Maxima code to set
>> the graphic file terminal and name. It must contain `%s' to set the
>> terminal and `%S' to set the filename. The default package is
>> `plot'. See `org-babel-maxima-expand'.")
>
> According to the docstring, it appears that the order of %s and %S do
> not matter, which is probably not the case.

Correct.

>
>> +  ;; graphic output
>> +  (if graphic-file
>> +  (let ((graphics-pkg (intern (or (cdr (assq 
>> :graphics-pkg params)) "plot")))
>> +(graphic-format-string (cdr (assq 
>> graphics-pkg org-babel-maxima-graphic-package-options)))
>> +(graphic-terminal (file-name-extension 
>> graphic-file))
>> +(graphic-file (if (eq graphics-pkg 'plot) 
>> graphic-file (file-name-sans-extension graphic-file
>> +(format graphic-format-string graphic-terminal 
>> graphic-file)))
>
> What will happen if :graphics-pkg value is not expected? What about
> unsupported graphics file extensions? 

I need to add a fail-safe when setting `graphic-format-string'

> And is it always the that terminal name is the same as file extension
> (I am thinking about Gnuplot's pngcairo terminal)?

I see your point.

At the moment, the code works for the following terminals:

png, jpg, gif, eps, svg, pdf

To support a range of terminal options including, I would need to add a
:terminal header argument and an alist of graphics packages and their
supported terminals.

>
>> -  (format "batchload(%S)$" in-file))
>> +  (format "(linenum:0, %s(%S))$" batch/load 
>> in-file))
>
> May you clarify the purpose of "linenum"?

Maxima keeps track of input/output line numbers via the variable
`linenum'. I set the linenum to 0 so that the line numbering of the
input in `in-file' starts at 1 not 2.

This idiom has been used in other Maxima front-ends, such as
`imaxima.el', too (although imaxima now uses the lisp reader, instead).

See 
https://sourceforge.net/p/maxima/code/ci/76105d9ee231679eccac888a04c98e6ef66df087/


>
>>(unless (or (string-match "batch" line)
>>(string-match "^rat: replaced 

[PATCH] ob-maxima.el, etc. (was Re: [MAINTENANCE] On how much we can expose internals into defcustom)

2023-09-12 Thread Leo Butler
On Thu, Sep 07 2023, Ihor Radchenko  wrote:

> `org-babel-execute:maxima' relies on certain output that maxima
> produces. Removing --very-quiet will make the assumptions in the code no
> longer valid. Worse - it might happen that in the absence of --very-quiet
> `org-babel-execute:maxima' (or its future code) will work _almost_
> correctly, with problems going unnoticed to the user.
>
> If we want to support use-case when --very-quiet is absent, we need to
> explicitly change `org-babel-execute:maxima' to account for it,
> maintaining this support forever.
>
> Either way, it will be an extra maintenance burden, which must be
> justified.
>
> The baseline is - we cannot put the burden of wrongly changing
> customization onto the user. Because the user may or may not notice
> them problem, especially when it is subtle and requires good knowledge
> of the Elisp code in ob-maxima.
>
> Of course, the above statement is not 100% strict. If you describe cases
> when customization is necessary for certain valid use cases, we may
> still put in such dangerous customization with all the appropriate
> warnings in the docstring. But it should be justified.
>
>>> So, leaving essential settings customizeable is not necessarily a good idea.
>>
>> I understand your hesitation about full-blown customization using
>> `defcustom'. However, I would still like to have more dials to turn.
>>
>> Perhaps we could add header arguments to get the desired customization?
>
> Header arguments are generally better, because they provide more
> fine-grained control compared to global customization.
>
>> E.g.
>>
>> - :batch :: Control how the Maxima source is evaluated by Maxima.
>>   1. Default. If nil or no, then use batchload with the --very-quiet
>>  command-line flag.
>>   2. If t or yes, then use batch with the --quiet command-line flag;
>
> Is there a place where I can see the differences between batch and batchload?
>
>> - :plot-engine :: Set the plotting package.
>>   1. Default. If nil or no, the use `plot';
>>   2. If `draw', then use `draw'.
>
> Sounds reasonable.
>
>> - Similarly, we could do something like ob-R.el does, and construct the
>>   graphics instructions using some additional header arguments and
>>   grovelling the terminal from the filename (see
>>   org-babel-R-construct-graphics-device-call).
>>
>> My sense is that this would be more in keeping with how other ob-*.el
>> packages do things.
>
> Yes.

Attached is a patch that tries to address some of Ihor's concerns. I
have added two header arguments for maxima src blocks:

- :graphics-pkg lets the user choose the graphics package to use;

- :batch lets the user choose which source-code loader Maxima will use.

I have also moved two defaults, that were embedded in the code, to
`defvar' forms.

I have added tests in test-ob-maxima.el and in ob-maxima-test.org to
demonstrate the use of these header arguments.

Leo


diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el
index d1d7c7424..ab166bfd4 100644
--- a/lisp/ob-maxima.el
+++ b/lisp/ob-maxima.el
@@ -48,29 +48,44 @@
   :group 'org-babel
   :type 'string)
 
+(defvar org-babel-maxima-command-arguments
+  "--very-quiet"
+  "A string containing the command-line arguments used when calling the Maxima executable. See `org-babel-maxima-command', `org-babel-maxima-batch/load' and `org-babel-execute:maxima'.")
+
+(defvar org-babel-maxima-graphic-package-options
+  '((plot . "(set_plot_option ('[gnuplot_term, %s]), set_plot_option ('[gnuplot_out_file, %S]))$")
+(draw . "(load(draw), set_draw_defaults(terminal='%s,file_name=%S))$"))
+  "An alist, each element of the form (PACKAGE-NAME . FORMAT-STRING). The format string contains the Maxima code to set the graphic file terminal and name. It must contain `%s' to set the terminal and `%S' to set the filename. The default package is `plot'. See `org-babel-maxima-expand'.")
+
+(defvar org-babel-maxima-default-epilogue
+  "gnuplot_close ()$"
+  "A string with the final Maxima code executed. See `org-babel-maxima-expand'.")
+
 (defun org-babel-maxima-expand (body params)
   "Expand a block of Maxima code according to its header arguments."
-  (let ((vars (org-babel--get-vars params))
-	(epilogue (cdr (assq :epilogue params)))
-	(prologue (cdr (assq :prologue params
+  (let* ((vars (org-babel--get-vars params))
+ (graphic-file (ignore-errors (org-babel-graphical-output-file params)))
+	 (epilogue (cdr (assq :epilogue params)))
+	 (prologue (cdr (assq :prologue params
 (mapconcat 'identity
-	   (list
-		;; Any code from the specified prologue at the start.
-		prologue
-		;; graphic output
-		(let ((graphic-file (ignore-errors (or

Re: [MAINTENANCE] On how much we can expose internals into defcustom

2023-09-06 Thread Leo Butler
On Tue, Sep 05 2023, Ihor Radchenko  wrote:

> CCing Bastien, as he might want to intervene.
>
> Leo Butler  writes:
>
>>> +(defcustom org-babel-maxima-command-arguments
>>> +  "--very-quiet"
>>
>>> +(defcustom org-babel-maxima-batch/load
>>> +  "batchload"
>>> +
>>> +(defcustom org-babel-maxima-graphic-file-format-string
>>> +  "(set_plot_option ('[gnuplot_term, png]), set_plot_option 
> ('[gnuplot_out_file, %S]))$"
>>> +
>>> +(defcustom org-babel-maxima-default-epilogue
>>> +  "gnuplot_close ()$"
>
>>> IMHO, in their current state, if a user mindlessly customizes these
>>> options without knowing how ob-maxima internals work, ob-maxima may
>>> simply be broken.
>>
>> I think there is a fine line between being too rigid but working within
>> a limited scope (as ob-maxima is now), or providing enough customizable
>> options to let users do what they want. I would prefer the latter,
>> if the defaults provide a working configuration.
>>
>> Note that I do attempt to suggest other working options in the defcustom
>> definitions.
>
>>> As a general rule, we do not expose internal details that are _required_
>>> for things to work to users.
>>
>> I understand this principle, but, why not provide enough options for
>> users to configure a package to do what they want? Yes, that may mean
>> they break the package--but only temporarily, because returning to the
>> default options will return the package to a working state.
>
> That's a bit more tricky.
> Imagine, for example, that we commit
>
> +(defcustom org-babel-maxima-command-arguments
> +  "--very-quiet"
>
> and some users will later customize the default value to
>
> "--very-quite --my-personal-switch-I-want"
>
> Then, in future, due to changes in Org or maxima, we might need to
> change "--very-quite" to something else in order to keep ob-maxima in
> working condition: "--very-quite=yes 
> --another-useful-flag-we-absolutely-need-in-org"
>
> In order to make such a switch, we will have to force all the users
> change their customization - something we do not want to annoy users
> with.

I understand your general argument, but I doubt it is relevant to this
particular case.

In this specific case, that command-line option `--very-quiet' was
introduced in 17 years ago
(https://sourceforge.net/p/maxima/mailman/message/11796355/). The syntax
has not changed since it was introduced.

>
> So, leaving essential settings customizeable is not necessarily a good idea.

I understand your hesitation about full-blown customization using
`defcustom'. However, I would still like to have more dials to turn.

Perhaps we could add header arguments to get the desired customization?
E.g.

- :batch :: Control how the Maxima source is evaluated by Maxima.
  1. Default. If nil or no, then use batchload with the --very-quiet
 command-line flag.
  2. If t or yes, then use batch with the --quiet command-line flag;

- :plot-engine :: Set the plotting package.
  1. Default. If nil or no, the use `plot';
  2. If `draw', then use `draw'.

- Similarly, we could do something like ob-R.el does, and construct the
  graphics instructions using some additional header arguments and
  grovelling the terminal from the filename (see
  org-babel-R-construct-graphics-device-call).

My sense is that this would be more in keeping with how other ob-*.el
packages do things.

Best,
Leo


Re: [BUG] Consider replacing bachload with batch in ob-maxima. [9.6.6 (release_9.6.6 @ /usr/share/emacs/30.0.50/lisp/org/)]

2023-09-02 Thread Leo Butler
On Sat, Sep 02 2023, Ihor Radchenko  wrote:

> Lockywolf  writes:
>
>> At the moment, ob-maxima has a straightforward way of evaluating
>> babel blocks,
>>
>> #+begin_src shell
>> maxima --very-quiet -r batchload\(\"/tmp/ob-maximaFOOBAR.mac\"\)\$
>> #+end_src
>> (line 87 of ob-maxima.el),
>>
>> I suggest replacing batchload with batch(), and changing line 73 from
>> "gnuplot_close ()$" to   "gnuplot_close ()$ \nquit();"
>>
>> The difference between "batch" and "batchload" is that "batch" can
>> process :lisp expressions in addition to maxima's own, and it prints
>> input/output labels. However, it is possible to customise label printing
>> from maxima's own code, and being able to evaluate :lisp just seems
>> uncontrovercially good.
>>
>> It might be that I am missing something, but batch seems a better fit
>> for Org-Babel.
>
> May you please explain more about :lisp expressions?

This special syntax is not necessary. A recent change introduced the
function `eval_string_lisp' that removes the need for it. I.e. one can
batchload a file and execute lisp code inside a call to eval_string_lisp.

>
> Also, what is the benefit/downside of printing input/output labels? Is
> there any chance they will be caught into the source block output? If
> so, it would be a breaking change.

Yes, his requests are breaking changes. That is why I suggested opening
up the internals a bit so that one can alter the behavior while
maintaining the same default.

Leo



Re: [BUG] Consider replacing bachload with batch in ob-maxima. [9.6.6 (release_9.6.6 @ /usr/share/emacs/30.0.50/lisp/org/)]

2023-09-02 Thread Leo Butler
On Sat, Sep 02 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I think that your request may be handled by one of two improvements:
>>
>> 1. Implement session support in ob-maxima.el; and
>> 2. Many of the design decisions in the existing ob-maxima code should be
>> customizable.
>
>> I am attaching a patch to address 2. Please try it out, I think that it
>> will satisfy your requests. Feedback is welcome.
>
> Thanks for the patch!
>
>> +(defcustom org-babel-maxima-command-arguments
>> +  "--very-quiet"
>
>> +(defcustom org-babel-maxima-batch/load
>> +  "batchload"
>> +
>> +(defcustom org-babel-maxima-graphic-file-format-string
>> +  "(set_plot_option ('[gnuplot_term, png]), set_plot_option 
>> ('[gnuplot_out_file, %S]))$"
>> +
>> +(defcustom org-babel-maxima-default-epilogue
>> +  "gnuplot_close ()$"
>
> This might be fine, but may you please explain what would be the purpose
> of customizing each of these options?

I am not sure of your request: do you want me to elaborate in the
docstrings? Or here?

>
> IMHO, in their current state, if a user mindlessly customizes these
> options without knowing how ob-maxima internals work, ob-maxima may
> simply be broken.

I think there is a fine line between being too rigid but working within
a limited scope (as ob-maxima is now), or providing enough customizable
options to let users do what they want. I would prefer the latter,
if the defaults provide a working configuration.

Note that I do attempt to suggest other working options in the defcustom
definitions.

> It is also not very clear what would be the benefit
> customizing any of the proposed options.

I had planned to update the worg documentation with some examples, but
here is one that answers the OP's original question:

>> +(defcustom org-babel-maxima-command-arguments
>> +  "--very-quiet"

This is the current setting.

It can be useful to include the build information that Maxima provides
on start-up, which would mean setting this to "".

>
>> +(defcustom org-babel-maxima-batch/load
>> +  "batchload"

This is the current setting.

Another option suggested is "batch". That is what the OP originally
requested.

>> +
>> +(defcustom org-babel-maxima-graphic-file-format-string
>> +  "(set_plot_option ('[gnuplot_term, png]), set_plot_option 
>> ('[gnuplot_out_file, %S]))$"

This is the current setting.

An alternative is to use the `draw' package, which is a suggested
option. Draw, in my opinion, is a much better package for plotting.

>> +
>> +(defcustom org-babel-maxima-default-epilogue
>> +  "gnuplot_close ()$"

This is the current setting.

The current setting is not needed in recent versions of Maxima (since
roughly 2010, I believe), except possibly on Windows. And, it is only
needed if `:results graphics file' is included as a src header.

On the other hand, the OP had requested adding

"quit() $"

to this setting. I don't think that is needed, but Maxima is built with
more than 6 different common-lisp implementations so there can be lots
of variability in how common tasks are performed...

>
> As a general rule, we do not expose internal details that are _required_
> for things to work to users.

I understand this principle, but, why not provide enough options for
users to configure a package to do what they want? Yes, that may mean
they break the package--but only temporarily, because returning to the
default options will return the package to a working state.

> In the above, `org-babel-maxima-default-epilogue' appears to be paired
> with `org-babel-maxima-graphic-file-format-string' and may need to be
> changed depending on its value.

No, they are not closely connected. Both plot and draw use gnuplot as
the graphing backend (although draw might be able to use vtk, that
capability has not been maintained...).

> Also, I am not sure if removing --very-quiet may
> not affect :results output.

Yes, it will. But that is what the OP is asking for.



I think that the original intention of ob-maxima was to provide a simple
`calculator'-like interface to Maxima. In many cases, though, one wants
to show a sequence of calculations that lead to the final answer. That
is why being able to configure some of these hard-coded settings is
desirable: to be able to modify how the input and output are presented.

Best regards,
Leo


Re: [BUG] Consider replacing bachload with batch in ob-maxima. [9.6.6 (release_9.6.6 @ /usr/share/emacs/30.0.50/lisp/org/)]

2023-09-01 Thread Leo Butler
On Fri, Sep 01 2023, Lockywolf  wrote:

> Dear org developers,
>
> At the moment, ob-maxima has a straightforward way of evaluating
> babel blocks,
>
> #+begin_src shell
> maxima --very-quiet -r batchload\(\"/tmp/ob-maximaFOOBAR.mac\"\)\$
> #+end_src
>
> (line 87 of ob-maxima.el),
>
> I suggest replacing batchload with batch(), and changing line 73 from
> "gnuplot_close ()$" to"gnuplot_close ()$ \nquit();"
>
> The difference between "batch" and "batchload" is that "batch" can
> process :lisp expressions in addition to maxima's own, and it prints
> input/output labels. However, it is possible to customise label printing
> from maxima's own code, and being able to evaluate :lisp just seems
> uncontrovercially good.
>
> It might be that I am missing something, but batch seems a better fit
> for Org-Babel.

Hello,

I think that your request may be handled by one of two improvements:

1. Implement session support in ob-maxima.el; and
2. Many of the design decisions in the existing ob-maxima code should be
customizable.

I am attaching a patch to address 2. Please try it out, I think that it
will satisfy your requests. Feedback is welcome.

---

This old thread may also be relevant:
https://list.orgmode.org/87o7q5rw62@t14.reltub.ca/

Best,
Leo


diff --git a/lisp/ob-maxima.el b/lisp/ob-maxima.el
index d1d7c7424..848811628 100644
--- a/lisp/ob-maxima.el
+++ b/lisp/ob-maxima.el
@@ -48,6 +48,33 @@
   :group 'org-babel
   :type 'string)
 
+(defcustom org-babel-maxima-command-arguments
+  "--very-quiet"
+  "Command-line arguments used when calling the Maxima executable. See `org-babel-maxima-batch/load' and `org-babel-execute:maxima'."
+  :group 'org-babel
+  :type 'string)
+
+(defcustom org-babel-maxima-batch/load
+  "batchload"
+  "The Maxima function used to read and execute Maxima code: `batchload' and `batch' are two alternatives, although a user-defined Maxima function may also be used. See `org-babel-execute:maxima'."
+  :options '("batchload" "batch")
+  :group 'org-babel
+  :type 'string)
+
+(defcustom org-babel-maxima-graphic-file-format-string
+  "(set_plot_option ('[gnuplot_term, png]), set_plot_option ('[gnuplot_out_file, %S]))$"
+  "A string with the Maxima code to set the graphic file terminal and name. It must contain `%S' to set the filename. See `org-babel-maxima-expand'."
+  :options '("(set_plot_option ('[gnuplot_term, png]), set_plot_option ('[gnuplot_out_file, %S]))$" "(load(draw), set_draw_option(terminal='pngcairo,file_name=%S))$")
+  :group 'org-babel
+  :type 'string)
+
+
+(defcustom org-babel-maxima-default-epilogue
+  "gnuplot_close ()$"
+  "A string with the final Maxima code executed. See `org-babel-maxima-expand'."
+  :group 'org-babel
+  :type 'string)
+
 (defun org-babel-maxima-expand (body params)
   "Expand a block of Maxima code according to its header arguments."
   (let ((vars (org-babel--get-vars params))
@@ -60,9 +87,7 @@
 		;; graphic output
 		(let ((graphic-file (ignore-errors (org-babel-graphical-output-file params
 		  (if graphic-file
-		  (format
-		   "set_plot_option ([gnuplot_term, png]); set_plot_option ([gnuplot_out_file, %S]);"
-		   graphic-file)
+		  (format org-babel-maxima-graphic-file-format-string graphic-file)
 		""))
 		;; variables
 		(mapconcat 'org-babel-maxima-var-to-maxima vars "\n")
@@ -70,7 +95,7 @@
 		body
 		;; Any code from the specified epilogue at the end.
 		epilogue
-		"gnuplot_close ()$")
+		org-babel-maxima-default-epilogue)
 	   "\n")))
 
 (defun org-babel-execute:maxima (body params)
@@ -81,10 +106,11 @@ This function is called by `org-babel-execute-src-block'."
 	(result
 	 (let* ((cmdline (or (cdr (assq :cmdline params)) ""))
 		(in-file (org-babel-temp-file "maxima-" ".max"))
-		(cmd (format "%s --very-quiet -r %s %s"
+		(cmd (format "%s %s -r %s %s"
 			 org-babel-maxima-command
+ org-babel-maxima-command-arguments
  (shell-quote-argument
-  (format "batchload(%S)$" in-file))
+  (format "%s(%S)$" org-babel-maxima-batch/load in-file))
  cmdline)))
 	   (with-temp-file in-file (insert (org-babel-maxima-expand body params)))
 	   (message cmd)


Re: org-cite: how to force a reparsing of the .bib file

2023-08-24 Thread Leo Butler
On Thu, Aug 24 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> Does the attached patch fix the problem?
>>
>> ...
>> To avoid an unneeded setq, I applied the patch:
>>
>>   (dolist (file (mapcar #'file-truename 
>> (org-cite-list-bibliography-files)))
>
> This would create an extra list and increase GC pressure. So, I prefer setq.
>
>> This caused the bibtex file to be re-parsed when I changed it.
>
> Thanks for testing!
> Applied.
> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=3c3db7b33

Thanks, Ihor.
Leo


Re: org-cite: how to force a reparsing of the .bib file

2023-08-23 Thread Leo Butler
On Wed, Aug 23 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Does org-cite monitor contents or the timestamp?
>> I am using a symlink to the bib file.
>
> Timestamp.
>
> Does the attached patch fix the problem?

Thanks, Ihor.

To avoid an unneeded setq, I applied the patch:

  (dolist (file (mapcar #'file-truename (org-cite-list-bibliography-files)))

This caused the bibtex file to be re-parsed when I changed it.

Best,
Leo

>
> From 39b503301fc7a3ea68733dfd9e4391e3f84efec8 Mon Sep 17 00:00:00 2001
> Message-ID: 
> <39b503301fc7a3ea68733dfd9e4391e3f84efec8.1692781998.git.yanta...@posteo.net>
> From: Ihor Radchenko 
> Date: Wed, 23 Aug 2023 12:12:13 +0300
> Subject: [PATCH] oc-basic: Fix detecting changes in symlinked bibliography
>
> * lisp/oc-basic.el (org-cite-basic--parse-bibliography): Use
> `file-truename' to follow symlinks first before checking bibliography
> file change times.
>
> Reported-by: Leo Butler 
> Link: https://orgmode.org/list/877cpmkds1@t14.reltub.ca
> ---
>  lisp/oc-basic.el | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el
> index 84d9492ea..c4468e5a8 100644
> --- a/lisp/oc-basic.el
> +++ b/lisp/oc-basic.el
> @@ -272,6 +272,9 @@ (defun org-cite-basic--parse-bibliography ( info)
>(plist-get info :cite-basic/bibliography)
>  (let ((results nil))
>(dolist (file (org-cite-list-bibliography-files))
> +;; Follow symlinks, to look into modification time of the
> +;; actual file, not its symlink.
> +(setq file (file-truename file))
>  (when (file-readable-p file)
>(with-temp-buffer
>  (when (or (org-file-has-changed-p file)
> -- 
> 2.41.0


Re: org-cite: how to force a reparsing of the .bib file

2023-08-22 Thread Leo Butler
On Tue, Aug 22 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I am struggling with org-cite at the moment. One problem: it is not
>> re-parsing my .bib file, so it is not picking up changes. How can I
>> force it to pick up changes?
>
> Please, provide more details.
> org-cite should already monitor .bib file contents and re-parse it as
> necessary.

Does org-cite monitor contents or the timestamp?
I am using a symlink to the bib file.

Leo


org-cite: how to force a reparsing of the .bib file

2023-08-22 Thread Leo Butler
Hello,

I am struggling with org-cite at the moment. One problem: it is not
re-parsing my .bib file, so it is not picking up changes. How can I
force it to pick up changes?

TIA,
Leo

ps: (insert (format "\n%s\nOrg: %s" (emacs-version) (org-version)))
GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo 
version 1.16.0)
 of 2023-05-13, modified by Debian
Org: 9.6.7


Re: [PATCH] float format specifier in ob-C.el

2023-06-02 Thread Leo Butler
On Fri, Jun 02 2023, Ihor Radchenko  wrote:

> Thanks!
> Applied, onto bugfix.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d55a11214

Thanks, Ihor.
Leo


Re: [PATCH] float format specifier in ob-C.el

2023-06-01 Thread Leo Butler
On Thu, Jun 01 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> In ob-C.el, line 339 has the format specifier
>>
>>  (`floatp '("double" "%f"))
>>
>> to print literal floats. However, that format specifier rounds, which
>> can result in errors. I think the correct approach is to print the
>> float without rounding or padding or trying to guess at the desired
>> accuracy (and let the compiler do whatever is needed):
>>
>>(`floatp '("double" "%s"))
>
> Makes sense. Thanks!
>
>> -(`floatp '("double" "%f"))
>> +(`floatp '("double" "%s"))
>
> Please add comment explaining why not %f. Otherwise, it is not fully
> clear why "%s" is used.

Done.

>
>> --- a/testing/examples/ob-C-test.org
>> +++ b/testing/examples/ob-C-test.org
>> @@ -60,6 +60,12 @@
>>return 0;
>>  #+end_src
>>  
>> +#+source: float_var
>> +#+begin_src cpp :var x=1.123456789012345678 :includes "" :results 
>> silent
>> +double y = 1.123456789012345678;
>> +std::cout << (x == y);
>> +#+end_src
>
> Please move the source block directly into the test using
> `org-test-with-temp-text'. The test will be more readable then.
>
> `org-test-at-id' should better be used only when necessary in order to
> not jump back and forth when debugging tests.

Ok, I have made the changes requested. Please see the attached patch.

Leo

From 65bddc861c1f439e98d5764f0587e97d4d99a190 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 1 Jun 2023 13:39:13 -0500
Subject: [PATCH] lisp/ob-C.el: replace %f with %s to prevent unneeded rounding

* lisp/ob-C.el (org-babel-C-val-to-C-type): Floats should be printed
as string literals to prevent rounding introduced by %f format.

* testing/lisp/test-ob-C.el (ob-C/float-var): Test that floats are not
rounded when passed as an org :var.
---
 lisp/ob-C.el  |  2 +-
 testing/lisp/test-ob-C.el | 11 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623..7763c4c07 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -339,7 +339,7 @@ FORMAT can be either a format string or a function which is called with VAL."
 	 (type
 	  (pcase basetype
 	(`integerp '("int" "%d"))
-	(`floatp '("double" "%f"))
+	(`floatp '("double" "%s")) ;; %f rounds, use %s to print the float literally
 	(`stringp
 	 (list
 	  (if (eq org-babel-c-variant 'd) "string" "const char*")
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e3..8546a48dd 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -95,6 +95,17 @@
 		  (org-babel-next-src-block 10)
 		  (should (= 42 (org-babel-execute-src-block))
 
+(ert-deftest ob-C/float-var ()
+  "Test that floats are passed without unnecessary rounding."
+  (if (executable-find org-babel-C++-compiler)
+  (org-test-with-temp-text 
+"#+source: float_var
+#+begin_src cpp :var x=1.123456789012345678 :includes \"\" :results silent
+double y = 1.123456789012345678;
+std::cout << (x == y);
+#+end_src"
+(should (= 1 (org-babel-execute-src-block))
+
 (ert-deftest ob-C/table ()
   "Test of a table output"
   (if (executable-find org-babel-C++-compiler)

base-commit: 5b4eebfabdc6a9b4ed223025161a342cb312c1d0
-- 
2.39.2



[PATCH] float format specifier in ob-C.el

2023-05-31 Thread Leo Butler
In ob-C.el, line 339 has the format specifier

(`floatp '("double" "%f"))

to print literal floats. However, that format specifier rounds, which
can result in errors. I think the correct approach is to print the
float without rounding or padding or trying to guess at the desired
accuracy (and let the compiler do whatever is needed):

   (`floatp '("double" "%s"))

Attached is a patch with a test that illustrates the problem (it fails
on HEAD but passes with the patch).

Leo



diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623..6b9898ebb 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -339,7 +339,7 @@ FORMAT can be either a format string or a function which is called with VAL."
 	 (type
 	  (pcase basetype
 	(`integerp '("int" "%d"))
-	(`floatp '("double" "%f"))
+	(`floatp '("double" "%s"))
 	(`stringp
 	 (list
 	  (if (eq org-babel-c-variant 'd) "string" "const char*")
diff --git a/testing/examples/ob-C-test.org b/testing/examples/ob-C-test.org
index c7a96f665..58ace91de 100644
--- a/testing/examples/ob-C-test.org
+++ b/testing/examples/ob-C-test.org
@@ -60,6 +60,12 @@
   return 0;
 #+end_src
 
+#+source: float_var
+#+begin_src cpp :var x=1.123456789012345678 :includes "" :results silent
+double y = 1.123456789012345678;
+std::cout << (x == y);
+#+end_src
+
 * Array
   :PROPERTIES:
   :ID:   2df1ab83-3fa3-462a-a1f3-3aef6044a874
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e3..41b500d5b 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -95,6 +95,13 @@
 		  (org-babel-next-src-block 10)
 		  (should (= 42 (org-babel-execute-src-block))
 
+(ert-deftest ob-C/float-var ()
+  "Test of a string variable"
+  (if (executable-find org-babel-C++-compiler)
+  (org-test-at-id "fa6db330-e960-4ea2-ac67-94bb845b8577"
+		  (org-babel-next-src-block 11)
+		  (should (= 1 (org-babel-execute-src-block))
+
 (ert-deftest ob-C/table ()
   "Test of a table output"
   (if (executable-find org-babel-C++-compiler)


Re: [RFC/PATCH] naming src/bin files in ob-C.el

2023-05-15 Thread Leo Butler
On Mon, May 15 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> On the other hand, I don't see any sense in producing a link to the
>> binary file. Org can't do anything with that link, so the user would
>> need to write something like ":results file :file /path/to :wrap
>> comment". That is why I would prefer something like a :bin-file header.
>
> I am not sure how I feel about such side effects of evaluation.
> Is there any other babel backend that is doing something similar?

ob-java.el deals with it by using a :dir header; if non-nil, the
compiled files are placed in that directory instead of
`org-babel-temporary-directory'. (And, by default, the :dir header is
"."). The filename is determined by the packagename.

Leo


Re: [RFC/PATCH] naming src/bin files in ob-C.el

2023-05-14 Thread Leo Butler
On Sat, May 13 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> IMHO, it will be more consistent with other backends to use :results file 
>>> :file /path/to/executable
>>
>> No, I don't think this is the way to do it. What happens in this
>> case is:
>>
>> 1. `org-babel-C-execute' creates a named source file, compiles it to the
>>named binary file;
>> 2. then executes that binary file, producing output;
>> 3. that output is inserted into the named binary file, overwriting its
>>contents.
>
> What I am suggesting is making :results file :file /path/to stop after 1
> and produce a link to the binary file.

Ok, stopping after 1 seems reasonable when the code block is meant to
produce just the executable. But, your suggestion would mean that the
code block can *only* produce an executable file. Maybe that is ok, but
since the current semantics allow something like

#+begin_src C++ :includes   :results file :file ./results.csv
  using namespace std;
  for(int i=0; i<10; i++){ cout << i << "," << i*i << endl; }
#+end_src

so I am not sure that we should break that.

On the other hand, I don't see any sense in producing a link to the
binary file. Org can't do anything with that link, so the user would
need to write something like ":results file :file /path/to :wrap
comment". That is why I would prefer something like a :bin-file header.

Leo


Re: [RFC/PATCH] naming src/bin files in ob-C.el

2023-05-12 Thread Leo Butler
On Fri, May 12 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> Comments?
>> ...
>> Replying to myself: it makes more sense to introduce a special-purpose
>> header argument for this special purpose, than to use :file with a
>> different meaning. Revised patch attached.
>
> IMHO, it will be more consistent with other backends to use :results file 
> :file /path/to/executable

No, I don't think this is the way to do it. What happens in this
case is:

1. `org-babel-C-execute' creates a named source file, compiles it to the
   named binary file;
2. then executes that binary file, producing output;
3. that output is inserted into the named binary file, overwriting its
   contents.

I don't see how to accomplish my stated goal of saving the binary file
to a named location without introducing a separate header argument
(e.g. ":bin-file").

Leo


Re: [RFC/PATCH] naming src/bin files in ob-C.el

2023-05-12 Thread Leo Butler
On Fri, May 12 2023, Leo Butler  wrote:

> Hello,
>
> I am using ob-C.el to work with a c++ library (capd::dynsys). The
> current behaviour creates a temporary src and bin file in
> `org-babel-temporary-directory'. There is currently no option to have
> these files named and put somewhere else.
>
> This behaviour is not quite right, in my opinion. I would like to be
> able to compile an executable and then be able to call this same
> executable without needing to recompile from source.
>
> Attached is a patch that uses the :file header to allow the naming of
> the source and compiled binary files.
>
> A test is included, too. All tests pass with this patch applied to HEAD
> (except the expected failures, of course).
>
> Comments?
>
> Leo
>
> ps: It might be better to use a custom header for this purpose,
> something like :bin-file. I am open to suggestions.

Replying to myself: it makes more sense to introduce a special-purpose
header argument for this special purpose, than to use :file with a
different meaning. Revised patch attached.

Leo

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623..57633cc9f 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -53,7 +53,8 @@
 (main. :any)
 (flags   . :any)
 (cmdline . :any)
-(libs. :any))
+(libs. :any)
+(bin-file . :any))
   "C/C++-specific header arguments.")
 
 (defconst org-babel-header-args:C++
@@ -128,16 +129,21 @@ This function is called by `org-babel-execute-src-block'."
   "Expand a block of C code with org-babel according to its header arguments."
   (let ((org-babel-c-variant 'c)) (org-babel-C-expand-C body params)))
 
+(defun org-babel-C-src/bin-file (params src?)
+  "Return the src or bin file name."
+  (let* ((f (cdr (assq :bin-file params)))
+ (file (or f (if src? "C-src-" "C-bin-")))
+ (ext (if src? (pcase org-babel-c-variant
+	 (`c ".c") (`cpp ".cpp") (`d ".d")) org-babel-exeext)))
+(org-babel-process-file-name
+ (if f (concat file ext)
+   (org-babel-temp-file file ext)
+
 (defun org-babel-C-execute (body params)
   "This function should only be called by `org-babel-execute:C'
 or `org-babel-execute:C++' or `org-babel-execute:D'."
-  (let* ((tmp-src-file (org-babel-temp-file
-			"C-src-"
-			(pcase org-babel-c-variant
-			  (`c ".c") (`cpp ".cpp") (`d ".d"
-	 (tmp-bin-file			;not used for D
-	  (org-babel-process-file-name
-	   (org-babel-temp-file "C-bin-" org-babel-exeext)))
+  (let* ((tmp-src-file (org-babel-C-src/bin-file params t))
+	 (tmp-bin-file (org-babel-C-src/bin-file params nil)) ;not used for D
 	 (cmdline (cdr (assq :cmdline params)))
 	 (cmdline (if cmdline (concat " " cmdline) ""))
 	 (flags (cdr (assq :flags params)))
diff --git a/testing/examples/ob-C-test.org b/testing/examples/ob-C-test.org
index c7a96f665..57fa42cec 100644
--- a/testing/examples/ob-C-test.org
+++ b/testing/examples/ob-C-test.org
@@ -174,3 +174,13 @@ std::cout << "\"line 1\"\n";
 std::cout << "\"line 2\"\n";
 std::cout << "\"line 3\"\n";
 #+end_src
+
+* File naming
+:PROPERTIES:
+:ID:   1a691f36-f9c1-4531-8fc0-ee7b21ef5975
+:END:
+
+#+source: file_naming
+#+begin_src cpp :includes  :results output raw drawer :bin-file ./hello-world
+std::cout << "Hello World!\n";
+#+end_src
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e3..3d16d1ae5 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -192,5 +192,19 @@
"\"line 1\"\n\"line 2\"\n\"line 3\"\n"
(org-babel-execute-src-block))
 
+(ert-deftest ob-C/set-src+bin-file-name ()
+  "Set the name of the src and bin file names created by `org-babel-C-execute'."
+  (if (executable-find org-babel-C++-compiler)
+  (unwind-protect
+  (org-test-at-id "1a691f36-f9c1-4531-8fc0-ee7b21ef5975"
+(org-babel-next-src-block 1)
+(should (equal
+ "Hello World!\n"
+ (org-babel-execute-src-block)))
+(should (file-exists-p "./hello-world"))
+(should (file-exists-p "./hello-world.cpp")))
+(ignore-errors (delete-file "./hello-world"))
+(ignore-errors (delete-file "./hello-world.cpp")
+
 (provide 'test-ob-C)
 ;;; test-ob-C.el ends here


[RFC/PATCH] naming src/bin files in ob-C.el

2023-05-12 Thread Leo Butler
Hello,

I am using ob-C.el to work with a c++ library (capd::dynsys). The
current behaviour creates a temporary src and bin file in
`org-babel-temporary-directory'. There is currently no option to have
these files named and put somewhere else.

This behaviour is not quite right, in my opinion. I would like to be
able to compile an executable and then be able to call this same
executable without needing to recompile from source.

Attached is a patch that uses the :file header to allow the naming of
the source and compiled binary files.

A test is included, too. All tests pass with this patch applied to HEAD
(except the expected failures, of course).

Comments?

Leo

ps: It might be better to use a custom header for this purpose,
something like :bin-file. I am open to suggestions.

diff --git a/lisp/ob-C.el b/lisp/ob-C.el
index 3a6e99623..76842acb6 100644
--- a/lisp/ob-C.el
+++ b/lisp/ob-C.el
@@ -128,16 +128,21 @@ This function is called by `org-babel-execute-src-block'."
   "Expand a block of C code with org-babel according to its header arguments."
   (let ((org-babel-c-variant 'c)) (org-babel-C-expand-C body params)))
 
+(defun org-babel-C-src/bin-file (params src?)
+  "Return the src or bin file name."
+  (let* ((f (cdr (assq :file params)))
+ (file (or f (if src? "C-src-" "C-bin-")))
+ (ext (if src? (pcase org-babel-c-variant
+	 (`c ".c") (`cpp ".cpp") (`d ".d")) org-babel-exeext)))
+(org-babel-process-file-name
+ (if f (concat file ext)
+   (org-babel-temp-file file ext)
+
 (defun org-babel-C-execute (body params)
   "This function should only be called by `org-babel-execute:C'
 or `org-babel-execute:C++' or `org-babel-execute:D'."
-  (let* ((tmp-src-file (org-babel-temp-file
-			"C-src-"
-			(pcase org-babel-c-variant
-			  (`c ".c") (`cpp ".cpp") (`d ".d"
-	 (tmp-bin-file			;not used for D
-	  (org-babel-process-file-name
-	   (org-babel-temp-file "C-bin-" org-babel-exeext)))
+  (let* ((tmp-src-file (org-babel-C-src/bin-file params t))
+	 (tmp-bin-file (org-babel-C-src/bin-file params nil)) ;not used for D
 	 (cmdline (cdr (assq :cmdline params)))
 	 (cmdline (if cmdline (concat " " cmdline) ""))
 	 (flags (cdr (assq :flags params)))
diff --git a/testing/examples/ob-C-test.org b/testing/examples/ob-C-test.org
index c7a96f665..1a104ae6a 100644
--- a/testing/examples/ob-C-test.org
+++ b/testing/examples/ob-C-test.org
@@ -174,3 +174,13 @@ std::cout << "\"line 1\"\n";
 std::cout << "\"line 2\"\n";
 std::cout << "\"line 3\"\n";
 #+end_src
+
+* File naming
+:PROPERTIES:
+:ID:   1a691f36-f9c1-4531-8fc0-ee7b21ef5975
+:END:
+
+#+source: file_naming
+#+begin_src cpp :includes  :results output raw drawer :file ./hello-world
+std::cout << "Hello World!\n";
+#+end_src
diff --git a/testing/lisp/test-ob-C.el b/testing/lisp/test-ob-C.el
index b6dbed8e3..3d16d1ae5 100644
--- a/testing/lisp/test-ob-C.el
+++ b/testing/lisp/test-ob-C.el
@@ -192,5 +192,19 @@
"\"line 1\"\n\"line 2\"\n\"line 3\"\n"
(org-babel-execute-src-block))
 
+(ert-deftest ob-C/set-src+bin-file-name ()
+  "Set the name of the src and bin file names created by `org-babel-C-execute'."
+  (if (executable-find org-babel-C++-compiler)
+  (unwind-protect
+  (org-test-at-id "1a691f36-f9c1-4531-8fc0-ee7b21ef5975"
+(org-babel-next-src-block 1)
+(should (equal
+ "Hello World!\n"
+ (org-babel-execute-src-block)))
+(should (file-exists-p "./hello-world"))
+(should (file-exists-p "./hello-world.cpp")))
+(ignore-errors (delete-file "./hello-world"))
+(ignore-errors (delete-file "./hello-world.cpp")
+
 (provide 'test-ob-C)
 ;;; test-ob-C.el ends here


Re: ox-beamer/latex questions

2023-03-03 Thread Leo Butler
On Fri, Mar 03 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> This is because
>>>  *** DONE :B_block:
>>> is actually parsed as a heading with DONE todo keyword and title
>>> ":B_block:". Tag is not recognized.
>>>
>>> We probably need to fix it, though I am not sure. It is one of the edge
>>> cases about Org parser.
>>
>> Ok. I have become addicted to using TODO tags to organize composition of
>> beamer slides. I often have untitled blocks in the slides, in order to
>> control the pacing of the presentation.
>
> I understand. Just need to figure out the best way to alter the syntax.
> We should be careful with such things.

Understood.

>
>>> For cookies, just use stat:nil in OPTIONS. See "13.2 Export Settings"
>>> section of the manual.
>>
>> Thanks for that. I am not sure how I missed it.
>>
>> Anyhow, it does not work correctly for subtree export (or I am not
>> understanding something). The title still includes the cookie. See the
>> attached.
>
> That was a rather interesting edge case that triggered a bug in
> org-element.el.
>
> Fixed, on main. It was a core function, so I did not risk bugfix.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f93cc661c

Thanks, Ihor.

Leo


Re: ox-beamer/latex questions

2023-03-01 Thread Leo Butler
On Wed, Mar 01 2023, Leo Butler  wrote:

> On Wed, Mar 01 2023, Ihor Radchenko  wrote:

>> For cookies, just use stat:nil in OPTIONS. See "13.2 Export Settings"
>> section of the manual.
>
> Anyhow, it does not work correctly for subtree export (or I am not
> understanding something). The title still includes the cookie. See the
> attached.

Marking the subtree with `C-c @' before export does result in the cookie
being removed from the title.

Is there an easy explanation why marking the subtree matters? I.e. why
do

C-c @ C-c C-e C-s l P

and

C-c C-e C-s l P

work differently?

Leo


Re: ox-beamer/latex questions

2023-03-01 Thread Leo Butler
On Wed, Mar 01 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I have a couple questions about TODO items, cookies and export. I am
>> unable to find anything the manual that seems relevant. Please see the
>> attached.
>
>> *** DONE:B_block:
>> :PROPERTIES:
>> :BEAMER_env: block
>> :END:
>> With =ox-beamer=, =TODO= markers mangle the output. That looks like a bug to 
>> me.
>
> This is because
>  *** DONE :B_block:
> is actually parsed as a heading with DONE todo keyword and title
> ":B_block:". Tag is not recognized.
>
> We probably need to fix it, though I am not sure. It is one of the edge
> cases about Org parser.

Ok. I have become addicted to using TODO tags to organize composition of
beamer slides. I often have untitled blocks in the slides, in order to
control the pacing of the presentation.

>
>> I would like to be able to remove the =TODO= cookies, =[1/2]= and =[0/1]=, 
>> on export.
>> How can I do that?
>
> For cookies, just use stat:nil in OPTIONS. See "13.2 Export Settings"
> section of the manual.

Thanks for that. I am not sure how I missed it.

Anyhow, it does not work correctly for subtree export (or I am not
understanding something). The title still includes the cookie. See the
attached.

TIA,
Leo

#+TITLE: ox-beamer/latex questions
#+AUTHOR: Leo Butler
#+OPTIONS: H:2 toc:t num:t tags:nil todo:nil stat:nil
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+LATEX_COMPILER: lualatex
#+STARTUP: beamer

* TODO [1/2] ox-beamer/latex questions
** DONE [1/2] Outline
*** DONE Slide 1:B_block:
:PROPERTIES:
:BEAMER_env: block
:END:
The =DONE= tag and =[1/2]= cookie should be filtered out by
=stat:nil=. Thanks, Ihor.

*** TODO Slide 2:B_block:
:PROPERTIES:
:BEAMER_env: block
:END:
However, the title is still mangled when exporting just this heading using =C-c C-e C-s l P= on the heading.

* TODO A second question
** TODO [1/1] Questions
*** DONE:B_block:
:PROPERTIES:
:BEAMER_env: block
:END:
With =ox-beamer=, =TODO= markers mangle the output. That looks like a bug to me.
Ihor says this is an edge case.


ox-beamer-q.pdf
Description: ox-beamer-q.pdf


ox-beamer/latex questions

2023-02-28 Thread Leo Butler
Hello,

I have a couple questions about TODO items, cookies and export. I am
unable to find anything the manual that seems relevant. Please see the
attached.

TIA,
Leo

#+TITLE: ox-beamer/latex questions
#+AUTHOR: Leo Butler
#+OPTIONS: H:2 toc:t num:t tags:nil todo:nil
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+LATEX_COMPILER: lualatex
#+STARTUP: beamer

* TODO [0/1] Outline
** TODO [1/2] Questions
*** DONE:B_block:
:PROPERTIES:
:BEAMER_env: block
:END:
With =ox-beamer=, =TODO= markers mangle the output. That looks like a bug to me.

*** TODO Filter out cookies
:PROPERTIES:
:BEAMER_act: <2->
:END:
I would like to be able to remove the =TODO= cookies, =[1/2]= and =[0/1]=, on export.
How can I do that?


ox-beamer-q.pdf
Description: ox-beamer-q.pdf


Re: Template for ob- packages?

2023-02-17 Thread Leo Butler
On Thu, Feb 16 2023, Matt  wrote:

>   On Thu, 16 Feb 2023 16:10:51 -0500  Galaxy Being  wrote --- 
>  > Is there a generic starter template for writing an ob-
> package, some sort of example code?
>
> Yes: 
> https://git.sr.ht/~bzg/worg/tree/master/item/org-contrib/babel/ob-template.el
>
> When I started learned Babel, I took notes with the hope of expanding
> it into a Worg article. Here are the notes:
> https://excalamus.com/2021-11-03-org_babel.html
>
> If you're interested in fleshing out the notes into proper
> documentation, I'd be happy to help.

Matt, thanks for sharing those notes. I would suggest that they be added
to worg in their current state.

Leo

Re: [PATCH] remove unused code in ob-octave.el

2023-02-14 Thread Leo Butler
On Fri, Feb 10 2023, Max Nikulin  wrote:

> On 10/02/2023 04:21, Leo Butler wrote:
>> In lisp/ob-octave.el:
>> What is the point of ob-octave-prep-session:octave or its brother,
>> ob-octave-prep-session:matlab?
>> These two functions are unused in the existing code.
>
> Have you checked the following? I am not familiar with org-babel code.
>
> grep -nH org-babel-prep-session lisp/ob-core.el
> lisp/ob-core.el:1041:  (prep-cmd (intern (concat
> "org-babel-prep-session:" lang
> lisp/ob-core.el:1050: (error "No org-babel-prep-session function for
> %s!" lang))
>
> Do test passes when you patch is applied? It might mean that test
> coverage is not perfect.

Yes, the tests pass after removing the code.

I can see from your and Ihor's response that my suggestion is
wrongheaded. 

After looking more carefully at ob-core, I am not sure how I could write
a test for the prep-session code, though. The comment and docstring in
ob-template.el does not help me, I am afraid. And the existing
session-related tests do not touch the prep-session code.

I'll poke around in other ob-*.el code and see if I can figure it out.

Leo


Re: [TIP] Exporting Maxima results to LaTeX

2023-02-14 Thread Leo Butler
On Sat, Feb 11 2023, Max Nikulin  wrote:

> On 09/02/2023 03:40, Leo Butler wrote:
>> On Wed, Feb 08 2023, Max Nikulin wrote:
>>> I am curious if it is possible to avoid duplication by e.g. using noweb.
>> 
>> ... I am not aware of how to
>> remove that duplication--all the examples I have found in the worg
>> source do what I have done above.
>
> I have tried



Recursive evaluation of code blocks! Of course! THANK YOU!

>
> For debugging of the inner src block it is necessary to swap escaping 
> with the outer #+begin_src.

Yes, it should be possible to recursive edit in indirect buffers. I
don't see how to do that.

> I have not figured out how to add some text in between of the exported
> source code example and its result.

See the attached. You need to name a code block and manually insert the
#+RESULT: stanza where you want the result put.

Thanks to Max and Eric for their comments. I have incorporated the
comments in the attached.

Leo

#+TITLE: Tip for exporting Maxima results to LaTeX
#+AUTHOR: Leo Butler
#+OPTIONS: H:3 toc:t num:t tags:nil todo:nil
#+LATEX_CLASS: article
#+LATEX_HEADER: \usepackage{color} \usepackage[margin=2cm]{geometry}
#+LATEX_COMPILER: lualatex
#+PROPERTY: header-args:maxima :eval export :exports results :results raw drawer

* Goal
Generate LaTeX code from Maxima code.

* Setup
** maxima-init.lisp
The command =org-babel-execute:maxima= in =lisp/ob-maxima.el= uses the Maxima command ~batchload~ to execute Maxima code. This is a very tight-lipped loader, so we over-write ~batchload~ with ~batch~. We also ~load~ an init file:

#+name: maxima-init.lisp.org
#+begin_src org :exports code :results replace
,#+name: maxima-init.lisp
,#+begin_src maxima :tangle maxima-init.lisp :exports none
  (defun $batchload (file) (mfuncall '$batch file))
  ($load "./maxima-init.mac")
,#+end_src
#+end_src

On tangling, this produces the ~common-lisp~ output file ~maxima-init.lisp~. It will be pre-loaded into Maxima.

#+RESULTS: maxima-init.lisp.org
#+name: maxima-init.lisp
#+begin_src maxima :tangle maxima-init.lisp :exports none
  (defun $batchload (file) (mfuncall '$batch file))
  ($load "./maxima-init.mac")
#+end_src

** maxima-init.mac
Next, we need to create an init file for Maxima that will provide an output printer that produces @@latex:\LaTeX{}@@ output. One option would be to use the ~imaxima~ printer. Here is another option that uses the ~alt-display~ package.
The code replaces the default printer with ~org_tex_display~. It also sets the ~epilog~ prompt, so that the final ~#+begin_example~ is terminated.

#+name: maxima-init.mac.org
#+begin_src org :exports code :results replace
  ,#+name: maxima-init.mac
  ,#+begin_src maxima :tangle maxima-init.mac :exports none :eval none
  load("alt-display.mac") $
  set_prompt('epilog,printf(false,"~%#+end_example")) $
  define_alt_display(org_tex_display(x),
block([], 
  printf(true,"#+end_example~%#+begin_export latex~%"),
  printf(true,"\\textcolor{blue}{(\\~a~d)} ",outchar,linenum-1),
  tex(second(x)),
  printf(true,"~&#

[PATCH] remove unused code in ob-octave.el

2023-02-09 Thread Leo Butler
In lisp/ob-octave.el:

What is the point of ob-octave-prep-session:octave or its brother,
ob-octave-prep-session:matlab?

These two functions are unused in the existing code.

Leo

From f91562d9ea36d7f76f222e457c8fd1b0570e7e3d Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 9 Feb 2023 11:02:04 -0600
Subject: [PATCH] lisp/ob-octave.el: remove
 org-babel-prep-session:{octave,matlab}

* lisp/ob-octave.el (org-babel-prep-session:matlab,
org-babel-prep-session:octave):  Remove unused functions.
---
 lisp/ob-octave.el | 15 ---
 1 file changed, 15 deletions(-)

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 9bf16b984..24537ad57 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -104,10 +104,6 @@ end")
(org-babel-pick-name
 	(cdr (assq :rowname-names params)) (cdr (assq :rownames params)))
 
-(defun org-babel-prep-session:matlab (session params)
-  "Prepare SESSION according to PARAMS."
-  (org-babel-prep-session:octave session params 'matlab))
-
 (defun org-babel-variable-assignments:octave (params)
   "Return list of octave statements assigning the block's variables."
   (mapcar
@@ -133,17 +129,6 @@ specifying a variable of the same value."
  (t
   (format "%s" var)
 
-(defun org-babel-prep-session:octave (session params  matlabp)
-  "Prepare SESSION according to the header arguments specified in PARAMS."
-  (let* ((session (org-babel-octave-initiate-session session params matlabp))
-	 (var-lines (org-babel-variable-assignments:octave params)))
-(org-babel-comint-in-buffer session
-  (mapc (lambda (var)
-  (end-of-line 1) (insert var) (comint-send-input nil t)
-  (org-babel-comint-wait-for-output session))
-	var-lines))
-session))
-
 (defun org-babel-matlab-initiate-session ( session params)
   "Create a matlab inferior process buffer.
 If there is not a current inferior-process-buffer in SESSION then
-- 
2.39.1



Re: [TIP] Exporting Maxima results to LaTeX

2023-02-08 Thread Leo Butler
On Wed, Feb 08 2023, Max Nikulin  wrote:

> On 08/02/2023 04:40, Leo Butler wrote:
>> Generate @@latex:\LaTeX{}@@ code from Maxima code.
>
> You can write just LaTeX, ox-latex recognizes such pattern. The bonus
> is the it will be literally exported to HTML.

Thanks.

>
>> #+begin_example
>> ,#+begin_src maxima :tangle maxima-init.lisp :exports none
>>(defun $batchload (file) (mfuncall '$batch file))
>>($load "./maxima-init.mac")
>> ,#+end_src
>> #+end_example
>> On tangling, this produces the ~common-lisp~ output file
>> ~maxima-init.lisp~. It will be pre-loaded into Maxima.
>> #+begin_src maxima :tangle maxima-init.lisp :exports none
>>(defun $batchload (file) (mfuncall '$batch file))
>>($load "./maxima-init.mac")
>> #+end_src
>
> I am curious if it is possible to avoid duplication by e.g. using noweb.

I am not sure what you think is being duplicated. Do you mean the
duplication of the example and src blocks? I am not aware of how to
remove that duplication--all the examples I have found in the worg
source do what I have done above.

>
>> #+begin_src maxima :tangle maxima-init.mac :exports none
>
> At first glance :prologue header argument might be an alternative, but
> likely I have missed something obvious.

The prologue header is put into a temporary source file, along with the
body and epilogue and it is read by Maxima's `batchload' command. So
using a prologue is too late, because I need to overwrite `batchload' by
its more verbose companion `batch'. That is why `maxima-init.lisp' is
pre-loaded.

Leo


[TIP] Exporting Maxima results to LaTeX

2023-02-07 Thread Leo Butler
Attached is a self-documented setup to do what the subject line says.
Comments/suggestions welcome.

Best,
Leo

#+TITLE: Tip for exporting Maxima results to LaTeX
#+AUTHOR: Leo Butler
#+OPTIONS: H:2 toc:nil num:nil tags:nil todo:nil
#+LATEX_CLASS: article
#+LATEX_HEADER: \usepackage{color}
#+LATEX_COMPILER: lualatex
#+STARTUP: beamer
#+PROPERTY: header-args:maxima :eval never-export :exports results :results raw drawer

* Goal
Generate @@latex:\LaTeX{}@@ code from Maxima code.

* Setup
** maxima-init.lisp
The command =org-babel-execute:maxima= in =lisp/ob-maxima.el= uses the Maxima command ~batchload~ to execute Maxima code. This is a very tight-lipped loader, so we over-write ~batchload~ with ~batch~. We also ~load~ an init file:

#+begin_example
,#+begin_src maxima :tangle maxima-init.lisp :exports none
  (defun $batchload (file) (mfuncall '$batch file))
  ($load "./maxima-init.mac")
,#+end_src
#+end_example

On tangling, this produces the ~common-lisp~ output file ~maxima-init.lisp~. It will be pre-loaded into Maxima.

#+begin_src maxima :tangle maxima-init.lisp :exports none
  (defun $batchload (file) (mfuncall '$batch file))
  ($load "./maxima-init.mac")
#+end_src

** maxima-init.mac
Next, we need to create an init file for Maxima that will provide an output printer that produces @@latex:\LaTeX{}@@ output. One option would be to use the ~imaxima~ printer. Here is another option that uses the ~alt-display~ package.
The code replaces the default printer with ~org_tex_display~. It also sets the ~epilog~ prompt, so that the final ~#+begin_example~ is terminated.

#+begin_example
,#+begin_src maxima :tangle maxima-init.mac :exports none
  load("alt-display.mac") $
  set_prompt('epilog,printf(false,"~%#+end_example")) $
  define_alt_display(org_tex_display(x),
block([], printf(true,"#+end_example~%#+begin_export latex~%"),
  printf(true,"\\textcolor{blue}{(\\~a~d)} ",outchar,linenum-1), tex(second(x)), printf(true,"~&#

Re: [BUG] LaTeX aligned equations do not have right spacing [9.6.1 (release_9.6.1 @ /home/yhu/dev/prefix/org-mode/emacs/site-lisp/org/)]

2023-02-01 Thread Leo Butler
On Wed, Feb 01 2023, Ihor Radchenko  wrote:

> Rick Hu  writes:
>
>> Example text in org mode:
>> \begin{align}
>> H_1(x) = & 3 x^2 - 2 x^3 \\
>> S_1(x) = &  -2 x^2 + x^3 \\
>> \end{align}
>>
>> When I export this to html and display on a browser, the spacing
>> between the equal sign and the terms behind is very small.
>> This is not the right amount around an equal sign.
>
> Could you please elaborate? Maybe attach a screenshot?


Not a bug. See the attached.

Leo

#+TITLE: [BUG] LaTeX aligned equations do not have right spacing
#+AUTHOR: L. Butler
#+OPTIONS: toc:nil num:nil

* Report
#+begin_example
From: Rick Hu 
Subject: [BUG] LaTeX aligned equations do not have right spacing [9.6.1
 (release_9.6.1 @ /home/yhu/dev/prefix/org-mode/emacs/site-lisp/org/)]
To: "emacs-orgmode@gnu.org" 
Date: Mon, 30 Jan 2023 20:38:43 + (2 days, 15 minutes, 16 seconds ago)

Example text in org mode:
\begin{align}
H_1(x) = & 3 x^2 - 2 x^3 \\
S_1(x) = &  -2 x^2 + x^3 \\
\end{align}

When I export this to html and display on a browser, the spacing
between the equal sign and the terms behind is very small.
This is not the right amount around an equal sign.

Emacs  : GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu)
of 2022-09-21
Package: Org mode version 9.6.1 (release_9.6.1 @ /home/yhu/dev/prefix/org-mode/emacs/site-lisp/org/)
#+end_example

* Analysis
Let's typeset the \LaTeX{} code above:

\begin{align}
H_1(x) = & 3 x^2 - 2 x^3 \\
S_1(x) = &  -2 x^2 + x^3 \\
\end{align}

There are a few errors, I think, with the \LaTeX{} not Org. Here is the correction:

\begin{align}
H_1(x) & = 3 x^2 - 2 x^3 \\
S_1(x) & = -2 x^2 + x^3
\end{align}

Note that the spacing around the ~=~ sign is correct and there is no spurious third equation label.

** Corrected source

#+begin_example
\begin{align}
H_1(x) & = 3 x^2 - 2 x^3 \\
S_1(x) & = -2 x^2 + x^3
\end{align}
#+end_example

* Conclusion

Not a bug.


hu.pdf
Description: hu.pdf


Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-24 Thread Leo Butler
On Mon, Jan 23 2023, Ihor Radchenko  wrote:

> Ihor Radchenko  writes:
>
>> Ihor Radchenko  writes:
>>
>>> So, the test failure is real.
>>
>> The error buffer contents when the test fails is the following:
>>
>> warning: using the gnuplot graphics toolkit is discouraged
>> ...
>> [ Babel evaluation exited with code 0 ]
>>
>> Exit code is 0, so octave does finish.
>>
>> Hence, test assertion that
>> (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*")))
>> does not appear to be accurate.
>>
>> Leo, should we simply remove the assertion?
>
> I decided to remove the assertion from the tests.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=59228e51345ab522d9db611c8e73caa078d86d2f
>
> While there could be a value in making sure that ob-octave calls octave
> without generating errors, it is not strictly what the test is checking
> for.
>
> Moreover, we currently have no reliable way to disambiguate mere
> warnings from non-zero exit code.

Yes, as I said in a previous email, I can live with that.

The origin of the errors that you documented is not, I believe, due to
either of the causes suggested by either Max or you. But, investigating
obscure test failures like this is probably not the best expenditure of
time and effort.

Best regards,
Leo


Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-14 Thread Leo Butler
On Fri, Jan 13 2023, Ihor Radchenko  wrote:

> Ihor Radchenko  writes:
>
>> So, the test failure is real.
>
> The error buffer contents when the test fails is the following:
>
> warning: using the gnuplot graphics toolkit is discouraged
>
> The gnuplot graphics toolkit is not actively maintained and has a number
> of limitations that are unlikely to be fixed.  Communication with gnuplot
> uses a one-directional pipe and limited information is passed back to the
> Octave interpreter so most changes made interactively in the plot window
> will not be reflected in the graphics properties managed by Octave.  For
> example, if the plot window is closed with a mouse click, Octave will not
> be notified and will not update its internal list of open figure windows.
> The qt toolkit is recommended instead.

This is not being caused by a faulty test.

The default graphics toolkit for octave is not gnuplot. To get that
warning, the graphics toolkit needs to be set to gnuplot. But, that is
not done in those tests, so where/how is that happening?

>  line 0: warning: iconv failed to convert degree sign

This warning makes no sense to me.

> error: ignoring const execution_exception& while preparing to exit
> [ Babel evaluation exited with code 0 ]
>
> Exit code is 0, so octave does finish.
>
> Hence, test assertion that
> (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*")))
> does not appear to be accurate.

I guess it depends on what is meant by `accurate'. Those warnings make
me think that the test is running in a mis-configured environment.

>
> Leo, should we simply remove the assertion?

Ok.

I would really like to understand why the two tests are failing on
sourcehut (but not the one that creates a session), but I can understand
your viewpoint.

Leo


Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-11 Thread Leo Butler
On Wed, Jan 11 2023, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>>>> Leo, could you please take a look?
>>>>>
>>>>> An earlier test is creating that *Org Babel Error Output* buffer.
>>>
>>> I will try to look into improving the tests so that we can trap the test(s)
>>> that is(are) creating that error buffer.
>>
>> See the attachment. There are four test failures that are currently
>> untrapped. I also see the `buffer-live-p' bug. 
>
> It looks like `buffer-live-p' is not a bug, but rather the result of
> backtrace being printed upon executing `kill-buffer' in unwind-protect
> form from the test body: (1) test fails; (2) unwind-protect executes
> kill-buffer; (3) backtrace is printed with "killed" buffer object.

Yes, that seems reasonable.

>
> So, the test failure is real.
>
> https://orgmode.org/list/94980226-d29a-4969-8640-1143a1979...@bundesbrandschatzamt.de
> might be related.

Ihor,

How do you want to treat the patch that was included? I think we should
have something like that to catch errors like these. And the failing
tests should be marked as known failures (that need to be fixed,
obviously). I note that both failures 3 & 4 are related to org's
built-in features.

Leo




Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-10 Thread Leo Butler
On Sat, Jan 07 2023, Leo Butler  wrote:

> On Fri, Jan 06 2023, Ihor Radchenko  wrote:
>
>>
>> Leo Butler  writes:
>>
>>>> https://builds.sr.ht/~bzg/job/914954
>>>> 2 unexpected results:
>>>>FAILED  ob-octave/graphics-file  ((should-not (get-buffer "*Org-Babel
>>>>Error Output*")) :form (get-buffer "*Org-Babel Error Output*") :value
>>>>#) 
>>>>FAILED  ob-octave/graphics-file-space  ((should-not (get-buffer
>>>>"*Org-Babel Error Output*")) :form (get-buffer "*Org-Babel Error
>>>>Output*") :value #) 
>>>>
>>>> As you can see *Org-Babel Error Output* buffer does not exist when
>>>> running the test.
>>>>
>>>> Leo, could you please take a look?
>>>
>>> An earlier test is creating that *Org Babel Error Output* buffer.
>
> I will try to look into improving the tests so that we can trap the test(s)
> that is(are) creating that error buffer.

See the attachment. There are four test failures that are currently
untrapped. I also see the `buffer-live-p' bug. 

Leo

#+AUTHOR: Leo Butler
#+DATE: 10 Jan 2023
#+TITLE: False positives in ~org~ tests
#+STARTUP: show2levels

* Summary
Applying the [[patch-to--org-test-with-temp-text]] reveals 4 tests that fail, but which are passed with the unpatched ~org-test-with-temp-text~ macro.
The next sections show the test failures. References:
- *Org-Babel Error Output* :: [[https://orgmode.org/list/87bknh5nva.fsf@localhosthttps://orgmode.org/list/87bknh5nva.fsf@localhost]]
- buffer-live-p :: [[https://debbugs.gnu.org/cgi/bugreport.cgi?bug=60626]]
  
#+name: patch-to--org-test-with-temp-text
#+begin_example
diff --git a/testing/org-test.el b/testing/org-test.el
index 22ac60670..7909f36cc 100644
--- a/testing/org-test.el
+++ b/testing/org-test.el
@@ -196,7 +196,18 @@ otherwise place the point at the beginning of the inserted text."
 	   (insert inside-text)
 	   (goto-char (point-min
(font-lock-ensure (point-min) (point-max))
-   ,@body)))
+   (prog1
+   (progn ,@body)
+ (unwind-protect
+ (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*")))
+   (when (get-buffer "*Org-Babel Error Output*")
+ (message "Detected: *Org-Babel Error Output*")
+ (message "Contents:")
+ (message (with-current-buffer "*Org-Babel Error Output*"
+(buffer-substring-no-properties (point-min) (point-max
+ (message "End:")
+ (kill-buffer "*Org-Babel Error Output*"
+ )))
 
 (defmacro org-test-with-temp-text-in-file (text  body)
   "Run body in a temporary file buffer with Org mode as the active mode.
   #+end_example
* Command
The tests are run in-place like so:
#+begin_src sh :exports none :results raw drawer
make test-dirty
#+end_src

* Test Failures
** Failure 1
#+begin_example
Detected: *Org-Babel Error Output*
Contents:
/tmp/tmp-orgtest/fortran-src-ym6m0X.F90:5:17:

5 | write (*, ’(i2)’), nint(s(1,2))
  | 1
Warning: Legacy Extension: Comma before i/o item list at (1)
[ Babel evaluation exited with code 0 ]
/tmp/tmp-orgtest/fortran-src-EYVgCk.F90:5:17:

5 | write (*, ’(i2)’), nint(s(2,3))
  | 1
Warning: Legacy Extension: Comma before i/o item list at (1)
[ Babel evaluation exited with code 0 ]
/tmp/tmp-orgtest/fortran-src-SwTuHS.F90:5:20:

5 | write (*, ’(3f5.2)’), s
  |1
Warning: Legacy Extension: Comma before i/o item list at (1)
[ Babel evaluation exited with code 0 ]
/tmp/tmp-orgtest/fortran-src-xnH1cO.F90:5:20:

5 | write (*, ’(2f5.2)’), s
  |1
Warning: Legacy Extension: Comma before i/o item list at (1)
[ Babel evaluation exited with code 0 ]
End:
Test ob-java/args-quoted-string backtrace:
  ert-fail(((should-not (buffer-live-p (get-buffer "*Org-Babel Error O
  (if (not (unwind-protect (setq value-1015 (apply fn-1013 args-1014))
  (let (form-description-1017) (if (not (unwind-protect (setq value-10
  (let ((value-1015 'ert-form-evaluation-aborted-1016)) (let (form-des
  (let* ((fn-1013 #'buffer-live-p) (args-1014 (condition-case err (let
  (unwind-protect (let* ((fn-1013 #'buffer-live-p) (args-1014 (conditi
  (prog1 (progn (let* ((fn-1008 #'string=) (args-1009 (condition-case 
  (progn (org-mode) (let ((point (string-match "" inside-text))
  (unwind-protect (progn (org-mode) (let ((point (string-match ")
  :value t))
   FAILED71/1116  ob-java/args-quoted-string (0.313545 sec)
#+end_example
** Failure 2
#+begin_example
Detected: *Org-Babel Error Output*
Contents:
[ Babel evaluation exited with code 1 ]
[ Babel evaluation exited with code 2 ]
En

Re: setting export_file_name during export

2023-01-10 Thread Leo Butler
On Tue, Jan 10 2023, Nick Dokos  wrote:

> Leo Butler  writes:
>
>>>
>>> So: if you insert 
>>>
>>>   :PROPERTIES:
>>>   :EXPORT_FILE_NAME: lecture-1.pdf
>>>   :END:
>>>
>>
>> Aha! Thank you very much. I had forgotten about using property
>> drawers. It would be a simple matter to create a filter to insert that
>> property drawer under the heading that contains point.
>>
>
> IIUC, you really don't need to insert things dynamically: you can add
> an appropriate property drawer after every top-level heading once and
> for all.

Yes, you are correct. And, in fact, the naïve way to insert the property
dynamically (using ~org-export-before-processing-hook~) does not work:

#+name: does-not-work
#+begin_src emacs-lisp :exports none
  (defun ltb-org-insert-export-file-name (backend)
(save-excursion
  (goto-char (point-min))
  (while (search-forward-regexp "^[*] Lecture \\([0-9]+\\)" nil t)
(forward-line 1)
(let ((num (match-string 1)))
  (unless (looking-at "^:PROPERTIES:")
(let ((pty (format ":PROPERTIES:\n:EXPORT_FILE_NAME: 
lecture-%s.pdf\n:END:\n" num)))
  (insert pty)
  (message (buffer-substring-no-properties (point-min) 
(point-max)
  (add-hook 'org-export-before-processing-hook 'ltb-org-insert-export-file-name)
#+end_src

The property drawer is ignored, presumably because org has already
scanned the file and determined the filename. I guess one would need to
reach inside the document structure and alter the filename there, but I
don't have that knowledge.

Suggestions are welcome.

Leo

Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-06 Thread Leo Butler
On Fri, Jan 06 2023, Ihor Radchenko  wrote:

> 
> Caution: This message was sent from outside the University of Manitoba.
> ****
>
> Leo Butler  writes:
>
>>> Apparently, `sleep-for' 1 second was not enough, and I decided to remove
>>> checking file size completely.
>>
>> Hello Ihor,
>>
>> Is there an environment variable that could be used to determine is the
>> tests are being run on sourcehut? This would let us cut out that test on
>> sourcehut, while still keeping it elsewhere.
>
> No, we have nothing like this.
>
> In theory, we can bind something in
> https://git.sr.ht/~bzg/org-mode-tests/tree/master/item/.builds/init.el,
> but I am not sure if it is a good idea.
>
> The tests are failing not because something wrong in the CI machine, but
> simply because CI machine is slow. You can get similar issue when
> running Org tests on an actual proper old PC or simply when someone is
> running CPU-heavy process alongside with Org tests.
>
> So, I do not think that creating exceptions for CI is a good idea.

Ok.

>
>>> https://builds.sr.ht/~bzg/job/914954
>>> 2 unexpected results:
>>>FAILED  ob-octave/graphics-file  ((should-not (get-buffer "*Org-Babel
>>>Error Output*")) :form (get-buffer "*Org-Babel Error Output*") :value
>>>#) 
>>>FAILED  ob-octave/graphics-file-space  ((should-not (get-buffer
>>>"*Org-Babel Error Output*")) :form (get-buffer "*Org-Babel Error
>>>Output*") :value #) 
>>>
>>> As you can see *Org-Babel Error Output* buffer does not exist when
>>> running the test.
>>>
>>> Leo, could you please take a look?
>>
>> An earlier test is creating that *Org Babel Error Output* buffer.

I will try to look into improving the tests so that we can trap the test(s)
that is(are) creating that error buffer.

>> That is killed on the first test, before the test is actually
>> run. But GET-BUFFER behaves in an undocumented way: it returns a
>> non-nil value, #. To remedy that, I have wrapped the
>> calls in BUFFER-LIVE-P.
>
> This is not undocumented. The killed buffers still exists as Elisp
> objects:

Thanks, for pointing that out. I was relying on the docstring for
GET-BUFFER. I see that I should have looked at the Elisp
manual. Apologies.

>> See the attached patch.
>
> Thanks!
> Installed onto bugfix.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=41ebc2e40

Regards,
Leo


Re: setting export_file_name during export

2023-01-06 Thread Leo Butler
On Fri, Jan 06 2023, alain.coch...@unistra.fr wrote:

> Leo Butler writes on Fri  6 Jan 2023 21:38:
>  > Hello,
>  > 
>  > I am trying something new this semester: all my lecture notes are
>  > organized into a single org file. A minor problem: I want to export each
>  > lecture (see below) as a separate pdf file. I would like to know if
>  > anyone has ``solved'' this problem or has a suggestion on how to do it.
>  > 
>  > Ideally, I would like to have a single function that retains only the
>  > current subtree that contains point, sets EXPORT_FILE_NAME based on the
>  > top heading, and exports it as a complete beamer pdf.
>
> Hi.  Sorry if you already know this and want something more automated
> it is not too clear to me.  (What is not clear either is why you have
> '* Lecture 1' _and_ '** Lecture 1', etc., i.e., why not just
> '* Lecture 1'.)

For my setup, each heading is a separate lecture, each subheading is a
separate beamer slide, etc.

>
> So: if you insert 
>
>   :PROPERTIES:
>   :EXPORT_FILE_NAME: lecture-1.pdf
>   :END:
>

Aha! Thank you very much. I had forgotten about using property
drawers. It would be a simple matter to create a filter to insert that
property drawer under the heading that contains point.

> right after '** Lecture 1' and, with the point inside that subtree,
> do:
>
>   C-c C-e C-s l O
>
> it seems to me it does the job.

Yes, it does! Thanks again.

Leo

>
>  > #+AUTHOR: Leo Butler
>  > #+TITLE: Lectures in Math
>  > #+OPTIONS: H:2 toc:t num:t
>  > #+LATEX_CLASS: beamer
>  > #+LATEX_CLASS_OPTIONS: [presentation]
>  > #+STARTUP: beamer
>  > #+EXPORT_FILE_NAME: lectures
>  > 
>  > * Lecture 1
>  > ** Lecture 1
>  > In the beginning...This subtree should be exported to =lecture-1.pdf=.
>  > * Lecture 2
>  > ** Lecture 2
>  > Next...This subtree should be exported to =lecture-2.pdf=.


*and* that I needed to 


setting export_file_name during export

2023-01-06 Thread Leo Butler
Hello,

I am trying something new this semester: all my lecture notes are
organized into a single org file. A minor problem: I want to export each
lecture (see below) as a separate pdf file. I would like to know if
anyone has ``solved'' this problem or has a suggestion on how to do it.

Ideally, I would like to have a single function that retains only the
current subtree that contains point, sets EXPORT_FILE_NAME based on the
top heading, and exports it as a complete beamer pdf.

TIA,
Leo

#+AUTHOR: Leo Butler
#+TITLE: Lectures in Math
#+OPTIONS: H:2 toc:t num:t
#+LATEX_CLASS: beamer
#+LATEX_CLASS_OPTIONS: [presentation]
#+STARTUP: beamer
#+EXPORT_FILE_NAME: lectures

* Lecture 1
** Lecture 1
In the beginning...This subtree should be exported to =lecture-1.pdf=.
* Lecture 2
** Lecture 2
Next...This subtree should be exported to =lecture-2.pdf=.


Re: [TASK] Enhance Worg HTML styling

2023-01-05 Thread Leo Butler
On Fri, Jan 06 2023, Tim Cross  wrote:

> alain.coch...@unistra.fr writes:
>
>> Tim Cross writes on Thu  5 Jan 2023 09:43:
>>
>>  > As a simple example, try increasing the font size and see what
>>  > happens to the menus. Keep in mind that some users require a very
>>  > large font (for example, I use a 26 or 28 pt font.
>>
>> OK, I understand.  (Even with default font size, I hate that the table
>> of contents hides some parts of the text -- I had forgotten about
>> that.)
>>
>>  > [...] There have also been numerous other issues (many have already
>>  > been addressed) such as broken links, links to data which doesn't
>>  > exist or has wrong MIME type [...]  Perhaps even more unfortunate
>>  > is that sometimes, you can come across some good information in the
>>  > worg site, but finding that same information again at a latter date
>>  > is often extremely challenging.
>>
>> But that's not "Org styling", right?  Or am I confused about what
>> "styling" means?
>>
>> At any rate, I agree with your other examples, understand why the
>> styling (as I understand it) should be improved, and am no longer
>> worried about changes.  Thank you very much for your time.
>
> It isn't just about the styling - that is just one aspect and the one I
> planned to start with. However, styling and presentation will also be
> part of providing better links/navigation, which I think is also
> necessary to make exploration and discovery easier and more consistent.
> .

Can you give us an example/model of a site that does these things
better? I agree with your assessment, but feel that some kind of target
is needed.

TIA,
Leo


Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2023-01-05 Thread Leo Butler
On Mon, Jan 02 2023, Ihor Radchenko  wrote:

> Ihor Radchenko  writes:
>
>> Ihor Radchenko  writes:
>>
>>>> There is a race condition between writing the contents of the graphics
>>>> file to disk and emacs checking the file size. My guess is that this is
>>>> causing the problem (and that the same failure applies for emacs-2{6,7},
>>>> since only the emacs-28 reports the exact test failure).
>>>
>>> Maybe we can just add several `sleep-for' calls to the test?
>>
>> I just did this. Let's see if CI errs again.
>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=e5c45358a
>
> Apparently, `sleep-for' 1 second was not enough, and I decided to remove
> checking file size completely.

Hello Ihor,

Is there an environment variable that could be used to determine is the
tests are being run on sourcehut? This would let us cut out that test on
sourcehut, while still keeping it elsewhere.

>
> Upon doing this, another failure popped up. This time, it looks like an
> actual Elisp issue:
>
> https://builds.sr.ht/~bzg/job/914954
> 2 unexpected results:
>FAILED  ob-octave/graphics-file  ((should-not (get-buffer "*Org-Babel
>Error Output*")) :form (get-buffer "*Org-Babel Error Output*") :value
>#) 
>FAILED  ob-octave/graphics-file-space  ((should-not (get-buffer
>"*Org-Babel Error Output*")) :form (get-buffer "*Org-Babel Error
>Output*") :value #) 
>
> As you can see *Org-Babel Error Output* buffer does not exist when
> running the test.
>
> Leo, could you please take a look?

An earlier test is creating that *Org Babel Error Output* buffer. That
is killed on the first test, before the test is actually run. But
GET-BUFFER behaves in an undocumented way: it returns a non-nil value,
#. To remedy that, I have wrapped the calls in
BUFFER-LIVE-P.

See the attached patch.

Leo

From b84f2f50b88fe6da3dcca3d751f6d75f7177ddaf Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Thu, 5 Jan 2023 13:53:44 -0600
Subject: [PATCH] test-ob-octave.el: wrap get-buffer in buffer-live-p

* testing/lisp/test-ob-octave.el (ob-octave/graphics-file):
(ob-octave/graphics-file-session):
(ob-octave/graphics-file-space): Wrap GET-BUFFER in BUFFER-LIVE-P.
This ensures that a killed buffer does not cause an incorrect failure
of a test.

Link: https://orgmode.org/list/87bknh5nva.fsf@localhost
---
 testing/lisp/test-ob-octave.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index 4e9fea97b..0b8ecea3b 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -79,7 +79,7 @@ sombrero;
   (org-babel-execute-src-block)
   (should (search-forward (format "[[file:%s]]" file) nil nil))
   (should (file-readable-p file))
-  (should-not (get-buffer "*Org-Babel Error Output*")))
+  (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*"
   ;; clean-up
   (delete-file file)
   (when (get-buffer "*Org-Babel Error Output*")
@@ -99,7 +99,7 @@ sombrero;
   (should (get-buffer "*Inferior Octave*"))
   (should (search-forward (format "[[file:%s]]" file) nil nil))
   (should (file-readable-p file))
-  (should-not (get-buffer "*Org-Babel Error Output*")))
+  (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*"
   ;; clean-up
   (delete-file file)
   (let (kill-buffer-query-functions kill-buffer-hook)
@@ -119,7 +119,7 @@ sombrero;
   (org-babel-execute-src-block)
   (should (search-forward (format "[[file:%s]]" file) nil nil))
   (should (file-readable-p file))
-  (should-not (get-buffer "*Org-Babel Error Output*")))
+  (should-not (buffer-live-p (get-buffer "*Org-Babel Error Output*"
   ;; clean-up
   (delete-file file)
   (when (get-buffer "*Org-Babel Error Output*")
-- 
2.39.0



Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2022-12-22 Thread Leo Butler
On Wed, Dec 21 2022, Ihor Radchenko  wrote:

> Ihor Radchenko  writes:
>
>>> Upon confirming the FSF copyright assignment, I have applied the patch
>>> onto bugfix.
>>> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=01c0ebee2
>>
>> Your patch appears to not work in some environments:
>>
>> https://builds.sr.ht/~bzg/job/906710
>>
>> Any ideas?
>
> Note that the tests are failing only partially. The graphics file does
> get created, but it has 0 size for some reason. Maybe something to do
> with non-graphical CI environment.

There is a race condition between writing the contents of the graphics
file to disk and emacs checking the file size. My guess is that this is
causing the problem (and that the same failure applies for emacs-2{6,7},
since only the emacs-28 reports the exact test failure).

>
> I disabled the tests for the time being until we figure out what is
> going on.
>
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a29103a78

That's pretty crude. Here are a couple thoughts:

- Is there a way to detect that the tests are running in this CI
  environment? We could use that to skip the file-size test selectively.
- Alternatively, we could remove the file-size test entirely.

Either option seems better than not running the tests at all.

Leo


Re: [BUG] exporting links with underscores

2022-12-18 Thread Leo Butler
On Sat, Dec 17 2022, Mike Gauland  wrote:

> On 17/12/22 11:32, Leo Butler wrote:
>> Org version is 9.5.2; emacs version is 27.1.
>>
>> The manual does not indicate that underscores need to be escaped in
>> links (and they can't be, as far as I can tell). The latex and html
>> exporters interpret them as the start of a subscript.
>>
>> Leo
>>
> By default underscore is treated that way--see the "Subscripts and 
> Superscripts" section of the manual 
> (https://orgmode.org/manual/Subscripts-and-Superscripts.html).

Thanks, I was looking at the section on links.

>
> Set the '^' option to 'nil' to get the behaviour you're after:
>
> #+OPTIONS: toc:nil num:nil ^:nil
>
> If you want a subscript anywhere, you can get that by using curly braces 
> (e.g., ex_{ample}).

Thanks for the tip and my apologies for the noise.

Best,
Leo


[BUG] exporting links with underscores

2022-12-16 Thread Leo Butler
Org version is 9.5.2; emacs version is 27.1.

The manual does not indicate that underscores need to be escaped in
links (and they can't be, as far as I can tell). The latex and html
exporters interpret them as the start of a subscript.

Leo

#+AUTHOR: Leo Butler
#+TITLE: Bug in processing underscores in links
#+OPTIONS: toc:nil num:nil

* Description

The link =[[mailto:ex_am...@ex.com][ex_ample]]= is expected to export
to =\href{mailto:ex_am...@ex.com}{ex_ample}= but instead, we get
[[mailto:ex_am...@ex.com][ex_ample]] exports to (in latex): =\href{mailto:ex\_am...@ex.com}{ex\textsubscript{ample}}=

Note that a similar issue is seen with the HTML export.

* Reproduction

Export this file: =C-c C-e l p=.


Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2022-11-15 Thread Leo Butler
On Mon, Nov 14 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> The amended patch is attached. Thanks for your helpful feedback.
>
> Thanks for the patch!
> It looks good, and the tests are passing. However, there is a side effect
> leaving testing/examples/octave-workspace file after running the tests.
>
> Can something be done about this?

Yes, sorry about that, I should have caught that while testing the
patch. the amended patch (attached) prevents Octave from dumping a core
file when running the :session test.

Best,
Leo

From 386c9c2f65730459bdc69b2e0b0b76e22e32dbc9 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 8 Nov 2022 13:31:47 -0600
Subject: [PATCH] prevent error in Octave process, add tests, update test docs

* lisp/ob-octave.el (org-babel-execute:octave):

  -Ensure that the special Octave variable `ans' is bound when
  GFX-FILE is non-nil.  The glue code in
  ORG-BABEL-OCTAVE-WRAPPER-METHOD causes Octave to exit with a
  non-zero exit code when `ans' is not bound.

  -Change format control string to %S from %s.  Ensure the graphics
  filename is quoted.  If it is not, Octave may create a mis-named
  file or fail entirely.

* testing/examples/ob-octave-test.org:

  Update the Graphical tests section:
  -put in the correct headers;
  -add a remark about where to find each test.

* testing/lisp/test-ob-octave.el:

  Add the three tests ob-octave/graphics-file,
  ob-octave/graphics-file-session and ob-octave/graphics-file-space.

  -ob-octave/graphics-file: The first test verifies that the first bug
  identified above is fixed; it also verifies that graphics file
  creation works correctly for scripting.

  -ob-octave/graphics-file-session: The second test verifies graphics
  file creation works correctly for sessions.  The Octave command
  `crash_dumps_octave_core(0)' is included to prevent the creation of
  a core file (`octave-workspace').

  -ob-octave/graphics-file-space: The third test verifies that a
  graphics filename with a space in it is created correctly.

Thanks to Ihor Radchenko for helpful feedback.
Ref: https://list.orgmode.org/8735asbtfe.fsf@localhost/T/#u
---
 lisp/ob-octave.el   |  2 +-
 testing/examples/ob-octave-test.org | 12 +-
 testing/lisp/test-ob-octave.el  | 65 +
 3 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 55926b789..1cb0e70b5 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -91,7 +91,7 @@ end")
  (list
   "set (0, \"defaultfigurevisible\", \"off\");"
   full-body
-  (format "print -dpng %s" gfx-file))
+  (format "print -dpng %S\nans=%S" gfx-file gfx-file))
  "\n")
 		full-body)
 		  result-type matlabp)))
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
index 9839d637e..bc19051a1 100644
--- a/testing/examples/ob-octave-test.org
+++ b/testing/examples/ob-octave-test.org
@@ -46,10 +46,18 @@ ans = s
 
 
 * Graphical tests
-#+begin_src octave :results graphics :file chart.png
+
+Graphics file.  This test is performed by =ob-octave/graphics-file= in =testing/lisp/test-ob-octave.el=.
+#+begin_src octave :results file graphics :file sombrero.png
+sombrero;
+#+end_src
+
+Graphics file in a session.  This test is performed by =ob-octave/graphics-file-session= in =testing/lisp/test-ob-octave.el=.
+#+begin_src octave :session :results graphics file :file sombrero.png
 sombrero;
 #+end_src
 
-#+begin_src octave :session
+Graphics file with a space in name.  This test is performed by =ob-octave/graphics-file-space= in =testing/lisp/test-ob-octave.el=.
+#+begin_src octave :results graphics file :file sombrero hat.png
 sombrero;
 #+end_src
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index 78ce10214..57f40d00b 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -64,4 +64,69 @@
 (org-babel-next-src-block 5)
 (should (equal nil (org-babel-execute-src-block)
 
+(ert-deftest ob-octave/graphics-file ()
+  "Graphics file.  Test that link is correctly inserted and graphics file is created (and not empty).  Clean-up side-effects."
+  ;; In case a prior test left the Error Output buffer hanging around.
+  (when (get-buffer "*Org-Babel Error Output*")
+(kill-buffer "*Org-Babel Error Output*"))
+  (let ((file (make-temp-file "test-ob-octave-" nil ".png")))
+(unwind-protect
+(org-test-with-temp-text
+	(format "#+begin_src octave :results file graphics :file %s
+sombrero;
+#+end_src"
+		file)
+  (org-babel-execute-src-block)
+  (should (search-forward (format "[[file:%s]]" file) nil nil))
+  (should (file-readable-p file))
+  (should (> (file-attribute-size (file-attributes file)) 0))
+

Re: [PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2022-11-09 Thread Leo Butler
Ihor, see below.

On Wed, Nov 09 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> Ihor,
>> Thanks for your feeback and the pointer. I have revised the tests and
>> attach the revised patch.
>
> Thanks!
>
> Note that your patch is over 15LOC, which exceeds legally allowed
> contribution size for people without copyright assignment.
>
> Would you be interested to sign the copyright assignment form and send
> it to FSF? See https://orgmode.org/worg/org-contribute.html#copyright
> for details. The process usually takes a few days on FSF side (they are
> obliged to reply within 5 working days).

Yes, I have done that. I did the paperwork about 10 years ago, but I
cannot find it and, except for my name, all other details have changed.

>
> Below are some comments.
>
>> * testing/lisp/test-ob-octave.el:
>>
>>   Add the tests ob-octave/graphics-file and
>>   ob-octave/graphics-file-session. The first test verifies that the
>
> Please use double space "  " between sentences. See
> https://orgmode.org/worg/org-contribute.html#commit-messages

Done.

>
>> -  (format "print -dpng %s" gfx-file))
>> +  (format "print -dpng %s\nans=%S" gfx-file 
>> gfx-file))
>
> Is there any reason why %S but not %s?

That is a good point. Both should be %S. This change is part of the
modified patch (and an extra test).

>
>>  * Graphical tests
>> -#+begin_src octave :results graphics :file chart.png
>> +
>> +Graphics file. This test is performed by =ob-octave/graphics-file= in 
>> =testing/lisp/test-ob-octave.el=.
>
> By convention, we use double space in distributed Org files and ~code~
> for symbol markup. See doc/Documentation_Standards.org.
>
> (It is not strictly necessary here, but would be nice to be consistent)
>

Done.

>> +  (org-babel-execute-src-block)
>> +  (should (search-forward (format "[[file:%s]]" file) nil nil))
>> +  (should (file-readable-p file))
>> +  (should (let ((size (nth 7 (file-attributes file
>
> It would be more clear to use `file-attribute-size' instead of `nth'.

Thanks. Done.

>
>> +(> size 0)))
>> +  (should (not (get-buffer "*Org-Babel Error Output*"
>
> `should-not' would be a bit more succinct.

Thanks. Done.

>
>> +  (should (let ((size (nth 7 (file-attributes file
>> +(> size 0)))
>> +  (should (not (get-buffer "*Org-Babel Error Output*"
>
> See the previous comment.

Done.

The amended patch is attached. Thanks for your helpful feedback.

Leo

From 3d0a083f11a2b4f395c730a04ca243dda4a3a4e3 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 8 Nov 2022 13:31:47 -0600
Subject: [PATCH] prevent error in Octave process, add tests, update test docs

* lisp/ob-octave.el (org-babel-execute:octave):

  -Ensure that the special Octave variable `ans' is bound when
  GFX-FILE is non-nil.  The glue code in
  ORG-BABEL-OCTAVE-WRAPPER-METHOD causes Octave to exit with a
  non-zero exit code when `ans' is not bound.

  -Change format control string to %S from %s.  Ensure the graphics
  filename is quoted.  If it is not, Octave may create a mis-named
  file or fail entirely.

* testing/examples/ob-octave-test.org:

  Update the Graphical tests section:
  -put in the correct headers;
  -add a remark about where to find each test.

* testing/lisp/test-ob-octave.el:

  Add the three tests ob-octave/graphics-file,
  ob-octave/graphics-file-session and ob-octave/graphics-file-session.
  The first test verifies that the first bug identified above is
  fixed; it also verifies that graphics file creation works correctly
  for scripting.  The second test verifies graphics file creation
  works correctly for sessions.  The third test verifies that a
  graphics filename with a space in it is created correctly.

Thanks to Ihor Radchenko for helpful feedback.
Ref: https://list.orgmode.org/8735asbtfe.fsf@localhost/T/#u
---
 lisp/ob-octave.el   |  2 +-
 testing/examples/ob-octave-test.org | 12 +-
 testing/lisp/test-ob-octave.el  | 64 +
 3 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 55926b789..1cb0e70b5 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -91,7 +91,7 @@ end")
  (list
   "set (0, \"defaultfigurevisible\", \"off\");"
   full-body
-  (format "print -dpng %s" gfx-file))
+  (format "print -dpng %S\nans=%S" gfx-file gfx-file))
  "\n")
 		full-body)
 		  result-type matlabp)))
diff --git a/testing/examples/ob-octave-test.or

[PATCH] lisp/ob-octave.el, was [PATCH] rfc: using ert-deftest with side-effects

2022-11-08 Thread Leo Butler
On Tue, Nov 08 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> However, I would like feedback/suggestions on writing such a
>> test. Issues include:
>>
>> 1. how to clean up the side-effects, including changes in the test
>>buffer, filesystem and potentially creating an error buffer;
>
> As you did, we generally use unwind-protect. Also, we prefer putting
> temporary files into temporary directory.
>
> You can grep for `make-temp-file' and `delete-file' in tests. There are
> plenty of examples.
>
>> 2. the general absence of similar tests (except in test-ob.el,
>>test-ob/result-graphics-link-type-header-argument).
>> ...
>> I am unsure about 2. Is the absence of such tests because there is a
>> policy against them, or ...
>
> We have no such policy. In fact, many tests are making
> temporary files.

Ihor,
Thanks for your feeback and the pointer. I have revised the tests and
attach the revised patch.

Best regards,
Leo

From 84587bdbd705c2769d0f02398f1e38fe26ac0a98 Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Tue, 8 Nov 2022 13:31:47 -0600
Subject: [PATCH] prevent error in Octave process, add tests, update test docs

* lisp/ob-octave.el (org-babel-execute:octave):

  Ensure that the special Octave variable `ans' is bound when GFX-FILE
  is non-nil.  The glue code in ORG-BABEL-OCTAVE-WRAPPER-METHOD causes
  Octave to exit with a non-zero exit code when `ans' is not bound.

* testing/examples/ob-octave-test.org:

  Update the Graphical tests section:
  -put in the correct headers;
  -add a remark about where to find the test.

* testing/lisp/test-ob-octave.el:

  Add the tests ob-octave/graphics-file and
  ob-octave/graphics-file-session. The first test verifies that the
  bug identified above is fixed; it also verifies that graphics file
  creation works correctly for scripting. The second test verifies
  graphics file creation works correctly for sessions.
---
 lisp/ob-octave.el   |  2 +-
 testing/examples/ob-octave-test.org |  7 +++--
 testing/lisp/test-ob-octave.el  | 47 +
 3 files changed, 53 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 55926b789..f85b79fa2 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -91,7 +91,7 @@ end")
  (list
   "set (0, \"defaultfigurevisible\", \"off\");"
   full-body
-  (format "print -dpng %s" gfx-file))
+  (format "print -dpng %s\nans=%S" gfx-file gfx-file))
  "\n")
 		full-body)
 		  result-type matlabp)))
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
index 9839d637e..c0f04b7b9 100644
--- a/testing/examples/ob-octave-test.org
+++ b/testing/examples/ob-octave-test.org
@@ -46,10 +46,13 @@ ans = s
 
 
 * Graphical tests
-#+begin_src octave :results graphics :file chart.png
+
+Graphics file. This test is performed by =ob-octave/graphics-file= in =testing/lisp/test-ob-octave.el=.
+#+begin_src octave :results file graphics :file sombrero.png
 sombrero;
 #+end_src
 
-#+begin_src octave :session
+Graphics file in a session. This test is performed by =ob-octave/graphics-file-session= in =testing/lisp/test-ob-octave.el=.
+#+begin_src octave :session :results graphics file :file sombrero.png
 sombrero;
 #+end_src
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index 78ce10214..dc3782fd0 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -64,4 +64,51 @@
 (org-babel-next-src-block 5)
 (should (equal nil (org-babel-execute-src-block)
 
+(ert-deftest ob-octave/graphics-file ()
+  "Graphics file. Test that link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
+  ;; In case a prior test left the Error Output buffer hanging around.
+  (when (get-buffer "*Org-Babel Error Output*")
+(kill-buffer "*Org-Babel Error Output*"))
+  (let ((file (make-temp-file "test-ob-octave-" nil ".png")))
+(unwind-protect
+(org-test-with-temp-text
+	(format "#+begin_src octave :results file graphics :file %s
+sombrero;
+#+end_src"
+		file)
+  (org-babel-execute-src-block)
+  (should (search-forward (format "[[file:%s]]" file) nil nil))
+  (should (file-readable-p file))
+  (should (let ((size (nth 7 (file-attributes file
+(> size 0)))
+  (should (not (get-buffer "*Org-Babel Error Output*"
+  ;; clean-up
+  (delete-file file)
+  (when (get-buffer "*Org-Babel Error Output*")
+(kill-buffer "*Org-Babel Error Output*")
+
+(ert-deftest ob-octave/graphics-file-session ()
+  "Graphics file in a session. Test that session is started in *Infe

[PATCH] rfc: using ert-deftest with side-effects

2022-11-07 Thread Leo Butler
Hello,

I am patching a bug in ob-octave.el (see attachment) involving the
creation of graphics files. The bug itself is easy to fix: a single line
in ob-octave.el ensures the special variable `ans' is bound, to prevent
Octave from exiting with a non-zero exit code.

However, I would like feedback/suggestions on writing such a
test. Issues include:

1. how to clean up the side-effects, including changes in the test
   buffer, filesystem and potentially creating an error buffer;
2. the general absence of similar tests (except in test-ob.el,
   test-ob/result-graphics-link-type-header-argument).

To address 1., I have wrapped the tests in an `unwind-protect' form to
ensure clean-up code gets run. The ERT manual does not suggest much
beyond this. At the moment, when the test is run, clean-up is being done
whether the test fails or passes.

I am unsure about 2. Is the absence of such tests because there is a
policy against them, or ...

Leo

diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 55926b789..f85b79fa2 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -91,7 +91,7 @@ end")
  (list
   "set (0, \"defaultfigurevisible\", \"off\");"
   full-body
-  (format "print -dpng %s" gfx-file))
+  (format "print -dpng %s\nans=%S" gfx-file gfx-file))
  "\n")
 		full-body)
 		  result-type matlabp)))
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
index 9839d637e..0fc84bc26 100644
--- a/testing/examples/ob-octave-test.org
+++ b/testing/examples/ob-octave-test.org
@@ -46,10 +46,16 @@ ans = s
 
 
 * Graphical tests
-#+begin_src octave :results graphics :file chart.png
+  :PROPERTIES:
+  :ID:   b8b1d6a0-b7f6-49bd-8cb0-0c74f737332f
+  :END:
+
+Graphics file
+#+begin_src octave :results file graphics :file sombrero.png
 sombrero;
 #+end_src
 
+Graphics session
 #+begin_src octave :session
 sombrero;
 #+end_src
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index 78ce10214..bdc9befef 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -64,4 +64,22 @@
 (org-babel-next-src-block 5)
 (should (equal nil (org-babel-execute-src-block)
 
+(ert-deftest ob-octave/graphics-file ()
+  "Graphics file. Test that link is correctly inserted and graphics file is created (and not empty). Clean-up side-effects."
+  (org-test-at-id "b8b1d6a0-b7f6-49bd-8cb0-0c74f737332f"
+(org-babel-next-src-block)
+(org-babel-execute-src-block)
+(unwind-protect
+(prog1
+(and (should (search-forward "[[file:sombrero.png]]" nil nil))
+ (should (file-readable-p "sombrero.png"))
+ (should (let ((size (nth 7 (file-attributes "sombrero.png"
+   (> size 0)))
+ (should (not (get-buffer "*Org-Babel Error Output*")
+  ;; clean-up
+  (delete-file "sombrero.png")
+  (when (get-buffer "*Org-Babel Error Output*")
+(kill-buffer "*Org-Babel Error Output*"))
+  (revert-buffer t t
+
 (provide 'test-ob-octave)


Re: [PATCH] Re: Maxima code blocks does not work in windows revisited

2022-11-07 Thread Leo Butler
On Sun, Nov 06 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>> I do not have a Windows machine to test and not motivated enough to
>>> try Emacs in wine.
>>
>> Max, a minor modification of the test you sent earlier shows that when
>> system-type is ms-dos, the placement does not matter (the command-line
>> is the same); but for gnu/linux, placement matters and Eric is right
>> (the command-lines are not the same and the dollar sign needs to be
>> escaped).
>>
>> I have attached a patch that puts the dollar sign in the right place for
>> both. The existing tests pass when running 'make test'.
>
> Thanks for your contribution!
> Applied onto main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=9abf1b5167e94291eee7c1400277ed55993106f9
>
> You are now also listed as an Org mode contributor.
> https://git.sr.ht/~bzg/worg/commit/8750cbeccf4283be5ec7078f635f8328b2cbee09

Thanks, Ihor.
Leo


Re: [BUG] ob-doc-maxima.org and ob-maxima.el

2022-11-07 Thread Leo Butler
On Sat, Nov 05 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>> I believe the attached patch fixes all the problems that you saw with
>> the previous versions.
>
> Thanks!
> Applied onto master.
> https://git.sr.ht/~bzg/worg/commit/c1440ba5f98634adf08209631d305c1814fb7f9a

Thanks, Ihor. I can see the new page already.

https://orgmode.org/worg//org-contrib/babel/languages/ob-doc-maxima.html

Best,
Leo


Re: [BUG] ob-doc-maxima.org and ob-maxima.el

2022-11-04 Thread Leo Butler
On Fri, Nov 04 2022, Ihor Radchenko  wrote:

>> +#+RESULTS: 3d-maxima
>> +[[https://orgmode.org/worg/org-contrib/babel/languages/images/maxima-3d.png]]
>> +
>
> I am a bit confused here. Did you hand-craft the results?

I did, based on what I see in ob-doc-octave.org. In the present patch
(attached), I have left the results alone.

>   
>> -#+NAME: solve-maxima
>> +#+NAME: tex-maxima
>>  #+HEADER: :exports results
>>  #+BEGIN_SRC maxima :results raw
>>tex(exp(-x)/x);
>>  #+END_SRC
>
> Please make #+RESULTS a separate paragraph. It may otherwise not be
> correctly recognized.

Ok, I have done this in the attached patch.

>
> Let's move the ob-maxima changes and discussion about graphics to a
> separate thread.

Ok.

I believe the attached patch fixes all the problems that you saw with
the previous versions.

Leo

From a4db0ed4af22e43e817ebca110872e7ee5222c2d Mon Sep 17 00:00:00 2001
From: Leo Butler 
Date: Fri, 4 Nov 2022 15:23:27 -0500
Subject: [PATCH] org-contrib/babel/languages/ob-doc-maxima.org: correct docs

* include the results of test-maxima and solve-maxima examples;
* correct the :results header of graphics example;
* rename the tex example to tex-maxima and include the results;
* add an empty line before each #+results: as suggested by Ihor.

Ref: https://list.orgmode.org/87k04b5qyf.fsf@localhost/T/#t
---
 org-contrib/babel/languages/ob-doc-maxima.org | 32 +++
 1 file changed, 25 insertions(+), 7 deletions(-)

diff --git a/org-contrib/babel/languages/ob-doc-maxima.org b/org-contrib/babel/languages/ob-doc-maxima.org
index 810c9ef4..a6b403dc 100644
--- a/org-contrib/babel/languages/ob-doc-maxima.org
+++ b/org-contrib/babel/languages/ob-doc-maxima.org
@@ -111,7 +111,9 @@ powers of 12, where the powers are passed with a variable.
   print(12^x);
 #+end_src
 
-#+results: test-maxima
+HTML export of the result:
+
+#+RESULTS: test-maxima
 : 26.06280316745402
 
 ** Solver
@@ -137,6 +139,14 @@ Of course, =maxima= is more than a calculator.
   print(solution);
 #+end_src
 
+HTML export of the result:
+
+#+RESULTS: solve-maxima
+: solve: solution:
+: x = - 4
+:  x = 4
+: [%t1, %t2] 
+
 ** 3D plots
 With =gnuplot= installed (4.0 or higher), 3D graphics are possible.
 This example is from [[http://maxima.sourceforge.net/maxima-gnuplot.html][a tutorial on the maxima/gnuplot interface]].
@@ -145,7 +155,7 @@ This example is from [[http://maxima.sourceforge.net/maxima-gnuplot.html][a tuto
 ,#+name: 3d-maxima
 ,#+header: :file images/maxima-3d.png
 ,#+header: :exports results
-,#+header: :results graphics
+,#+header: :results file graphics
 ,#+begin_src maxima 
   programmode: false;
   plot3d(atan(-x^2+y^3/4),[x,-4,4],[y,-4,4],[grid,50,50],[gnuplot_pm3d,true]);
@@ -154,35 +164,43 @@ This example is from [[http://maxima.sourceforge.net/maxima-gnuplot.html][a tuto
 
 #+name: 3d-maxima
 #+header: :file images/maxima-3d.png
-#+header: :results graphics
 #+header: :exports results
+#+header: :results file graphics
 #+begin_src maxima 
   programmode: false;
   plot3d(atan(-x^2+y^3/4),[x,-4,4],[y,-4,4],[grid,50,50],[gnuplot_pm3d,true]);
 #+end_src
 
-#+results: 3d-maxima
+HTML export of the Maxima code block result:
+
+#+RESULTS: 3d-maxima
 [[file:images/maxima-3d.png]]
 
+
 ** Inline Display of Maxima LaTeX Output
   [[http://maxima.sourceforge.net/][Maxima]] code can be evaluated and displayed inline in Org mode
   through babel [fn:1] as in the example below, based on RS initial
   example.
 
 #+begin_example
-,#+NAME: solve-maxima
-,#+HEADER: :exports none
+,#+NAME: tex-maxima
+,#+HEADER: :exports results
 ,#+BEGIN_SRC maxima :results raw
   tex(exp(-x)/x);
 ,#+END_SRC
 #+end_example
 
-#+NAME: solve-maxima
+#+NAME: tex-maxima
 #+HEADER: :exports results
 #+BEGIN_SRC maxima :results raw
   tex(exp(-x)/x);
 #+END_SRC
 
+HTML export of the result:
+
+#+RESULTS: tex-maxima
+$${{e^ {- x }}\over{x}}$$
+
 *** Toggle inline display of latex code
 Latex code in org mode can be displayed inline by 'C-c C-x
 C-l'. To remove the inline display 'C-c C-c' is used. This is
-- 
2.35.1



Re: Clarification on :results file vs. :results graphics file

2022-11-04 Thread Leo Butler
On Fri, Nov 04 2022, Ihor Radchenko  wrote:

> Leo Butler  writes:
>
>>>> @@ -145,7 +151,7 @@ This example is from 
>>>> [[http://maxima.sourceforge.net/maxima-gnuplot.html][a tuto
>>>>  ,#+name: 3d-maxima
>>>>  ,#+header: :file images/maxima-3d.png
>>>>  ,#+header: :exports results
>>>> -,#+header: :results graphics
>>>> +,#+header: :results graphics file
>>>
>>> Using graphics together with file does not make sense.
>>
>> Ok. But I am not sure the code agrees with you. In ob-core.el,
>>  ...
>>
>> Is it, in your opinion, ob-maxima's responsibility to add "graphics" to
>> :result-params when :results file is specified?
>
> No.

Thank you for correcting yourself and me. I had arrived at the same
conclusion and was going to retract that `patch' to ob-maxima.el.

Leo


  1   2   3   4   5   6   7   >