Search code examples
emacsorg-mode

Emacs Org Mode: use result of src block in another src block


A got src block

#+NAME: gdt
#+BEGIN_SRC ruby :var date="14-05-2018"
  require 'active_support/all'
  table_header_days = []
  today = Date.parse(date)

  0.upto(7 - today.wday) do |n|
    table_header_days.push("#{(today + n.days).day} #{(today + n.days).strftime('%a')}")
  end

  [['', table_header_days, ''].flatten, nil, ['row 1'], ['row 2'], ['row 3'], ['row 4']]
#+END_SRC

It outputs like table

#+RESULTS: gdt
|       | 14 Mon | 15 Tue | 16 Wed | 17 Thu | 18 Fri | 19 Sat | 20 Sun |   |
|-------+--------+--------+--------+--------+--------+--------+--------+---|
| row 1 |        |        |        |        |        |        |        |   |
| row 2 |        |        |        |        |        |        |        |   |
| row 3 |        |        |        |        |        |        |        |   |
| row 4 |        |        |        |        |        |        |        |   |

I want to use this src block in other src block

#+BEGIN_SRC ruby :noweb eval :exports table
<<gdt("14-05-2018")>>
#+END_SRC

I expect to get table but got an error

-:3: syntax error, unexpected tIDENTIFIER, expecting ')'
i" "19 Sat" "20 Sun" "") hline ("row 1") ("row 2") ("row 3")
                              ^
-:3: syntax error, unexpected '(', expecting ')'
"20 Sun" "") hline ("row 1") ("row 2") ("row 3") ("row 4"))
                              ^
-:3: syntax error, unexpected '(', expecting keyword_end
") hline ("row 1") ("row 2") ("row 3") ("row 4"))
                              ^
-:3: syntax error, unexpected ')', expecting keyword_end
 ("row 1") ("row 2") ("row 3") ("row 4"))
                              ^
-:3: syntax error, unexpected ')', expecting keyword_end
 ("row 2") ("row 3") ("row 4"))
                              ^
-:6: syntax error, unexpected end-of-input, expecting keyword_end

What I did wrong?


Solution

  • The only thing you can use inside the <<...>> markers in a noweb "call" is a code ID, i.e. the name of the block that is to replace it. In particular, you cannot pass arguments like this <<gdt("arg")>>.

    Try changing your second block to this:

    #+BEGIN_SRC ruby :noweb eval :exports table :var date="14-05-2018"
    <<gdt>>
    #+END_SRC