Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code blocks inside tables for org-mode

Tags:

org-mode

I love org-tables, I use them to document all sorts of things. I was now documenting some one-liners for Nix (after reading this excellent guide by Domen Kožar, given at this year's EuroPython), and I got into some problems:

* NIX Oneliners

|------------------+---------------------------------------------+------------------------------|
| DATE             | COMMAND                                     | DESCRIPTION                  |
|------------------+---------------------------------------------+------------------------------|
| <2014-07-24 Thu> | curl -L http://git.io/nix-install.sh § bash | Install nix                  |
| <2014-07-24 Thu> | nix-env -qaP § grep python3-3               | search for python3-3 package |
|------------------+---------------------------------------------+------------------------------|

The commands should be actually curl -L http://git.io/nix-install.sh | bash and nix-env -qaP | grep python3-3, but since the pipe breaks the whole thing, I need to use another character (in this case §)

My question is: how can I tell org-mode to take a text in a region literally? I do not want to use a escape sequence for the pipe, because I want to do easy copy-paste to the shell from my documentation.

What I want is something similar to the code block in markdown:

`do | not | care | about | this`

Does this exist in org-mode?

EDIT

Event using = this | trick = does not work inside tables.

like image 600
blueFast Avatar asked Jul 24 '14 12:07

blueFast


1 Answers

You cannot do that: you cannot escape the "|" character in a table entry: the best you can do is replace it with something that looks like it instead. There have been several questions on the ML about this and the best answer seems to be the Unicode character at #xa6 (¦) - see e.g. this message and the enclosing thread.

However, you can store links to code blocks in the table. Inside a code block, you can have arbitrary code so there is no problem with special characters there, and as a bonus, you can execute the code blocks.

Something like this:

* Table of code blocks

| Name | Code block |
|------+------------|
| foo  | [[foo][foo]]        |
| bar  | [[bar][bar]]        |


#+name: foo
#+begin_src bash
echo "Foo"
#+end_src

#+RESULTS: foo
: Foo

#+name: bar
#+begin_src bash
echo "Bar"
#+end_src
like image 98
NickD Avatar answered Oct 20 '22 22:10

NickD