Emacs 用于从组织表中删除选定行的宏
我有一些Emacs 用于从组织表中删除选定行的宏,emacs,org-mode,Emacs,Org Mode,我有一些org表,有5列和100行 我想删除带有字段$3=“away”的所有行 下面是应该执行以下操作的函数。不幸的是,我不知道如何将使用(org table to lisp)创建的org表转换回文本表到我的缓冲区中 (defun org-table-tests () "acts on balance table itself" (interactive) (save-excursion (unless (org-table-p) (error "Y
org
表,有5列和100行
我想删除带有字段$3=“away”
的所有行
下面是应该执行以下操作的函数。不幸的是,我不知道如何将使用(org table to lisp
)创建的org
表转换回文本表到我的缓冲区中
(defun org-table-tests ()
"acts on balance table itself"
(interactive)
(save-excursion
(unless (org-table-p)
(error
"You are not in an org-table."))
(goto-char (org-table-begin))
(let (out-tbl
(tbl-list (org-table-to-lisp)))
(while
(let ((row-list (car tbl-list)))
(cond ((and
(listp row-list)
;; do not copy "away" (3rd column) lines containing folliwng:
(string-match "away" (nth 2 row-list)))
;; just skip copying to new table
)
(t (setq out-tbl (cons row-list out-tbl))))
(setq tbl-list (cdr tbl-list))))
;;(orgtbl-to-generic out-tbl) <---------- QUESTION: which function to use to convert back to table in text format.
)))
(defun组织表测试()
“作用于平衡表本身”
(互动)
(省去远足
(除非(org-table-p)
(错误
“您不在组织表中。”)
(转到字符(组织表开始))
(出租)(待决)
(tbl列表(组织表到lisp)))
(而
(出租((行列表(车辆tbl列表)))
(cond)(and)
(listp行列表)
;不要复制包含以下内容的“离开”(第三列)行:
(字符串匹配“远离”(第n个2行列表)))
只需跳过复制到新表即可
)
(t(设置输出tbl(cons行列表输出tbl)))
(setq tbl列表(cdr tbl列表)))
;;;(orgtbl到generic out tbl)看看组织列表表到string
。它与组织表到lisp的顺序相反
也看看怎么样
我在不到一分钟的时间内找到了解决方案(基本上只是在org的代码库中为“to table”打了灰)。既然您的主要问题得到了回答,现在有一个解决方案不依赖于转换为lisp并返回:
(defun org-table-tests ()
(interactive)
(save-excursion
(unless (org-table-p)
(error "You are not in an org-table."))
(goto-char (org-table-begin))
(while (org-table-p)
(if (string-match "away" (save-excursion (org-table-get-field 3)))
(delete-region (point) (progn (forward-line) (point)))
(forward-line)))))
如果您只想删除$3==“away”所在的行,下面的命令很有用。但我不知道为什么它会起作用
ESC M-更清洁的解决方案:)
^[|][^|]*[|][^|
]*[|] away [|]
| 1 | 2 | 3 | 4 | 5 |
|------+------+------+------+------|
| away | 12 | 13 | 14 | away |
| 21 | 22 | away | 24 | 25 |
| 31 | away | 33 | away | 35 |
| 1 | 2 | 3 | 4 | 5 |
|------+------+------+------+------|
| away | 12 | 13 | 14 | away |
| 31 | away | 33 | away | 35 |