无需用户交互即可在 org-mode 表和 table.el 表之间进行转换

Ado*_*obe 3 emacs elisp

我将组织模式表转换为 table.el 表。为此,我选择了表格:

| Option      | Type | Value | Descr        |
| -[no]h      | bool | yes   | Print        |
| -[no]versio | bool | no    | Print        |
| -nice       | int  | 0     | Set t        |
| -[no]v      | bool | no    | Be lo        |
| -time       | real | -1    | Take         |
| -[no]rmvsbd | bool | yes   | Removvirtual |
| sites       |      |       |              |
| -maxwarn    | int  | 0     | Numbe        |
| procenerate |      |       |              |
| unsta       |      |       |              |
| -[no]zero   | bool | no    | Set pthout   |
| defau error |      |       |              |
| -[no]renum  | bool | yes   | Renum        |
| atomty      |      |       |              |
Run Code Online (Sandbox Code Playgroud)

并按C-c ~org-mode然后问我

Convert table to table.el table? (y or n)
Run Code Online (Sandbox Code Playgroud)

我如何以y编程方式回答?我阅读了那个 defun 的文档——没有办法用前缀 arg 来做到这一点。

bash 中的类似功能:

echo y | script-which-asks-y-or-n
Run Code Online (Sandbox Code Playgroud)

Tyl*_*ler 5

C-c ~调用命令org-table-create-with-table.el,它提供了一堆围绕调用的包装器org-table-convert。如果您想在知道自己已经在组织模式表中时使用此功能,则不需要包装器,您只需要两个(可能只有一个)命令:org-table-alignorg-table-convert

因此,如果您以交互方式执行此操作,则只需调用即可M-x org-table-convert完成。这假设表格已经对齐。您可以通过从一个单元格切换到下一个单元格来手动完成此操作,这会触发表格对齐。或者你可以用一个小函数来做到这一点:

(defun my-convert-tables ()
"No questions asked, just convert the table"
  (interactive)
  (org-table-align)
  (org-table-convert))
Run Code Online (Sandbox Code Playgroud)