emacs - 在组织模式导出上重新应用表公式

标签 emacs org-mode org-babel

我正在使用 org-mode 文件进行一些文件系统监控。为此,我有一个表格,我在其中通过公式中的 org-sbe 调用代码块。它看起来像这样:

#+NAME: part-size
#+BEGIN_SRC bash :var mach="" :var part="" :var bs="TB" :exports none :results silent
 tmp=($(df -B ${bs} /net/${mach}/${part} | tail -1 ))
 bc -l <<< "scale=2; ${tmp[1]}/1024/1024"
#+END_SRC

#+NAME: part-used
#+BEGIN_SRC bash :var mach="" :var part="" :var bs="TB" :exports none :results silent
 tmp=($(df -B${bs} /net/${mach}/${part} | tail -1))
 bc -l <<< "scale=2; ${tmp[2]}/1024/1024"
#+END_SRC

| machine | partition | size[TB] | used[TB] | available[TB] |
|---------+-----------+----------+----------+---------------|
| mach1   | part1     |     60.0 |     56.0 |           4.0 |
| mach1   | part2     |     15.0 |     12.5 |           2.5 |
| mach2   | part1     |     40.5 |     10.5 |          30.0 |
|---------+-----------+----------+----------+---------------|
| total   |           |    115.5 |     79.0 |          36.5 |
#+TBLFM: @>$3..@>$5=vsum(@I..II)::@2$3..@9$3='(org-sbe part-size (mach $$1) (part $$2) (bs \"1MB\"))::@2$4..@9$4='(org-sbe part-used (mach $$1) (part $$2) (bs \"1MB\"))::@2$5..@9$5=$-2 - $-1

我的问题是我定期自动将该文件导出到网页,但表格的内容没有得到更新。所以我想知道是否有一种方法可以在导出时自动重新应用表格公式,就像在导出时运行代码块一样。

最佳答案

这是一个简化的示例,使用 Seth Rothschild 在评论中建议的机制,每次导出时都会在表中更新时间:

* code                                                     :noexport:                                                                                           

#+begin_src emacs-lisp
(defun tables-recalc (backend)
    (org-table-recalculate-buffer-tables))

(add-hook 'org-export-before-processing-hook #'tables-recalc)
#+end_src

#+RESULTS:
| tables-recalc |

* table
#+NAME: gettime
#+begin_src shell 
date
#+end_src
| time                         |
|------------------------------|
| Wed Apr 11 16:27:09 EDT 2018 |
#+TBLFM: $> = '(org-sbe gettime)

关于emacs - 在组织模式导出上重新应用表公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49756167/

相关文章:

arrays - 更好的排列生成算法

emacs - Elisp破坏性操作警告?

emacs - 如何在 Emacs Org-Mode 中锁定表字段(使它们只读,常量)?

emacs - 如何在emacs中使用向后删除单词而不是向后杀死单词

emacs - 在哪里可以找到 Gnu Emacs 的公钥?

emacs - 如何在 org-mode 中创建多级有序(编号)普通列表?

emacs - 组织模式:抽屉的可见导出

emacs - org-babel 中的 noweb 样式编织

org-mode - 为什么 Org-mode 会忽略 :noexport: tags