【问题标题】:Emacs org-mode file/viewer associationsEmacs 组织模式文件/查看器关联
【发布时间】:2011-04-27 19:07:57
【问题描述】:

在 Emacs 组织模式文件中,当我单击 PDF 时,文件会在 PDF 查看器中打开。同样,当我单击 URL 时,它会在 Web 浏览器中打开。但是,当我单击图像文件的路径时,字节流会在编辑器中以文本形式打开。如何配置 Emacs/org-mode 以使用指定的应用程序(例如图像编辑器或浏览器)打开图像?

【问题讨论】:

标签: emacs org-mode


【解决方案1】:

在 org-mode 中,org-file-apps 控制点击类似 URL 的文本时要执行的操作。

默认配置为:

((auto-mode . emacs)
 ("\\.mm\\'" . default)
 ("\\.x?html?\\'" . default)
 ("\\.pdf\\'" . default))

正如 org-file-apps help 中所说:auto-mode 匹配与auto-mode-alist 中的任何条目匹配的文件,因此所有文件 Emacs 都知道如何处理。将此命令与 emacs 一起使用将在 Emacs 中打开大多数文件。

您可能在自动模式列表中配置了图像文件扩展名。您可以通过在 .emacs 中执行类似的操作来覆盖此列表(例如,对于 png 文件):

(add-hook 'org-mode-hook
      '(lambda ()
             (setq org-file-apps
                   (append '(
                             ("\\.png\\'" . default)
                             ) org-file-apps ))))

使用这段代码,当我点击这样的链接时:

file:///e:/jrx/emacs/image.png

它使用与此文件扩展名关联的默认操作系统程序在 emacs 外部打开文件。

您无需更改org-file-apps-defaults-windowsntorg-file-apps-defaults-gnuorg-file-apps-defaults-macosx 即可使用与文件扩展名关联的操作系统默认程序。

【讨论】:

  • 使用 appendadd-hook 'org-mode-hook 似乎会在调用 Org-mode 时附加到列表中。这可以用"\\.png\\'" . default 淹没列表。您最好使用add-to-list 结构,例如stackoverflow.com/a/8836108/789593
【解决方案2】:

这取决于您使用的操作系统,但应该可以使用org-file-apps 进行配置。

  • 在 OS X 上,我会使用 open(或 open -a Application.app)自动打开文件
  • 在 Linux/BSD 等平台上,我会使用 xdg-open(虽然设置起来有点棘手)
  • 在 Windows 上,我想我会使用 open(在控制台中)

根据您的平台查看变量org-file-apps-defaults-windowsntorg-file-apps-defaults-gnuorg-file-apps-defaults-macosx

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多