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 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 <>= >> 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) >> >