2

我正在使用这种创建列的方法:http:
//orgmode.org/worg/org-tutorials/org-spreadsheet-lisp-formulas.html

我有一个包含 9 列的电子表格,第 8 列包含其中带有美元符号的文件名,例如:
product_name $500.00.jpg

所以我希望第 9 列说明文件是否实际存在,所以我的 org TBLFM 如下:
#+TBLFM: $9='(file-exists-p (concat "/import/" $8))

所以问题是,无论我是否使用;LTBLFM 末尾的标志,在应用公式时,我都会立即得到“无效字段说明符:“$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")
4

2 回答 2

2

这是 Org 代码的一部分,它处理公式的这种情况:

;; 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))
于 2013-06-24T17:44:22.307 回答
0

尝试用美元字符转义 8 美元,即 8 美元。

于 2013-06-23T18:10:41.500 回答