【问题标题】:Re-apply table formulas on org-mode export在组织模式导出上重新应用表公式
【发布时间】:2018-04-10 14:25:57
【问题描述】:

我正在使用 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

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

【问题讨论】:

  • 您可能会在emacs 特定站点上得到更快的答复。我怀疑您会想要修改 org 导出挂钩之一。
  • 感谢您的提示,我是there

标签: emacs org-mode org-babel


【解决方案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)

【讨论】:

  • 很高兴它有帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-08
  • 1970-01-01
  • 2014-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多