How do I generate source code from an org mode table? - emacs

I'm trying to figure out a way to move my i3wm configuration file to an org-mode file. I have a table with keybindings and what command they should execute, and I would like to generate the appropriate source code from it.
Example:
| Keybinding | Command | Action |
|-----------------------+----------------------+--------------------------|
| {{{mod}}} + Return | i3-sensible-terminal | Opens a new terminal |
| {{{mod}}} + Shift + q | kill | Kills the focused window |
should generate
bindsym {{{mod}}}+Return exec --no-startup-id i3-sensible-terminal ;; Opens a new Terminal
bindsym {{{mod}}}+Shift+q exec --no-startup-id kill ;; Kills the focused window
is such thing possible?

You can name the table and pass it as an argument to a source block and have the source block iterate over rows. Here's an implementation in python:
#+NAME: commands
| Keybinding | Command | Action |
|-----------------------+----------------------+--------------------------|
| {{{mod}}} + Return | i3-sensible-terminal | Opens a new terminal |
| {{{mod}}} + Shift + q | kill | Kills the focused window |
#+begin_src python :var cmds=commands :results output raw
for row in cmds:
print("bindsym {} exec --no-startup-id {} ;; {}".format(row[0].replace(' ', ''), row[1], row[2]))
#+end_src
Here I assumed that the spaces in the first column should be eliminated, rather than quoting the string, but you can easily modify that.
And here are the results of running the above source block:
#+RESULTS:
bindsym {{{mod}}}+Return exec --no-startup-id i3-sensible-terminal ;; Opens a new terminal
bindsym {{{mod}}}+Shift+q exec --no-startup-id kill ;; Kills the focused window

Related

complex canvas getting stuck in the middle

Setup:
Celery 4.1.0, broker=RabbitMQ 3.6.5, backend=Redis 3.2.5
Consider the following canvas:
celery worker -A worker.celeryapp:app -l info -Q default -c 2 -n defaultworker#%h -Ofair
#app.task(name='task_1',
bind=True,
base=MyConnectionHolderTask)
def task_1(self, feed_id, flow_id, **kwargs):
do_something()
task_1 = t_1.si(feed_id, flow_id)
.
.
task_13 = t_13.si(feed_id, flow_id)
(task_1 |
group((task_2 | group(task_3, task_4)),
task_5,
task_6,
task_7,
task_8) |
task_9 |
task_10 |
task_11 |
task_12 |
task_13).apply_async(link_error=unlock)
means I have chain of tasks which one of its tasks is a group of several tasks, and one of them is chain of size 2 (with latter task as group of 2).
Expected behavior
all task succeeded so expecting finish until task_13
Actual behavior
task_4 is the last to run. task_9 and the rest (10..13) doesn't run.
if i cancel the group of task_3 & task_4 it does work (till 13):
(task_1 |
group((task_2 | task_3 | task_4),
task_5,
task_6,
task_7,
task_8) |
task_9 |
task_10 |
task_11 |
task_12 |
task_13).apply_async(link_error=unlock)
Ref: Issue in github

org-mode latex export: wrap text around a table

I can make text wrap around images by adding
#+CAPTION: foo
#+ATTR_LATEX: :float wrap
[[./my_img.png]]
If I do the same to
#+CAPTION: bar
#+ATTR_LATEX: :float wrap
| a | b |
| c | d |
The table will stay centered in its own part of the document, the text being broken above and below it, not auto-flowing around it.
I also tried to do something like
#+CAPTION: baz
#+ATTR_LATEX: :environment wraptable :options {l}{5cm}
| a | b |
| c | d |
or using :position instead of :options, with no results.
Basically I want the table to export to
\begin{wraptable}{l}{5cm}
\begin{tabular}
....
\end{tabular}
\end{wraptable}
in the tex file. The arguments {r|l}{width} are mandatory, so simply #+begin_wraptable won't work either. Is there any way to do that from inside org-mode without manually fiddling with the final .tex?
You have to explicitly add the LaTeX-code for wraptable, using the :center attribute with no value removes the automatic insertion of \beginn{center} in the .tex-file.
#+LaTeX: \begin{wraptable}{r|l}{width}
#+ATTR_LATEX: :center
| A | B | C |
|--------+-------+-------|
| a | b | c |
#+LaTeX: \end{wraptable}

No borders in table in org-mode

This is how I wrote my table in org-mode:
| col1 | col2 | col3 |
|------+------+------|
| val1 | val2 | val3 |
| val4 | val5 | val6 |
This is the output I'm getting in org-export-as-pdf :
What I want is the borders for the table. The org-mode version I'm
using is 7.9.3f.
UPDATE:
With #+ATTR_LaTeX: align=|c|c|c|, I get the follwing table:
UPDATE:
Solved that using putting horizontal lines on top and below of the table using C-u C-c - and C-c - respectively.
If you want vertical lines, you need to specify it, hence something like:
#+ATTR_LaTeX: align=|c|c|c|
in your old version of Org mode, or:
#+ATTR_LaTeX: :align |c|c|c|
in Org mode 8.

