Re: [PATCH] Re: [BUG] ob-shell: :shebang changes interpretation of :cmdline

2024-04-23 Thread Ihor Radchenko
Matt  writes:

> Whether this is a solution, in part, depends on the perennial problem of 
> shell blocks: knowing what's wrong means knowing what's right.
>
> The proposed solution assumes we intend to parse the characters following 
> :cmdline as space delimited and grouped by quotes.  However, AFAICT, the 
> parsing issue makes this solution ambiguous.
>
> Thoughts?

Manually parsing the shell arguments is calling for trouble.
Especially when the arguments involve shell-specific escapes like
:cmdline 1\ 2\ 3

Since escape characters may vary from shell to shell, it is not a good
idea to parse the arguments on Elisp side. We should better leave this
job to the shell.

I propose the attached patch.

>From e0cf4161b4af05c513ba402ee9625851853c9465 Mon Sep 17 00:00:00 2001
Message-ID: 
From: Ihor Radchenko 
Date: Tue, 23 Apr 2024 13:22:22 +0300
Subject: [PATCH] ob-shell: Pass :cmdline arguments consistently regardless of
 :shebang

* lisp/ob-shell.el (org-babel-sh-evaluate): When invoking script file
generated from the code block, consistently use
 -c   command line, even when
:shebang is header argument is provided.  The previous approach with
  call caused differences in how shell
parsed the provided command line arguments.

