【问题标题】:Emacs bibtex-mode unable to parse un-visited fileEmacs bibtex-mode 无法解析未访问的文件
【发布时间】:2016-09-29 04:02:23
【问题描述】:

我不确定表达这个问题的最佳方式,但希望我的例子能说明发生了什么。

我有一些代码,我想在临时缓冲区中插入 bibtex 文件的内容,并一次移动一个条目,使用 bibtex-parse-entry 抓取条目以供以后使用。但是,每当我在此 emacs 会话期间未访问过的 bibtex 文件上运行代码时,bibtex-parse-entry 就会返回 (wrong-type-argument stringp nil) 错误。

一旦我访问了文件,即使我随后关闭了缓冲区,代码也会毫无问题地运行。如果我删除 bibtex-parse-entry 调用,bibtex-kill-entry 也会出现同样的问题。

这是我正在使用的 elisp 代码:

(with-temp-buffer
  (insert-file-contents "~/test.bib")
  (goto-char (point-min))
  (bibtex-mode)
  (while (not (eobp))
    (let* ((entry (bibtex-parse-entry t)))
      (message "i'm here"))
    (bibtex-kill-entry)
    (bibtex-beginning-of-entry)
    )
  )

还有一个虚拟的 .bib 文件:

@Article{test,
  author =   {joe shmo},
  title =    {lorem ipsum},
  journal =      {something},
  year =     {1990},
}

有了这些你应该能够重现我的错误。

我不知道发生了什么,所以我非常感谢任何帮助!

【问题讨论】:

    标签: emacs bibtex


    【解决方案1】:

    我并不是这方面的专家。我只是稍微调试了一下情况(在这种情况下尝试M-x toggle-debug-on-error)并找到了对looking-at 的调用,其值为nil。堆栈跟踪告诉我们问题出在 bibtex 函数bibtex-valid-entry 中。在那里,我找到了变量 bibtex-entry-maybe-empty-head,根据它的文档字符串,它是由 bibtex-set-dialect 设置的。

    因此,在调用 bibtex-mode 之后向您的函数添加对 bibtex-set-dialect 的调用似乎可以解决问题。因为我真的不知道,你最终想要实现什么,我不确定它是否真的解决了你的问题。至少该函数确实不再引发错误。

    希望,这是有道理且有帮助的。

    (with-temp-buffer
      (insert-file-contents "~/test.bib")
      (goto-char (point-min))
      (bibtex-mode)
      (bibtex-set-dialect) ;; <-- add this
      (while (not (eobp))
        (let* ((entry (bibtex-parse-entry t)))
        (message "i'm here"))
        (bibtex-kill-entry)
        (bibtex-beginning-of-entry)))
    

    【讨论】:

    • 成功了!谢谢你的帮助。我正在尝试调试,但我还没有掌握调试 elisp 代码的窍门(我的大部分经验是使用 Python 和 Matlab,它们的工作方式非常不同)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    相关资源
    最近更新 更多