我正在使用这种创建列的方法:
http://orgmode.org/worg/org-tutorials/org-spreadsheet-lisp-formulas.html
我有一个包含 9 列的电子表格,第 8 列包含带有美元符号的文件名,例如:
product_name $500.00.jpg
所以我希望第 9 列说明该文件是否实际存在,因此我的组织 TBLFM 如下:
#+TBLFM: $9='(file-exists-p (concat "/import/" $8))
所以问题是,我是否使用;L
标记在 TBLFM 末尾,当应用公式时,我立即得到“无效的字段说明符:“$500””,因为没有编号为 500 的列。
关于如何让它工作有什么想法吗?我尝试过在引号中使用 $8,而不是在引号中使用,无论是否带有文字标记,并且我尝试过在实际列中转义美元符号,但都没有成功。
编辑:请务必注意,将我的列值更改为:product_name $\ 500.00.jpg
事实上确实有效,但是 file-exists-p
返回值明显不正确。
编辑:触发错误的组织模式表示例:
| foo | bar | /some/file with $500 in it.jpg | | baz |
| | | | | |
#+TBLFM: $4='(or (file-exists-p $3) "f")
最佳答案
这是组织代码位,用于处理公式的这种情况:
;; Insert the references to fields in same row
(while (string-match "\\$\\(\\([-+]\\)?[0-9]+\\)" form)
(setq n (+ (string-to-number (match-string 1 form))
(if (match-end 2) n0 0))
x (nth (1- (if (= n 0) n0 (max n 1))) fields))
(unless x (error "Invalid field specifier \"%s\""
(match-string 0 form)))
(setq form (replace-match
(save-match-data
(org-table-make-reference x nil numbers lispp))
t t form)))
如您所见,您无法回避这一点,但是,您可以在该位置附近修补org-table-eval-formula
,以允许您进行某种转义序列要插入文字印记,我可以做到这一点:
;; Insert the references to fields in same row
(while (string-match "\\(^\\|[^\\$]\\)\\$\\(\\([-+]\\)?[0-9]+\\)" form)
(setq n (+ (string-to-number (match-string 2 form))
(if (match-end 3) n0 0))
x (nth (1- (if (= n 0) n0 (max n 1))) fields))
(unless x (error "Invalid field specifier \"%s\""
(match-string 0 form)))
(setq form (replace-match
(save-match-data
(org-table-make-reference x nil numbers lispp))
t t form)))
这将跳过 $$
,不幸的是,这个函数会递归地调用自身,直到所有 $
都被替换(我不知道)。稍后你可以做什么:在 eLisp 代码中用单字符替换双字符...这在我的情况下有效:
| foo | bar | /some/file with $$500 in it.jpg | f | /some/file with $500 in it.jpg |
| | | | t | |
#+TBLFM: $4='(or (file-exists-p $3) "f")::$5='(format "%s" (replace-regexp-in-string "\\$\\$" "$" $3))
关于emacs - 带有美元符号列的组织表格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17263267/