0

The context

Lately, I've been writing the configurations of all the programs I use in Org Mode because of some features that improves the readibility of such files.

The code block below shows a part of my =mpv= configuration that I wrote in Org Mode

The following mappings zoom in and zoom out, respectively, in different magnitudes.

#+begin_src text :tangle input.conf
i add video-zoom 0.25
I add video-zoom 0.5
Alt+i add video-zoom 0.75
Alt+I add video-zoom 1
ctrl+i add video-zoom 1.25
ctrl+I add video-zoom 1.5
ctrl+Alt+i add video-zoom 1.75
ctrl+Alt+I add video-zoom 2
#+end_src

#+begin_src text :tangle input.conf
o add video-zoom -0.25
O add video-zoom -0.5
Alt+o add video-zoom -0.75
Alt+O add video-zoom -1
ctrl+o add video-zoom -1.25
ctrl+O add video-zoom -1.5
ctrl+Alt+o add video-zoom -1.75
ctrl+Alt+O add video-zoom -2
#+end_src 

As seen above, =add= is being repeated in each. Because of that reason, I decided to store =add= in a code block and call that code block by using a =noweb= reference.

#+NAME: zoom-operation
#+begin_src text
add
#+end_src

#+begin_src text :noweb yes :tangle input.conf
i <<zoom-operation>> video-zoom 0.25
I <<zoom-operation>> video-zoom 0.5
Alt+i <<zoom-operation>> video-zoom 0.75
Alt+I <<zoom-operation>> video-zoom 1
ctrl+i <<zoom-operation>> video-zoom 1.25
ctrl+I <<zoom-operation>> video-zoom 1.5
ctrl+Alt+i <<zoom-operation>> video-zoom 1.75
ctrl+Alt+I <<zoom-operation>> video-zoom 2
#+end_src

#+begin_src text :noweb yes :tangle input.conf
o <<zoom-operation>> video-zoom -0.25
O <<zoom-operation>> video-zoom -0.5
Alt+o <<zoom-operation>> video-zoom -0.75
Alt+O <<zoom-operation>> video-zoom -1
ctrl+o <<zoom-operation>> video-zoom -1.25
ctrl+O <<zoom-operation>> video-zoom -1.5
ctrl+Alt+o <<zoom-operation>> video-zoom -1.75
ctrl+Alt+O <<zoom-operation>> video-zoom -2
#+end_src

The problem

Now, what I'm trying to do is to obtain the different zoom magnitudes in a code block and create a =noweb= ref to the results of that code block. The problem is that, as far as I know, it is just possible to obtain an entire #+RESULTS block but not specific parts of it which implies that I need to create a +RESULTS block for each zoom magnitude which I don't want to do.

Let's suppose I obtain the different magnitudes with the following code block

#+NAME: zoom-magnitude
#+begin_src python
for i in range(1, 9):
  print(i/10)
#+end_src

#+RESULTS: zoom-magnitude
#+begin_example
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
#+end_example

I want to be able to obtain specific lines of the #+RESULTS block so that my configuration would look like

#+begin_src text :noweb yes :tangle input.conf
i <<zoom-operation>> video-zoom <<zoom-magnitude()[0]>>
I <<zoom-operation>> video-zoom <<zoom-magnitude()[1]>>
Alt+i <<zoom-operation>> video-zoom <<zoom-magnitude()[2]>>
Alt+I <<zoom-operation>> video-zoom <<zoom-magnitude()[3]>>
ctrl+i <<zoom-operation>> video-zoom <<zoom-magnitude()[4]>>
ctrl+I <<zoom-operation>> video-zoom <<zoom-magnitude()[5]>>
ctrl+Alt+i <<zoom-operation>> video-zoom <<zoom-magnitude()[6]>>
ctrl+Alt+I <<zoom-operation>> video-zoom <<zoom-magnitude()[7]>>
#+end_src

#+begin_src text :noweb yes :tangle input.conf
o <<zoom-operation>> video-zoom -<<zoom-magnitude()[0]>>
O <<zoom-operation>> video-zoom -<<zoom-magnitude()[1]>>
Alt+o <<zoom-operation>> video-zoom -<<zoom-magnitude()[2]>>
Alt+O <<zoom-operation>> video-zoom -<<zoom-magnitude()[3]>>
ctrl+o <<zoom-operation>> video-zoom -<<zoom-magnitude()[4]>>
ctrl+O <<zoom-operation>> video-zoom -<<zoom-magnitude()[5]>>
ctrl+Alt+o <<zoom-operation>> video-zoom -<<zoom-magnitude()[6]>>
ctrl+Alt+O <<zoom-operation>> video-zoom -<<zoom-magnitude()[7]>>
#+end_src

The syntax shown above (i.e. <<zoom-magnitude()[i]>>) doesn't work. It is just an example in order to show what I'm trying to accomplish.

The questionn

How can I obtain an specific line of a #+RESULTS block in a noweb reference?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.