简体   繁体   English

如何使用elisp在Emacs中格式化数据表?

[英]How to format a table of data in Emacs using elisp?

I want to format a table of data automatically in Emacs using elisp with the awesome table-insert command. 我想使用elisp和真棒的table-insert命令在Emacs中自动格式化数据table-insert My idea is to do something like this, but it doesn't work: 我的想法是做这样的事情,但是不起作用:

(defun make-table ()
  (interactive)
  (table-insert 2 1) ; Table with 2 columns and 1 row
  (insert "first cell contents")
  (table-forward-cell)
  (insert "second cell contents")
  (table-release)
  )

Instead of inserting the "first cell contents" in the table, it inserts the text just before the first cell, so the text doesn't go into the table at all. 它没有在表中插入“第一个单元格内容”,而是在第一个单元格之前插入了文本,因此文本根本不会进入表中。 Then it crashes on the (table-forward-cell) call. 然后它在(table-forward-cell)调用上崩溃。

When I do this interactively, it works fine--how is the elisp code above different from doing it manually with my keyboard? 当我以交互方式进行此操作时,它可以正常工作-上面的elisp代码与使用键盘手动进行操作有何不同?

Reason is that the insert "destroys" the table, as it moves the | 原因是插入内容在移动表时会“破坏”表| character. 字符。 Then (table-forward-cell) fails because it cannot "parse" the table in the buffer. 然后(table-forward-cell)失败,因为它无法“解析”缓冲区中的表。

My advice would be to take a look to org-mode and the table relate functionality it provides. 我的建议是看一下org-mode ,该表涉及它提供的功能。 Then, you will figure out which one suits your needs better, table or org-mode 然后,您将找出tableorg-mode哪个更适合您的需求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM