如何从组织模式表生成源代码?

问题描述 投票:0回答:1

我正在试图找到一种方法将我的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

这样的事情可能吗?

emacs org-mode
1个回答
2
投票

您可以将表命名并将其作为参数传递给源块,并使源块迭代遍历行。这是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
© www.soinside.com 2019 - 2024. All rights reserved.