如何编写 LISP 以在将表导入 org 文件后转置表?

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

我从

txt
文件中读取了一个表格,如下所示,如何通过脚本转置它?脚本中似乎无法使用
org-table-transpose-table-at-point
函数。有没有内置函数可以缩短脚本?

#+begin_src emacs-lisp
  (org-table-import "ttt.out" nil)
#+end_src

文件

ttt.out
将是:

#Cluster   Frames   Rep RepScore   Rep RepScore
       0      23      2      0.6     6      0.4 
       1      10      5      0.1     3      0.5
       2       5      4      0.4     5      0.6
       3       4      1      0.4     2      0.6

我需要的结果(转置)。

| #Cluster |   0 |   1 |   2 |   3 |
| Frames   |  23 |  10 |   5 |   4 |
| Rep      |   2 |   5 |   4 |   1 |
| RepScore | 0.6 | 0.1 | 0.4 | 0.4 |
| Rep      |   6 |   3 |   5 |   2 |
| RepScore | 0.4 | 0.5 | 0.6 | 0.6 |

额外

转置可以使用来自(https://lists.gnu.org/archive/html/emacs-orgmode/2010-04/msg00239.html)的org-babel

然而,它并没有工作如下:

(apply #'mapcar* #'list (org-table-import "ttt.out" nil))

发生什么事了?

emacs elisp org-mode
1个回答
0
投票

在您提供的链接中,表作为变量传递到 babel 块。

(org-table-import "ttt.out" nil)
不会返回任何内容,因此应用程序没有任何工作可做。

这里为您提供一种解决方案:

#+BEGIN_SRC emacs-lisp :results org
(with-temp-buffer "tmp.org"
          (org-table-import "ttt.out" nil)
          (org-table-transpose-table-at-point)
          (buffer-string))
#+END_SRC

这会以字符串形式返回表格,您可以将其插入到您想要的位置。

© www.soinside.com 2019 - 2024. All rights reserved.