如何在Emacs dired模式下从外部打开文件?

Gus*_*lip 29 emacs docview dired

我想用evince而不是DocView模式打开pdf.是否有可能使用像'evince'这样的特定命令打开文件?

Raf*_*ler 24

是.!在dired中使用,在文件上运行shell命令.

在这种情况下evince,使用&它会更智能,它将异步运行命令,因此当您打开PDF时,emacs仍然可用.

  • 请注意,您可以通过dired-x中的dired-guess-shell-alist-user自定义由!!使用的默认命令:((setq dired-guess-shell-alist-user'((“ \\ .pdf \\'“” evince“))) (2认同)

Vic*_*gin 19

有更多的方法可以做到这一点.我建议使用OpenWith库.您的案例的设置可能如下所示:

(add-to-list 'load-path "/path/to/downloaded/openwith.el")
(require 'openwith)
(setq openwith-associations '(("\\.pdf\\'" "evince" (file))))
(openwith-mode t)
Run Code Online (Sandbox Code Playgroud)

它设置将同时使用dired和的文件处理程序find-file.

  • 至少在Mac OSX中,我用`open`替换了`evince`,然后它使用默认软件(在我的情况下为`Skim`). (4认同)
  • 请注意,在这种情况下,您只需在dired中命名文件名`RET`,而不是使用`!`或`&`来运行shell命令.您还可以通过在openwith-associations上使用setq来丢失所有内置关联.可能有一个更好的方法来改变pdf关联,同时留下.mp3,.jpg,...的关联? (3认同)

tot*_*shi 9

试试这个.

(defun dired-open-file ()
  "In dired, open the file named on this line."
  (interactive)
  (let* ((file (dired-get-filename nil t)))
    (message "Opening %s..." file)
    (call-process "gnome-open" nil 0 nil file)
    (message "Opening %s done" file)))
Run Code Online (Sandbox Code Playgroud)

  • 这很好用.如果在另一个GUI(如KDE)中使用,我将`gnome-open`替换为`xdg-open`. (4认同)

Nou*_*him 8

您可以使用!打开文件,然后指定命令。

  • 如果您想异步运行该命令,请使用“&”而不是“!”。 (9认同)

Ice*_*ack 5

请注意,您可以在退出 Emacs 后使用nohup[Wikipedia]保持进程处于活动状态,因此将重点放在单个文件中dired

C-u ! nohup evince ? &
Run Code Online (Sandbox Code Playgroud)

它创建了一个持久进程[EmacsWiki]。