N.N*_*.N. 31 pdf emacs org-mode
在Org-mode中,当我尝试打开PDF文件的链接时,没有任何反应.此外,当我C-c C-e d作为LaTeX导出并处理为PDF并打开PDF时生成但未打开.如何在Evince中创建组织模式打开PDF文件?
我在GNU Emacs 23.3.1中使用Org-mode 7.6,在Ubuntu 11.10中使用Evince 3.2.1.
小智 22
M-x customize-variable [RET] org-file-apps [RET]
Run Code Online (Sandbox Code Playgroud)
如果org使用您的系统默认值,则必须编辑./mailcap文件.
尝试添加此行:
application/pdf; /usr/bin/evince %s
Run Code Online (Sandbox Code Playgroud)
Jon*_*pin 11
可能适用于此的另一种可能的构造是使用eval-after-load而不是add-hook.它只会在启动时设置一次值,您不必担心添加或不添加条目(除非您经常重新加载组织).
将其与之结合使用setcdr,您可以避免从列表中删除然后重新添加,添加if并确保添加或更改值.if仅在默认情况下不在列表中的值时才需要,只是为了确保您不会在某个地方遇到冲突.
(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")))
Run Code Online (Sandbox Code Playgroud)
编辑以澄清
eval-after-load仅在(require 'org)调用时计算块.如果已经加载了org,它将立即进行评估(我错误地认为每次加载库时它都会运行,但它似乎只是第一次).这里解释add-hook和之间的区别. eval-after-load
既然org-file-apps是defcustom不会改变的值,如果你把其中装载组织之前,如果你建立的名单从头开始(包括默认值作为你的第二个(丑陋的)解决方案),你可以简单地setq在你的init.el,一切会工作.这也意味着它不会覆盖您的更改.
添加(if (assoc到PDF条目不会对任何内容产生任何影响,它只会确保如果从默认情况下删除了PDF org-file-apps,它仍将被添加.如果删除PDF,唯一不会失败的解决方案是您的第二个解决方案.其他人都假设条目以某种形式存在.
您可以使用类似于/sf/answers/278988671/的构造,但将其修改为PDF文件和Evince.你想要做的是改变列表org-file-apps.这可以通过在.emacs中添加以下内容来完成:
;; PDFs visited in Org-mode are opened in Evince (and not in the default choice) https://stackoverflow.com/a/8836108/789593
(add-hook 'org-mode-hook
'(lambda ()
(delete '("\\.pdf\\'" . default) org-file-apps)
(add-to-list 'org-file-apps '("\\.pdf\\'" . "evince %s"))))
Run Code Online (Sandbox Code Playgroud)
这将删除PDF文件的默认设置,而是在Evince中打开它们(并保留其中包含的所有内容org-file-apps).我是elisp的新手,所以我不知道这个解决方案是否健壮,但它对我有用,似乎比下面的更优雅.
另一个看起来更丑陋的选择是改为查找默认值并将它们全部设置为但更改PDF文件的值:
;; PDFs visited in Org-mode are opened in Evince (and other file extensions are handled according to the defaults)
(add-hook 'org-mode-hook
'(lambda ()
(setq org-file-apps
'((auto-mode . emacs)
("\\.mm\\'" . default)
("\\.x?html?\\'" . default)
("\\.pdf\\'" . "evince %s")))))
Run Code Online (Sandbox Code Playgroud)