在组织模式导出中重新应用 table 公式
Re-apply table formulas on org-mode export
我正在使用 org-mode 文件进行一些文件系统监控。为此,我有一个 table,我在其中通过公式中的 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: @>..@>=vsum(@I..II)::@2..@9='(org-sbe part-size (mach $) (part $) (bs \"1MB\"))::@2..@9='(org-sbe part-used (mach $) (part $) (bs \"1MB\"))::@2..@9=$-2 - $-1
我的问题是我定期自动将该文件导出到网页,但 table 的内容没有得到更新。所以我想知道是否有一种方法可以在导出时自动重新应用 table 公式,就像在导出时可以 运行 代码块一样。
这是一个简化的示例,每次导出时都会在 table 中更新时间,使用 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)
我正在使用 org-mode 文件进行一些文件系统监控。为此,我有一个 table,我在其中通过公式中的 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: @>..@>=vsum(@I..II)::@2..@9='(org-sbe part-size (mach $) (part $) (bs \"1MB\"))::@2..@9='(org-sbe part-used (mach $) (part $) (bs \"1MB\"))::@2..@9=$-2 - $-1
我的问题是我定期自动将该文件导出到网页,但 table 的内容没有得到更新。所以我想知道是否有一种方法可以在导出时自动重新应用 table 公式,就像在导出时可以 运行 代码块一样。
这是一个简化的示例,每次导出时都会在 table 中更新时间,使用 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)