emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
@ 2024-04-27 10:05 Greg Minshall
  2024-04-28 12:29 ` Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2024-04-27 10:05 UTC (permalink / raw)
  To: emacs-orgmode

Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

     https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.
------------------------------------------------------------------------

hi.  the following org block describes a problem i noticed.  possibly
the fix is simply issuing an appropriate error message (and aborting the
process of tangling.

thanks for looking at this when you have a chance.  and, apologies if
this is a FAQ.

cheers, Greg

#+begin_src org
  ,** introduction

  this is to show an oddity -- a bug, or a security feature? -- in
  tangling a source code block that has a variable (=:var=) header
  argument.

  if the variable =org-babel-load-languages= includes the source type of
  the code block (e.g., "shell", "python", etc.), the variable will be
  set in the tangled file.  if =org-babel-load-languages= does *not*
  include that source type, the variable will be unset in the tangled
  file.  without any error message.

  (note that in a running emacs, *removing* elements from
  =org-babel-load-languages= doesn't seem to cause this problem to
  appear.  maybe this is because the relevant "ob-..." files have
  already been loaded?)

  to see this, first *tangle* this file, to get works.el, fails.el, and
  variable.sh, and then evaluate this code block:

  ,#+name: DemonstrateBehavior
  ,#+begin_src sh :results output
    ./works.el
    echo -n "works.el: "
    ./variable.sh
    ./fails.el
    echo -n "fails.el: "
    ./variable.sh
  ,#+end_src

  ,#+RESULTS: DemonstrateBehavior
  : works.el: 2.4
  : fails.el: 

  notice that after running fails.el, the 2.4 disappears.


  ,** this is the test code and blocks

  here is the variable to be included.
  ,#+name: variable
  | 2.4 |

  and, the code block that includes that variable
  ,#+begin_src sh :var variable=variable :shebang #!/bin/sh :tangle variable.sh
    echo "${variable}"
  ,#+end_src

  tangling with this works
  ,#+begin_src elisp :tangle works.el :shebang "#!/usr/bin/env -S emacs --script"
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((emacs-lisp . t)
       (shell . t)))
    (org-babel-tangle-file "maybe.org")
  ,#+end_src

  tangling with this fails (notice the absence of =(shell . t)=)
  ,#+begin_src elisp :tangle fails.el :shebang "#!/usr/bin/env -S emacs --script"
    (org-babel-do-load-languages
     'org-babel-load-languages
     '((emacs-lisp . t)))
    (org-babel-tangle-file "maybe.org")
  ,#+end_src
#+end_src


Emacs  : GNU Emacs 30.0.50 (build 14, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.18.0)
 of 2023-11-20
Package: Org mode version 9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-27 10:05 [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)] Greg Minshall
@ 2024-04-28 12:29 ` Ihor Radchenko
  2024-04-28 18:54   ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ihor Radchenko @ 2024-04-28 12:29 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

>   here is the variable to be included.
>   ,#+name: variable
>   | 2.4 |
>
>   and, the code block that includes that variable
>   ,#+begin_src sh :var variable=variable :shebang #!/bin/sh :tangle variable.sh
>     echo "${variable}"
>   ,#+end_src

Confirmed.

This is because Org mode currently cannot distinguish between babel
backends that simply do not support variable assignments and babel
backends that are not loaded.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-28 12:29 ` Ihor Radchenko
@ 2024-04-28 18:54   ` Greg Minshall
  2024-04-29 12:48     ` Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2024-04-28 18:54 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

hi, Ihor,

thanks for looking at this.

> This is because Org mode currently cannot distinguish between babel
> backends that simply do not support variable assignments and babel
> backends that are not loaded.

currently, is it possible to see well enough what is going on to
generate an error and abort the tangle?

(off the top of my head i would think a `:var` in either of the
situations you describe might be described as an error -- albeit a user
error.)

cheers, Greg


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-28 18:54   ` Greg Minshall
@ 2024-04-29 12:48     ` Ihor Radchenko
  2024-04-30  7:38       ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ihor Radchenko @ 2024-04-29 12:48 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

>> This is because Org mode currently cannot distinguish between babel
>> backends that simply do not support variable assignments and babel
>> backends that are not loaded.
>
> currently, is it possible to see well enough what is going on to
> generate an error and abort the tangle?
>
> (off the top of my head i would think a `:var` in either of the
> situations you describe might be described as an error -- albeit a user
> error.)

Not necessarily.

Consider something like


#+property: header-args :var common_variable = "foo"

#+begin_src elisp
(message "variable is %S" common_variable)
#+end_src

#+RESULTS:
: variable is "foo"

#+begin_src python :result value
return f"variable is \"{common_variable}\""
#+end_src

#+RESULTS:
: variable is "foo"

Below, ob-dot does not implement variable assignments.
Throwing an error here would be unexpected.

#+begin_src dot :file foo.png
digraph G {
a -> b
}
#+end_src

#+RESULTS:
[[attachment:foo.png]]

We may, theoretically, only throw an error when the variable assignments
are not inherited, but that will create even more confusion - sometimes,
the error will be thrown, and sometimes not.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-29 12:48     ` Ihor Radchenko
@ 2024-04-30  7:38       ` Greg Minshall
  2024-04-30 10:33         ` Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2024-04-30  7:38 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor,

