emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: [feature request] The :pre header argument
Date: Fri, 19 Feb 2021 20:50:40 -0500	[thread overview]
Message-ID: <CAGxMbPYWCc57Cb6O+JbCJGZZzSZyw81WwvgFz6H_aU0YRKp3CQ@mail.gmail.com> (raw)
In-Reply-To: <CAGxMbPZ2TLiZSKEcFGxZzS-=MxWFcucy7_AXUgtjUOqmOk2eTg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4775 bytes --]

I've provided more relevant information on this feature request [[
https://codeberg.org/rdrg109/gists/src/branch/main/feature-request-pre-header-argument.org][here]].
Please consider reading that instead of the first message on this thread.

On Fri, 19 Feb 2021 at 08:33, Rodrigo Morales <moralesrodrigo1100@gmail.com>
wrote:

> You can read this message with proper formatting here (
> https://codeberg.org/rdrg109/gists/src/branch/main/the-pre-header-argument.org
> ).
>
> On Thu, 18 Feb 2021 at 16:52, Rodrigo Morales <
> moralesrodrigo1100@gmail.com> wrote:
>
>>
>> This message contains my thoughts on a feature request which I think
>> would be useful: The =:pre= header argument, it would be used to
>> execute a code block before the code block at point is executed. It
>> would be similar to the behavior of the =:post= header argument.
>>
>> Here's a simple example that shows how =:pre= could be used
>>
>> #+NAME: clean-path-experiments
>> #+begin_src dash
>> if [ ! -z "$my__experiments" ] && [ -d "$my__experiments" ]; then
>>   find ~/e -mindepth 1 -maxdepth 1 -exec rm -rf {} +
>> fi
>> #+end_src
>>
>> #+NAME: tree-command
>> #+begin_src dash
>> tree -a --noreport
>> #+end_src
>>
>> #+NAME: create-dir-for-minimal-reproducible-example
>> #+HEADER: :pre clean-path-experiments()
>> #+HEADER: :post tree-command()
>> #+begin_src python
>> import os
>>
>> [os.makedirs(_) for _ in ["a/foo", "a/bar", "b"]]
>> [os.mknod(_) for _ in ["a/1.txt", "a/2.txt", "a/foo/b.txt",
>> "a/bar/b.txt", "b/b.txt"]]
>> #+end_src
>>
>> #+RESULTS: create-dir-for-minimal-reproducible-example
>> #+begin_example
>> .
>> ├── a
>> │   ├── 1.txt
>> │   ├── 2.txt
>> │   ├── bar
>> │   │   └── b.txt
>> │   └── foo
>> │       └── b.txt
>> └── b
>>     └── b.txt
>> #+end_example
>>
>> I think that such header argument would be useful because of two
>> main reasons:
>>
>> * It would improve readability of code blocks by explicitly expressing
>> dependency
>>
>> By having a header argument for the sole purpose of expressing
>> dependencies between code blocks, the readability of header arguments
>> would be improved. Recall that it is currently possible to express
>> such dependency by calling a code block through a =:var <<name>>=
>> header argument but I think that =:var= header argument must only be
>> used for defining variables (be it from results obtained from
>> different code blocks or literals).
>>
>> The first code block shown below show the differences between using
>> =:var= and =:pre= for the same scenario. =first-code-block= uses the
>> =:var= header argument while the =second-code-block= uses the =:pre=
>> header argument.
>>
>> #+NAME: first-code-block
>> #+begin_src org
>> For our experimentation, let's start with an empty directory and let's
>> execute the first step.
>>
>> ,#+NAME: first-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :var e=clean-path-experiments
>> ,#+begin_src dash
>> touch first-step.txt
>> ,#+end_src
>>
>> We know execute the second step.
>>
>> ,#+NAME: second-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :var e=first-step
>> ,#+begin_src dash
>> touch second-step.txt
>> ,#+end_src
>>
>> Finally, we execute the third step.
>>
>> ,#+NAME: third-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :var e=second-step
>> ,#+begin_src dash
>> touch third-step.txt
>> ,#+end_src
>> #+end_src
>>
>> #+NAME: second-code-block
>> #+begin_src org
>> For our experimentation, let's start with an empty directory and let's
>> execute the first step.
>>
>> ,#+NAME: first-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :pre clean-path-experiments()
>> ,#+begin_src dash
>> touch first-step.txt
>> ,#+end_src
>>
>> We know execute the second step.
>>
>> ,#+NAME: second-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :pre first-step()
>> ,#+begin_src dash
>> touch second-step.txt
>> ,#+end_src
>>
>> Finally, we execute the third step.
>>
>> ,#+NAME: third-step
>> ,#+HEADER: :results silent
>> ,#+HEADER: :pre second-step()
>> ,#+begin_src dash
>> touch third-step.txt
>> ,#+end_src
>> #+end_src
>>
>> In my opinion, the second code block looks more readable than the
>> first one.
>>
>> * it would add importance to the =:post= header argument
>>
>> The =:post= header argument can be used in Org Mode 9.3 to execute a
>> given code block after the code block at point is executed; having a
>> header argument that does the opposite of the =:post= header argument
>> would give relevance to the =:post= header argument.
>>
>> --
>> Greetings,
>> Rodrigo Morales.
>>
>> IRC: rdrg109 (freenode)
>>
>

[-- Attachment #2: Type: text/html, Size: 5881 bytes --]

  reply	other threads:[~2021-02-20  1:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-18 21:48 Rodrigo Morales
2021-02-19 13:33 ` Rodrigo Morales
2021-02-20  1:50   ` Rodrigo Morales [this message]
2021-04-05  4:49     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGxMbPYWCc57Cb6O+JbCJGZZzSZyw81WwvgFz6H_aU0YRKp3CQ@mail.gmail.com \
    --to=moralesrodrigo1100@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [feature request] The :pre header argument' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this 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).