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

时间:2011-07-27 13:20:43

标签: emacs dired docview

我想用evince而不是DocView模式打开pdf。是否有可能使用'evince'等特定命令打开文件?

7 个答案:

答案 0 :(得分:23)

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

evince的情况下,使用&更聪明,它会异步运行命令,因此在打开PDF时仍然可以使用emacs。

答案 1 :(得分:18)

有多种方法可以做到这一点。我建议OpenWith库。您的案例设置可能如下:

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

它设置了可以同时使用diredfind-file的文件处理程序。

答案 2 :(得分: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)))

答案 3 :(得分:4)

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

答案 4 :(得分:3)

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

C-u ! nohup evince ? &

创建Persistent Processes [EmacsWiki]。

答案 5 :(得分:1)

在Windows中,我经常使用!和命令"探险家#34;打开PDF / Word / Excel ......

答案 6 :(得分:0)

(defun dired-open()
  (interactive)
  (setq file (dired-get-file-for-visit))
  (setq ext (file-name-extension file))
  (cond ((string= ext "pdf")
         ;; shell-quote-argument escapes white spaces on the file name
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "epub")
         (async-shell-command (concat "zathura " (shell-quote-argument file))))
        ((string= ext "rar")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        ((string= ext "zip")
         (async-shell-command (concat "file-roller " (shell-quote-argument file))))
        (t (dired-find-file))))