thanks again.

> #+property: header-args :var common_variable = "foo"

ah, hierarchical :var's.  i didn't realize such existed.  of course,
then, you're right.

a dream might be something like ":var none" to allow the dot source code
block to indicate it wasn't expecting any ":var" anyway.  but, i guess
then one would want to allow picking and choosing:
----
: #+header: :var =common_variable
----
or some such to disable *that*?

maybe, anyway, a warning message *might* be nice -- "failing" (as the
user may see it) silently can be hard to debug.

cheers, Greg


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-30  7:38       ` Greg Minshall
@ 2024-04-30 10:33         ` Ihor Radchenko
  2024-05-01 17:41           ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ihor Radchenko @ 2024-04-30 10:33 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

> a dream might be something like ":var none" to allow the dot source code
> block to indicate it wasn't expecting any ":var" anyway.  but, i guess
> then one would want to allow picking and choosing:
> ----
> : #+header: :var =common_variable
> ----
> or some such to disable *that*?

This can be implemented, but not if the purpose is working around the
tangling issue you are experiencing.

I do not recall many people asking for such a feature.

> maybe, anyway, a warning message *might* be nice -- "failing" (as the
> user may see it) silently can be hard to debug.

It might be. But the real fix should be adding babel API to allow
backends declaring the list of supported features.
Such API is relatively easy to implement.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-04-30 10:33         ` Ihor Radchenko
@ 2024-05-01 17:41           ` Greg Minshall
  2024-05-01 17:47             ` Ihor Radchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Greg Minshall @ 2024-05-01 17:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor,

> > or some such to disable *that*?
> 
> I do not recall many people asking for such a feature.

no, i don't either.  :)

> It might be. But the real fix should be adding babel API to allow
> backends declaring the list of supported features.
> Such API is relatively easy to implement.

with such a fix, then if a language is not loaded that could accept a
:var, either an error would be thrown, or maybe the language would be
loaded?  (i would vote for the error, but ...)

either way that would be great.

cheers, Greg


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-05-01 17:41           ` Greg Minshall
@ 2024-05-01 17:47             ` Ihor Radchenko
  2024-05-02 13:01               ` Greg Minshall
  0 siblings, 1 reply; 9+ messages in thread
From: Ihor Radchenko @ 2024-05-01 17:47 UTC (permalink / raw)
  To: Greg Minshall; +Cc: emacs-orgmode

Greg Minshall <minshall@umich.edu> writes:

> with such a fix, then if a language is not loaded that could accept a
> :var, either an error would be thrown, or maybe the language would be
> loaded?  (i would vote for the error, but ...)

The idea is to use something like `org-cite-try-load-processor', but for
babel backends. Then, if the backend does not define variable expansion
method, do nothing. If the backend is not loaded, throw an error/warning
(maybe depending on a customization).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)]
  2024-05-01 17:47             ` Ihor Radchenko
@ 2024-05-02 13:01               ` Greg Minshall
  0 siblings, 0 replies; 9+ messages in thread
From: Greg Minshall @ 2024-05-02 13:01 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor,

> Then, if the backend does not define variable expansion method, do
> nothing. If the backend is not loaded, throw an error/warning (maybe
> depending on a customization).

great.  thanks.  if customizable, i'd vote to default with an error.


then, for what it's worth, my experience led me to write some code for a
command line program (basically, an elisp script) to tangle files.

if anyone is interested in playing/using it, that'd be great.  the idea
is to figure out what languages are needed by walking the source code
blocks, keeping track of languages, then set `org-babel-load-languages`
appropriately, and tangle the file.
----
https://sr.ht/~minshall/org-cli-tangle/
----

cheers, Greg


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-05-02 13:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-27 10:05 [BUG] oddity tangling src_blk with :var [9.7-pre (release_9.6.26-1368-g1ae978 @ /home/minshall/.emacs.d/straight/build/org/)] Greg Minshall
2024-04-28 12:29 ` Ihor Radchenko
2024-04-28 18:54   ` Greg Minshall
2024-04-29 12:48     ` Ihor Radchenko
2024-04-30  7:38       ` Greg Minshall
2024-04-30 10:33         ` Ihor Radchenko
2024-05-01 17:41           ` Greg Minshall
2024-05-01 17:47             ` Ihor Radchenko
2024-05-02 13:01               ` Greg Minshall

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).