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"
+:   |  ^
+:   |  ;
+:10 | return 0;
+:   | ~~
+: [ Babel evaluation exited with code 1 

Re: org-persist - not wanted.

2023-12-20 Thread Ihor Radchenko
Colin Baxter  writes:

> I find a file called "gc-lock.eld" has been deposited un-requested and
> un-wanted in ~/.emacs.d/org-persist.
>
> I had thought I had disabled org-persist with the following
>
> --8<---cut here---start->8---
> (setq org-persist-disable-when-emacs-Q t)
> (defun me/advice--org-persist (old-fn  args)
>  (let (user-init-file)
>   (apply old-fn args)))
> (advice-add 'org-persist-write :around #'me/advice--org-persist)
> (advice-add 'org-persist-read :around #'me/advice--org-persist)
> (advice-add 'org-persist-gc :around #'me/advice--org-persist)
> --8<---cut here---end--->8---
>
> This had worked fine until today. How do I now stop org-persist
> depositing this - and maybe other -files. I do not want them.

Please note that disabling org-persist is not officially supported and
can be broken any moment. Like it appeared to happen for you after
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=5a5ec1b320512f5e97f72668abc13447567fdd35

In future, I may implement some options to, say, set org-persist save
the data alongside with .org file. For now, it is a centralized place.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



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



Re: org-persist - not wanted.

2023-12-20 Thread Colin Baxter
> Colin Baxter  writes:

> I find a file called "gc-lock.eld" has been deposited un-requested
> and un-wanted in ~/.emacs.d/org-persist.

> I had thought I had disabled org-persist with the following

> (setq org-persist-disable-when-emacs-Q t) (defun
> me/advice--org-persist (old-fn  args) (let (user-init-file)
> (apply old-fn args))) (advice-add 'org-persist-write :around
> #'me/advice--org-persist) (advice-add 'org-persist-read :around
> #'me/advice--org-persist) (advice-add 'org-persist-gc :around
> #'me/advice--org-persist)

> This had worked fine until today. How do I now stop org-persist
> depositing this - and maybe other -files. I do not want them.

> I am using emacs-30.0.50 and Org mode version 9.7-pre
> (release_9.6.13-998-g571186).

 Ignore my rant. I cannot reproduce this so it looks to be spurious. 




org-persist - not wanted.

2023-12-20 Thread Colin Baxter


I find a file called "gc-lock.eld" has been deposited un-requested and
un-wanted in ~/.emacs.d/org-persist.

I had thought I had disabled org-persist with the following

--8<---cut here---start->8---
(setq org-persist-disable-when-emacs-Q t)
(defun me/advice--org-persist (old-fn  args)
 (let (user-init-file)
  (apply old-fn args)))
(advice-add 'org-persist-write :around #'me/advice--org-persist)
(advice-add 'org-persist-read :around #'me/advice--org-persist)
(advice-add 'org-persist-gc :around #'me/advice--org-persist)
--8<---cut here---end--->8---

This had worked fine until today. How do I now stop org-persist
depositing this - and maybe other -files. I do not want them.

I am using emacs-30.0.50 and Org mode version 9.7-pre
(release_9.6.13-998-g571186).

Best wishes, Colin Baxter.