emacs - 带有美元符号列的组织表格式

标签 emacs elisp org-mode

我正在使用这种创建列的方法:
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/

相关文章:

ruby - 我如何开始在 Emacs 中使用 Xiki?

emacs - 从文件读入Emacs Lisp列表

emacs - 在缓冲区中输入时监听键盘事件

emacs - 如何在 Windows 中专注于新的 Emacs 框架

emacs - 当我在组织模式下点击链接时,最初找不到附加目录;我总是必须先执行 org-attach-sync 。我该如何解决这个问题?

github - Mylyn 的 Emacs 组织模式文件连接器?

emacs - idris-mode – 缓冲区没有进程

emacs - 为什么 Melpa(Emacs Lisp 存储库)版本号如此之高?

emacs - 如何将函数作为参数传递给elisp?

emacs - 退出 emacs 之前运行函数