Reported-by: Max Nikulin 
Link: https://orgmode.org/list/18f01342a2f.124ad27612732529.8693431365849276...@excalamus.com
---
 lisp/ob-shell.el | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 35d9e9376..30b3ea322 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -322,14 +322,12 @@ (defun org-babel-sh-evaluate (session body &optional params stdin cmdline)
 	  (with-temp-buffer
 (with-connection-local-variables
  (apply #'process-file
-(if shebang (file-local-name script-file)
-  shell-file-name)
+shell-file-name
 		stdin-file
 (current-buffer)
 nil
-(if shebang (when cmdline (list cmdline))
-  (list shell-command-switch
-(concat (file-local-name script-file)  " " cmdline)
+(list shell-command-switch
+  (concat (file-local-name script-file)  " " cmdline
 		(buffer-string
 	   (session			; session evaluation
 (if async
-- 
2.44.0


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


Re: [PATCH] Re: [BUG] ob-shell: :shebang changes interpretation of :cmdline

2024-04-23 Thread Max Nikulin

On 21/04/2024 22:09, Matt wrote:

The proposed solution assumes we intend to parse the characters
following :cmdline as space delimited and grouped by quotes.  However,
AFAICT, the parsing issue makes this solution ambiguous.


Matt, I am sorry, but I do not agree with your proposal. I do not think 
that `split-string-and-unquote' will solve all issues.


Certainly issues with formatting of output should be treated separately.

I figured out there is at least one more issue. Consider

#+property: header-args:bash :results verbatim
#+begin_src bash :cmdline $LANG :shebang #!/bin/bash
  printf '"%s" ' "$0" "$@"
  printf '\n'
  tr '\000' '\n' First line is argv as it is represented for a script, next lines are 
exec arguments at lower level (actual executable may be obtained from

"readlink /proc/$$/exe")

Notice that in the former case "$LANG" is passed literally, but in the 
latter it is expanded. I am in favor of dropping `shell-command-switch' 
in the latter case to pass arguments literally in both cases.


I think, it would be more consistent with :var to specify multiple 
arguments using elisp lists

#+header: :cmdline '("first 1" "second 2")

However looking wider, I do not like that :cmdline for ob-shell has 
different meaning than for other languages, see e.g. ob-sql. Only for 
shell this parameter is treated as arguments of a *script*. In other 
cases :cmdline is used to specify arguments of *interpreter* and I think 
ob-shell should follow this convention.


Actually script arguments (and :stdin) might be applied to python and at 
least some other languages, so support of this feature should be moved 
from ob-shell to common org-babel code.


My point:
- header arguments should have as close as possible meaning across 
various languages.
- withing ob-shell variation of ways to execute a script should be 
minimized either some parameters (:cmdline, :shebang, :stdin) are 
specified or not.


Finally a note on tests

+(ert-deftest test-cmdline-alone-and-with-shebang-have-same-result ()
+  "Pass arguments to a block.  Don't use shebang.  Then use
+shebang set to the same language as the block.  The result should
+be the same."
+  (should (equal
+   (org-test-with-temp-text
+   "#+begin_src bash :cmdline 1 2 3
+echo \"$1\"
+
+#+end_src"
+ (org-babel-execute-src-block))
+   (org-test-with-temp-text
+   "#+begin_src bash :cmdline 1 2 3 :shebang #!/usr/bin/env bash
+echo \"$1\"
+
+#+end_src"
+ (org-babel-execute-src-block)
I believe, that starting point of the discussion is that the results 
should be same and decision what is more correct is the result of the 
discussion. Unit tests should check both cases independently and should 
fix particular treatment of arguments.





Re: [FR] Please add custom command variable to org-latex-footnote-refere

2024-04-23 Thread Ihor Radchenko
Alexander Gogl  writes:

> you mean like this?

Not really, but I now squashed the previous patches manually.
Applied, onto main, with amendments.
I fixed some wording in the etc/NEWS entry, added description of %s%s to
the docstring, and removed BEHAVIOR=t from the new option - all other
similar options have BEHAVIOR=nil, so let's keep things consistent.

https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=46e13c3eb

You are also listed as an Org contributor now.
https://git.sr.ht/~bzg/worg/commit/ec8a1007

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



Re: columnview dynamic block - different time summing behaviour for EFFORT and CLOCKSUM

2024-04-23 Thread Ihor Radchenko
Alexander Adolf  writes:

> Ihor Radchenko  writes:
>
>> [...]
>> Calling `org-columns--clean-item' is a must to create a valid table.
>
> True.
>
> Additionally, it would seem advisable to call `org-quote-vert' on the
> data, too, as `org-columns--clean-item' does not take care of vertical
> bars? This is done in a previous step in `org-columns--capture-view',
> however, so that the vertical bars get converted to "\vert" before the
> formatting function gets called.
>
> `org-link-heading-search-string', and `org-link-make-string' (both
> called from the formatting function _after_ `org-columns--clean-item')
> OTOH take care of the link's path and description parts being
> appropriate for a link.

It would make sense then to include `org-quote-vert' call into
`org-columns--clean-item' then.

> Kindly find updated patches below. I hope to have succeeded in
> addressing all your comments; that was my intention at least.

Thanks!

>  (defun org-columns--capture-view (maxlevel match skip-empty exclude-tags 
> format local)
>"Get the column view of the current buffer.
>...
> +When LOCAL is non-nil, only capture headings in current subtree.  When
> +LINK is non-nil, item headlines will be linked to their origins.

Looks like you removed the LINK parameter, but forgot to remove its
description from the docstring.
  
> +(let ((search (org-link-heading-search-string 
> raw)))
> +  (org-link-make-string
> +   (if (not (buffer-file-name)) search
> + (format "file:%s::%s" (buffer-file-name) 
> search))
> +   cleaned))

This will unconditionally generate file: links, even when the dynamic
block only refers to headings in the same buffer. The clock tables do
use internal links when appropriate (see `org-clock-get-table-data').

I am attaching a patch containing test case making sure that internal
links are generated when appropriate. The test case is failing with
the latest version of your patch.

If you can, please add some more tests like mine checking
`org-columns--clean-item'.

>From 3961072d80883aef5da21d8d6ba10213778ff32f Mon Sep 17 00:00:00 2001
Message-ID: <3961072d80883aef5da21d8d6ba10213778ff32f.1713871396.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Tue, 23 Apr 2024 14:22:44 +0300
Subject: [PATCH] org-colview: Add test for the new :link parameter

* testing/lisp/test-org-colview.el (test-org-colview/dblock): New
test case.
---
 testing/lisp/test-org-colview.el | 12 
 1 file changed, 12 insertions(+)

diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el
index 7f0aa763e..872a61753 100644
--- a/testing/lisp/test-org-colview.el
+++ b/testing/lisp/test-org-colview.el
@@ -1422,6 +1422,18 @@ (ert-deftest test-org-colview/dblock ()
 "* H\n:PROPERTIES:\n:A: 1\n:END:\n#+BEGIN: columnview\n#+END:"
   (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
   (buffer-substring-no-properties (point) (point-max)
+  ;; Test `:link' parameter.
+  (should
+   (equal
+"#+BEGIN: columnview
+| ITEM |
+|--|
+| [[*H][H]]|
+#+END:"
+(org-test-with-temp-text
+"* H\n#+BEGIN: columnview\n#+END:"
+  (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
+  (buffer-substring-no-properties (point) (point-max)
   ;; Test column widths.
   (should
(equal
-- 
2.44.0


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


Re: `org-emphasize' missing in the manual

2024-04-23 Thread Ihor Radchenko
Arash Esbati  writes:

> Thanks for your response.  I'm not really familiar with Org development,
> but I hope the attached change fits the bill.  Please feel free to
> adjust when necessary.

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

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



Re: [POLL] Should we enable or disable automatic tag alignment by default everywhere

2024-04-23 Thread Ihor Radchenko
Max Nikulin  writes:

> There should be a way to align tags for a specific heading even when 
> `org-auto-align-tags' is nil.
>
>> -   (org-align-tags)
>> +   (when org-auto-align-tags (org-align-tags))

I can convert org-align-tags into a command.

> Instead of repetitive changes I would consider either checking 
> `org-auto-align-tags' inside `org-align-tags' or introducing a macro.

It will not do much good:

1. If we check inside `org-align-tags', it will be a breaking API
   change and the command name will no longer be intuitive.

2. If we introduce a macro/function, it will be something like
   (org-align-tags-maybe) - not much different from
   (when org-auto-align-tags (org-align-tags))

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



Re: Can we add PLOT to org-element-multiple-keywords?

2024-04-23 Thread Ihor Radchenko
Jeff Trull  writes:

> I notice that multiple #+PLOT lines before a table will be coalesced and
> handled as one. However, this is
> accomplished through specific code in org-plot.el that does a reverse
> search through the buffer for
> additional lines. org-element has a built-in mechanism for this,
> org-element-multiple-keywords. It seems
> like it would be useful to add PLOT to it. Can that be done? If not, is
> there a way to temporarily add it for
> an exporter (i.e. after the export is launched but before the buffer is
> parsed)?

Yes, it can be done.

However, in addition to changing the parser, we should also make use of
the change in org-plot itself.

I tried to do this, and noticed that `org-plot/gnuplot' promises to
parse #+TABLE options _after_ the table as well. Affiliated keywords are
of no help then.

Further, I reviewed the two calls to `org-plot/collect-options' in
org-table.el and noticed that the second call is no longer doing the
right thing of scanning #+PLOT lines after the table - since commit
ac3148ef8 (by Timothy):

org-plot: Don't move point when plotting

* lisp/org-plot.el (org-plot/gnuplot): Expanding the `save-excursion'
block to include `org-plot/goto-nearest-table` prevents the current
point from being moved, and doesn't affect the rest of the function.

Timothy, may you please take a look?

We may drop support for the #+PLOT lines after the table - they are not
really documented in our manual. Though it will technically be a
breaking change, so I am not 100% sure.

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



Re: `org-emphasize' missing in the manual

2024-04-23 Thread Arash Esbati
Ihor Radchenko  writes:

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

Thanks for considering this.

Best, Arash



Re: Is there a way to set options *programatically* ?

2024-04-23 Thread Ihor Radchenko
Emmanuel Charpentier  writes:

> I'd like to create a function able to set some options, namely
>
> - `#+options: tex:`{t|dvipng|imagemagick}
>
> - `#+export-file-name:`
>
> I have been unable to find a *documented* way to do that from `elacs-lisp`.
>
> I *think* that an `org` source block could place those options in the buffer, 
> but I can't find a way to reliably trigger a "setup refreshment" of these 
> options from `emacs-lisp`.
>
> Any ideas ?

You can set `org-export-with-latex' variable value - it is a counterpart
of tex: option. See 13.2 Export Settings section of the manual.

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



Re: [POLL] Should we enable or disable automatic tag alignment by default everywhere

2024-04-23 Thread Max Nikulin

On 23/04/2024 18:47, Ihor Radchenko wrote:

Max Nikulin writes:


There should be a way to align tags for a specific heading even when
`org-auto-align-tags' is nil.


I can convert org-align-tags into a command.


I would prefer to have C-u C-c C-q (`org-set-tags-command') applied just 
to the current heading (or to active region). Unfortunately it would be 
a breaking change. I have no idea how to make (org-align-tags) call 
easier than (org-align-tags 'all) without breaking changes. Otherwise it 
would be inconsistent and M-: (org-align-tags) can be used in the last 
resort.





Re: columnview dynamic block - different time summing behaviour for EFFORT and CLOCKSUM

2024-04-23 Thread Alexander Adolf
Ihor Radchenko  writes:

> [...]
> It would make sense then to include `org-quote-vert' call into
> `org-columns--clean-item' then.

Good point. I'll move the call to `org-quote-vert' there.

> [...]
>>  (defun org-columns--capture-view (maxlevel match skip-empty exclude-tags 
>> format local)
>>"Get the column view of the current buffer.
>>...
>> +When LOCAL is non-nil, only capture headings in current subtree.  When
>> +LINK is non-nil, item headlines will be linked to their origins.
>
> Looks like you removed the LINK parameter, but forgot to remove its
> description from the docstring.

Ah, ashes to my head for overlooking this. Well spotted!

>> +   (let ((search (org-link-heading-search-string 
>> raw)))
>> + (org-link-make-string
>> +  (if (not (buffer-file-name)) search
>> +(format "file:%s::%s" (buffer-file-name) 
>> search))
>> +  cleaned))
>
> This will unconditionally generate file: links, even when the dynamic
> block only refers to headings in the same buffer. The clock tables do
> use internal links when appropriate (see `org-clock-get-table-data').

Um, actually it does exactly the same as `org-clock-get-table-data'
(from where I borrowed the code snippet): it generates file: links in
buffers visiting files, and local links in buffers not visiting any
file.

Perhaps you were looking at a test case in which
`org-clock-get-table-data' gets called in an Org buffer that is not
visiting any file?

> [...]
> I am attaching a patch containing test case making sure that internal
> links are generated when appropriate. The test case is failing with
> the latest version of your patch.
>
> If you can, please add some more tests like mine checking
> `org-columns--clean-item'.
> [...]

Thanks for the springboard hint to get started with adding tests, which
I'm happy to do, of course.

Is there any way for me to run a specific subset of the tests only, for
instance "make test colview", or similar?


Many thanks and cheers,

  --alexander



Re: columnview dynamic block - different time summing behaviour for EFFORT and CLOCKSUM

2024-04-23 Thread Ihor Radchenko
Alexander Adolf  writes:

>>> +  (let ((search (org-link-heading-search-string 
>>> raw)))
>>> +(org-link-make-string
>>> + (if (not (buffer-file-name)) search
>>> +   (format "file:%s::%s" (buffer-file-name) 
>>> search))
>>> + cleaned))
>>
>> This will unconditionally generate file: links, even when the dynamic
>> block only refers to headings in the same buffer. The clock tables do
>> use internal links when appropriate (see `org-clock-get-table-data').
>
> Um, actually it does exactly the same as `org-clock-get-table-data'
> (from where I borrowed the code snippet): it generates file: links in
> buffers visiting files, and local links in buffers not visiting any
> file.
>
> Perhaps you were looking at a test case in which
> `org-clock-get-table-data' gets called in an Org buffer that is not
> visiting any file?

Nope. I was writing a test case (the one I shared) and noticed that
file: links are generated. Then, I misread what org-clock does.
You don't need to do anything other than adjusting the test example I
shared to use file: links.

>> If you can, please add some more tests like mine checking
>> `org-columns--clean-item'.
>> [...]
>
> Thanks for the springboard hint to get started with adding tests, which
> I'm happy to do, of course.
>
> Is there any way for me to run a specific subset of the tests only, for
> instance "make test colview", or similar?

make test BTEST_RE="test-org-colview/dblock"
# the same, but do not re-compile Org mode
make test-dirty BTEST_RE="test-org-colview/dblock"

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



[PATCH] ob-lua: Support all types and multiple values in results

2024-04-23 Thread Rudolf Adamkovič
* etc/ORG-NEWS
(New and changed options): Describe the new option
'org-babel-lua-multiple-values-separator'.
(New features): Describe the main change, as per the title of this
commit message.
* lisp/ob-lua.el
(org-babel-lua-multiple-values-separator): Enable the user to
customize the string that separates the individual values in
multi-valued returns.
(org-babel-lua-wrapper-method): Support all Lua types and multi-valued
returns.  Further, do not pretty-print tables with one or more
extraneous newline characters.
(org-babel-lua-pp-wrapper-method): Remove in favor of the new, more
general 'org-babel-lua-wrapper-method'.
(org-babel-lua-evaluate-external-process): Adapt for the new
'org-babel-lua-wrapper-method'.
* testing/lisp/test-ob-lua.el
(test-ob-lua/colnames-yes-header-argument-pp):
(test-ob-lua/colnames-nil-header-argument):
(test-ob-lua/colnames-no-header-argument): Stop expecting extraneous
newlines, now that the pretty printer does not output them.
(test-ob-lua/types): Test nil, boolean, number, string, and table
results.
(test-ob-lua/multiple-values): Test multi-valued results.
---
 etc/ORG-NEWS| 17 +
 lisp/ob-lua.el  | 73 ++---
 testing/lisp/test-ob-lua.el | 48 ++--
 3 files changed, 105 insertions(+), 33 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index fc2ff9e00..696f46e53 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -637,6 +637,11 @@ link when storing any type of external link type in an Org 
file, not
 just =id:= links.
 
 ** New and changed options
+*** ~org-babel-lua-multiple-values-separator~
+
+The string that separates the values of multi-valued results returned
+from Lua code blocks.
+
 *** =.avif= images are now recognized in ~org-html-inline-image-rules~
 
 In =ox-html=, =.avif= image links are now inlined by default.
@@ -1012,6 +1017,18 @@ The option can be customized either by
 2. by setting the file local keyword =LATEX_FOOTNOTE_COMMAND=
 
 ** New features
+*** =ob-lua=: Support all types and multiple values in results
+
+Lua code blocks can now return values of any type and can also return
+multiple values.  Previously, values of certain types were incorrectly
+converted to the empty string =""=, which broke HTML export for inline
+code blocks, and multiple values were incorrectly concatenated, where
+~return 1, 2, 3~ was evaluated as =123=.
+
+Multiple values are comma-separated by default, so that they work well
+with inline code blocks.  To change the string used as the separator,
+customize ~org-babel-lua-multiple-values-separator~.
+
 *** ~org-paste-subtree~ now handles =C-u= and =C-u C-u= prefix arguments 
specially
 
 With =C-u= prefix argument, force inserting a sibling heading below.
diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index b241fccdc..92a1b3344 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -81,6 +81,13 @@ This will typically be `lua-mode'."
   :package-version '(Org . "8.3")
   :type 'symbol)
 
+(defcustom org-babel-lua-multiple-values-separator ", "
+  "Separate multiple values with this string."
+  :group 'org-babel
+  :version "30.0"
+  :package-version '(Org . "9.7")
+  :type 'string)
+
 (defun org-babel-execute:lua (body params)
   "Execute Lua BODY according to PARAMS.
 This function is called by `org-babel-execute-src-block'."
@@ -251,41 +258,47 @@ function main()
 %s
 end
 
-fd=io.open(\"%s\", \"w\")
-fd:write( main() )
-fd:close()")
-(defvar org-babel-lua-pp-wrapper-method
-  "
--- table to string
-function t2s(t, indent)
+function dump(it, indent)
if indent == nil then
-  indent = \"\"
+  indent = ''
end
-   if type(t) == \"table\" then
-  ts = \"\"
-  for k,v in pairs(t) do
- if type(v) == \"table\" then
-ts = ts .. indent .. t2s(k,indent .. \"  \") .. \" = \\n\" ..
-   t2s(v, indent .. \"  \")
- else
-ts = ts .. indent .. t2s(k,indent .. \"  \") .. \" = \" ..
-   t2s(v, indent .. \"  \") .. \"\\n\"
+   if type(it) == 'table' and %s then
+  local count = 0
+  for _ in pairs(it) do
+ count = count + 1
+  end
+  local result = ''
+  if #indent ~= 0 then
+ result = result .. '\\n'
+  end
+  for key, value in pairs(it) do
+ result = result
+.. indent
+.. dump(key)
+.. ' = '
+.. dump(value, indent .. '  ')
+ count = count - 1
+ if count ~= 0 then
+result = result .. '\\n'
  end
   end
-  return ts
+  return result
else
-  return tostring(t)
+  return tostring(it)
end
 end
 
-
-function main()
-%s
+function combine(...)
+  local result = {}
+  for index = 1, select('#', ...) do
+result[index] = dump(select(index, ...))
+  end
+  return table.concat(result, '%s')
 end
 
-fd=io.open(\"%s\", \"w\")
-fd:write(t2s(main()))
-fd:close()")
+output = io.open('%s', 'w')
+output:write(combine(main()))
+output:cl

Re: [PATCH] ob-lua: Support all types and multiple values in results

2024-04-23 Thread Rudolf Adamkovič
Rudolf Adamkovič  writes:

> +Lua code blocks can now return values of any type and can also return
> +multiple values.  Previously, values of certain types were incorrectly
> +converted to the empty string =""=, which broke HTML export for inline
> +code blocks, and multiple values were incorrectly concatenated, where
> +~return 1, 2, 3~ was evaluated as =123=.

Also,

  #+BEGIN_SRC lua
  return {1, 2, 3}
  #+END_SRC

previously crashed, as did

  #+BEGIN_SRC lua
  function divide()
 error("oops")
 return divident / divisor
  end
  return pcall(oops)
  #+END_SRC

All that works now, with no more crashes.

P.S. #1

We still have an old bug where

  src_lua{return string.match("A {B} C", "%b{}")}

is misjudged to be a table:

  org-babel-insert-result: Inline error: list result cannot be used

P.S. #2

I did not update any session-related code.

Currently,

  #+BEGIN_SRC lua :session x
  print 1
  #+END_SRC

gives

  ... Sessions currently not supported, work in progress

This is also documented in the header

  ;; Requirements:
  ;; for session support, lua-mode is needed.
  ;; [...]
  ;; However, sessions are not yet working.

This half-finished session support should be removed, IMHO.

If someone needs it and are willing to finish it, they can still dig it
up it in the history.  That is what VC is for, after all.

As of now, all that session-related dead code only pollutes the file,
making it harder to change, as it drifts out of sync...

Rudy
-- 
"All you have to do is write one true sentence.  Write the truest
sentence that you know."  --- Ernest Miller Hemingway (1899-1961)

Rudolf Adamkovič  [he/him]
Studenohorská 25, 84103 Bratislava, Slovakia, European Union



Re: [PATCH] Re: [BUG] ob-shell: :shebang changes interpretation of :cmdline

2024-04-23 Thread Max Nikulin

On 23/04/2024 17:51, Max Nikulin wrote:
I am in favor of dropping `shell-command-switch' in the latter case to 
pass arguments literally in both cases.


Dropping "-c" may have side effects. Instead of :shebang, a source block 
may have shebang in the body


#+begin_src bash
#!/bin/bash -e
echo first; false; echo second
#+end_src

This shebang is ignored if the script is executed as
bash /tmp/script
and respected in the case of
bash -c /tmp/script
Shebang in the script body may be detected to run it as
/tmp/script
or
/bin/bash -e /tmp/script

To avoid interpretation of shell specials in script arguments when "-c" 
is used, it is possible to use a trick

bash -c /tmp/script ob-shell arg1 arg2 arg3
The -c option adds extra execve() call in comparison to
/tmp/script arg1 arg2 arg3
Perhaps it may be neglected.

It may be more tricky on Windows where shebangs are likely ignored even 
by bash. However I do not thing ob-shell is working on windows since 
`shell-command-switch' should be /c there instead of -c since default 
shell is cmd.exe.





[BUG] Exporting to text fails when there are broken links

2024-04-23 Thread Pablo Aguado

Org mode version 9.6.15

* CURRENT BEHAVIOR

Exporting to text fails when ~org-export-with-broken-links~ is set to ~mark~. 
[[help:org-export-with-broken-links]]

The following are minimal examples using source blocks in org. I'm using an 
LLM-generated function to call ~org-export-string-as~, but there might be an 
easier option with arguments and blocks. You can also replicate by calling 
~org-export-dispatch~ -> Export to plain text -> As ASCII buffer (or Latin1 or 
UTF-8).

#+begin_src elisp
  (defun org-src-to-text (block-name)
"Convert the content of a named Org source block to text."
(org-element-map (org-element-parse-buffer) 'src-block
  (lambda (src)
(when (string= block-name (org-element-property :name src))
  (let ((src-block (org-element-property :value src)))
(princ (org-export-string-as src-block 'ascii t)))
#+end_src

#+RESULTS:
: org-src-to-text


** broken-links:nil

#+NAME: source-broken-links-nil
#+begin_src org
,#+OPTIONS: broken-links:nil

,* Some title
  
1. This [[file:existing-file.org][link1]] is exported correctly to text.
2. This [[file:{filename}existing-file.org][link2]] is exported correctly 
to text.
3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported 
correctly to text.
4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to 
text.
5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported 
correctly to text.
#+end_src

#+begin_src elisp :results output
  (org-src-to-text "source-broken-links-nil")
#+end_src

This fails with =org-export-data: Unable to resolve link: 
"{filename}test-nonexistent-file.org"=


** source-broken-links-t

#+NAME: source-broken-links-t
#+begin_src org
  ,#+OPTIONS: broken-links:t

  ,* Some title

  1. This [[file:existing-file.org][link1]] is exported correctly to text.
  2. This [[file:{filename}existing-file.org][link2]] is exported correctly to 
text.
  3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported 
correctly to text.
  4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to 
text.
  5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported 
correctly to text.
#+end_src

#+RESULTS: source-broken-links-t

#+begin_src elisp :results output
  (org-src-to-text "source-broken-links-t")
#+end_src

#+RESULTS:
#+begin_example
,* Some title

1. This [link1] is exported correctly to text.
2. This [link2] is exported correctly to text.
3. This [link3] is exported correctly to text.
4. This [link4] is exported correctly to text.
5. This is NOT exported correctly to text.


[link1] 

[link2] 

[link3] 

[link4] 
#+end_example




** source-broken-links-mark

#+NAME: source-broken-links-mark
#+begin_src org
  ,#+OPTIONS: broken-links:mark

  ,* Some title

  1. This [[file:existing-file.org][link1]] is exported correctly to text.
  2. This [[file:{filename}existing-file.org][link2]] is exported correctly to 
text.
  3. This [[file:{filename}test-nonexistent-file.org][link3]] is exported 
correctly to text.
  4. This [[file:test-nonexistent-file.org][link4]] is exported correctly to 
text.
  5. This [[{filename}test-nonexistent-file.org][link5]] is NOT exported 
correctly to text.
#+end_src

#+begin_src elisp :results output
  (org-src-to-text "source-broken-links-mark")
#+end_src

#+RESULTS:
: [BROKEN LINK: {filename}test-nonexistent-file.org]


NOTE THAT ONLY THE BROKEN LINK IS SHOWN HERE! BUT NOT THE REST OF THE TEXT.



* EXPECTED BEHAVIOR

As with other backends (like ~html~), I'd expect the correctly exported text, 
not only the broken link.

#+begin_example
  ,* Some title

  1. This [link1] is exported correctly to text.
  2. This [link2] is exported correctly to text.
  3. This [link3] is exported correctly to text.
  4. This [link4] is exported correctly to text.
  5. This [BROKEN LINK: {filename}test-nonexistent-file.org]is NOT exported 
correctly to text.


  [link1] 

  [link2] 

  [link3] 

  [link4] 
#+end_example