使用emacs中的默认Windows应用程序打开文件

Tom*_*ith 12 windows emacs elisp

我正在尝试dired-find-file在Windows XP上调整emacs中的功能,以便当我从dired打开(说)一个pdf文件时,它会激活一份Acrobat Reader并用它打开该文件,而不是在emacs中打开它.但我无法确定shell-command/call-process要使用的变体.这是我到目前为止所拥有的:

(defadvice dired-find-file (around dired-find-file-external (filename &optional wildcards))
  "Open non-text files with an appropriate external program."
  (if (string= ".pdf" (substring filename (- (length filename) 4))) ; obviously I'll replace this with something more general/robust
    (shell-command filename) ;; what should go here?
    (ad-do-it)))

(ad-activate 'dired-find-file)
Run Code Online (Sandbox Code Playgroud)

我知道我可以硬编码启动Acrobat Reader,方法是给它提供.exe文件的位置.但我宁愿有一些东西需要较少的搜索,当默认应用程序移动/更改时不会破坏.我该怎么用?

小智 9

要扩展'org-open-file'提案:

(defun my-dired-find-file (&optional prefix)
    (interactive "P")
    (if prefix
        (org-open-file (dired-get-file-for-visit) 'system)
      (dired-find-file)))

(define-key dired-mode-map "\r" 'my-dired-find-file)
Run Code Online (Sandbox Code Playgroud)

将允许您使用`Cu RET'在外部打开文件.

发现于http://lists.gnu.org/archive/html/bug-gnu-emacs/2012-11/msg01069.html


小智 7

  1. 评估以下elisp
  2. 运行dired(Mx dired)
  3. 浏览到目录和文件
  4. 使用文件指针,按F3将打开基于Windows扩展名的文件.

    (defun w32-browser (doc) (w32-shell-execute 1 doc))

    (eval-after-load "dired" '(define-key dired-mode-map [f3] (lambda () (interactive) (w32-browser (dired-replace-in-string "/" "\\" (dired-get-filename))))))