[英]How do I prevent org-mode from executing all of the babel source blocks?
[英]How do I generate source code from an org mode table?
我正在嘗試找出一種將i3wm配置文件移動到組織模式文件的方法。 我有一個包含鍵綁定以及它們應執行什么命令的表,我想從中生成適當的源代碼。
例:
| Keybinding | Command | Action |
|-----------------------+----------------------+--------------------------|
| {{{mod}}} + Return | i3-sensible-terminal | Opens a new terminal |
| {{{mod}}} + Shift + q | kill | Kills the focused window |
應該產生
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
這樣有可能嗎?
您可以命名表並將其作為參數傳遞給源塊,並使源塊遍歷行。 這是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
在這里,我假設應該消除第一列中的空格,而不是引用字符串,但是您可以輕松地對其進行修改。
這是運行上述源代碼塊的結果:
#+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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.