如何在 Evince 中使用 Org 模式打开 PDF 文件? [英] How do I make Org-mode open PDF files in Evince?

查看:21
本文介绍了如何在 Evince 中使用 Org 模式打开 PDF 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Org 模式下,当我尝试打开指向 PDF 文件的链接时,没有任何反应.此外,当我执行 C-c C-e d 导出为 LaTeX 并处理为 PDF 并打开时,生成的 PDF 已生成但未打开.如何在 Evince 中使用 Org 模式打开 PDF 文件?

In Org-mode when I try to open a link to a PDF file nothing happens. Also, when I do C-c C-e d to export as LaTeX and process to PDF and open the PDF is generated but not opened. How do I make Org-mode open PDF files in Evince?

我在 GNU Emacs 23.3.1 中使用 Org-mode 7.6,在 Ubuntu 11.10 中使用 Evince 3.2.1.

I am using Org-mode 7.6 in GNU Emacs 23.3.1 and Evince 3.2.1 in Ubuntu 11.10.

推荐答案

另一种可行的结构是使用 eval-after-load 而不是 add-hook.它只会在启动时设置一次值,您不必担心是否添加条目(除非您定期重新加载组织).

Another possible construct that could work for this would be to use eval-after-load rather than add-hook. It will only set the values once on startup, you won't have to worry about entries being added or not (unless you regularly reload org).

将它与 setcdr 结合起来,您可以避免从列表中删除然后重新添加,添加 if 并且您将确保添加或更改价值.if 仅用于默认情况下不在列表中的值,只是为了确保您最终不会在某处发生冲突.

Combine that with setcdr and you can avoid having to delete from the list and then re-add, add if and you'll ensure that you either add or change the value. The if is only needed for values that aren't in the list by default, just to make sure you don't end up with conflicts somewhere down the line.

(eval-after-load "org"
  '(progn
     ;; .txt files aren't in the list initially, but in case that changes
     ;; in a future version of org, use if to avoid errors
     (if (assoc "\.txt\'" org-file-apps)
         (setcdr (assoc "\.txt\'" org-file-apps) "notepad.exe %s")
       (add-to-list 'org-file-apps '("\.txt\'" . "notepad.exe %s") t))
     ;; Change .pdf association directly within the alist
     (setcdr (assoc "\.pdf\'" org-file-apps) "evince %s")))

<小时>

编辑以澄清


Edit for clarification

eval-after-load 仅在调用 (require 'org) 时评估块.如果 org 已经加载,它将立即评估(我错误地认为每次加载库时它都会运行,但似乎只是第一次).add-hookeval-after-load 之间的区别解释 此处.

eval-after-load only evaluates the block when (require 'org) is called. If org is already loaded it will evaluate immediately (I mistakenly thought it ran each time a library was loaded, but it seems to be only the first time). The difference between add-hook and eval-after-load is explained here.

因为 org-file-apps 是一个 defcustom 如果你在 org 加载之前设置它们,它不会改变这些值,如果你从头开始构建列表(包括你的第二个(更丑的)解决方案中的默认值)你可以在你的 init.el 中简单地 setq ,一切都会正常工作.这也意味着它不会覆盖您的更改.

Since org-file-apps is a defcustom it won't change the values if you set them before org is loaded, if you build the list from scratch (including default values as in your second (uglier) solution) you could simply setq in your init.el and everything would work. It also means it won't overwrite your changes.

添加 (if (assoc 到 PDF 条目不会伤害任何东西,它只会确保是否从默认的 org-file-apps 中删除了 PDF它仍然会被添加.如果 PDF 被删除,唯一不会失败的解决方案是你的第二个.其他人都假设条目以一种或另一种形式存在.

Adding (if (assoc to the PDF entry won't hurt anything, it will simply ensure that if PDFs are ever removed from the default org-file-apps that it will still be added. The only solution that would not fail if PDFs were removed is your second one. The others all assume the entry exists in one form or another.

这篇关于如何在 Evince 中使用 Org 模式打开 PDF 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