Opening files with default Windows application from within emacs

前端 未结 8 1713
难免孤独
难免孤独 2021-02-07 21:06

I\'m trying to tweak the dired-find-file function in emacs on Windows XP so that when I open (say) a pdf file from dired it fires up a copy of Acrobat Reader and op

8条回答
  •  無奈伤痛
    2021-02-07 21:56

    I'd use (w32-shell-execute "open" file-name).

    In fact, in my init file I have:

    (defun open-externally (file-name)
      (interactive "fOpen externally: ")
      (let ((process-connection-type nil))
         (start-process "open-externally" nil
                        "xdg-open" file-name)))
    
    (when (eq window-system 'w32)
      (defun open-externally (file-name)
        (interactive "fOpen externally: ")
        (w32-shell-execute "open" file-name)))
    

    Which defines a command that (may be used interactively and) opens a file with the default application according to xdg-open and then, if I'm actually on Windows, redefines that command appropriately.

提交回复
热议问题