Org mode spreadsheet programmatic remote references

I keep my budget in org-mode and have been pleased with how simple it is. The simplicity fails, however, as I am performing formulas on many cells; for instance, my year summary table that performs the same grab-and-calculate formulas for each month. I end up with a massive line in my +TBLFM. This would be dramatically shorter if I could programmatically pass arguments to the formula. I'm looking for something like this, but working:
| SEPT |
| #ERROR |
#+TBLFM: #2$1=remote(#1,$tf)
Elsewhere I have a table named SEPT and it has field named "tf". This function works if I replace "#1" with "SEPT" but this would cause me to need a new entry in the formula for every column.
Is there a way to get this working, where the table itself can specify what remote table to call (such as the SEPT in my example)?
Yes, you can't do this with built-in remote and you need to use org-table-get-remote-range. Hopefully this better suits your needs than the answer given by artscan (I used his/her example):
| testname1 | testname2 |
|-----------+-----------|
| 1 | 2 |
#+TBLFM: #2='(org-table-get-remote-range #<$0 (string ?# ?1 ?$ ?1))
#+TBLNAME: testname1
| 1 |
#+TBLNAME: testname2
| 2 |
Note the (string ?# ?1 ?$ ?1): this is necessary because before evaluating table formulae, all substitutions will be done first. If you use "#1$1" directly, it would have triggered the substitution mechanism and be substituted by the contents of the first cell in this table.
There is some ugly hack for same effect without using remote:
1) it needs named variable for remote address
(setq eab/test-remote "#1$1")
2) it uses elisp expression (from org-table.el) instead remote(tablename,#1$1)
(defun eab/test-remote (x)
`(car (read
(org-table-make-reference
(org-table-get-remote-range ,x eab/test-remote)
't 't nil))))
3) worked example
| testname1 | testname2 |
|-----------+-----------|
| | |
#+TBLFM: #2='(eval (eab/test-remote #1))
#+TBLNAME: testname1
| 1 |
#+TBLNAME: testname2
| 2 |
4) result
| testname1 | testname2 |
|-----------+-----------|
| 1 | 2 |

Emacs org-mode totals table

I have an org file, describing a project:
* task1
** task1-1
:PROPERTIES:
:price: 10
:given: <2012-11-08 Thu>
:END:
** task1-2
:PROPERTIES:
:price: 11
:given: <2012-11-08 Thu>
:END:
* task2
** task2-1
:PROPERTIES:
:price: 20
:given: <2012-11-08 Thu>
:END:
** task2-2
:PROPERTIES:
:price: 21
:given: <2012-11-08 Thu>
:END:
I used org-collector to produce a totals table:
#+BEGIN: propview :id global :conds ((not (= price 0))) :cols (ITEM price)
| ITEM | price |
|-----------+-------|
| "task1-1" | 10 |
| "task1-2" | 11 |
| "task2-1" | 20 |
| "task2-2" | 21 |
|-----------+-------|
| | 62 |
#+TBLFM: #6$2=vsum(#2$2..#5$2)
#+END:
But I want to have something like this:
| ITEM | price |
|-----------+-------|
| "task1-1" | 10 |
| "task1-2" | 11 |
| "task2-1" | 20 |
| "task2-2" | 21 |
|-----------+-------|
| Total | 62 |
How to do it?
For the “Total” line, you can add a line |Total| |, press C-u C-c = in the empty cell (to define a formula for it), and enter the formula vsum(#1$2..#4$2). (If you wanna recalc, that's C-u C-c C-c for all.)
I don't know about org-collector, so can't help you with this part. Run it on the entire document (is :id global working?), or shift everything by one level to the right for it to be inside a single tree, maybe.
I just figured this one out this morning. The answer you're looking for with Org-Collector is straightforward. Just put the table formulae two blank lines beneath the beginning of the property view and it'll be calculated automatically when the property view is evaluated (with C-c C-c).
#+BEGIN: propview :scope tree :cols (ITEM CLOCKSUM EFFORT) :match "TODO=\"TODO\"" :noquote ALL
#+TBLFM: #>$1=Totals::#>$2=vsum(#I..#II);t::#>$3=vsum(#I..#II);t
#+END:
If you want to turn this into a generic yasnippet, you need to escape the $ and the \:
#+BEGIN: propview :scope tree :cols (ITEM CLOCKSUM EFFORT) :match "TODO=\\"TODO\\"" :noquote ALL
#+TBLFM: #>\$1=Totals::#>\$2=vsum(#I..#II);t::#>\$3=vsum(#I..#II);t
#+END:
Now, you can add a generic property view that calculates the time so far and effort remaining for each step of a project, as well as the total time overall.