Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从emacs中使用默认Windows应用程序打开文件_Windows_Emacs_Elisp - Fatal编程技术网

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

从emacs中使用默认Windows应用程序打开文件,windows,emacs,elisp,Windows,Emacs,Elisp,我试图在Windows XP上调整emacs中的dired find file函数,这样当我从dired打开(比如)一个pdf文件时,它会启动Acrobat Reader的副本并用它打开该文件,而不是在emacs中打开它。但我无法确定要在shell命令/调用过程中使用哪个变量。以下是我目前掌握的情况: (defadvice dired-find-file (around dired-find-file-external (filename &optional wildcards))

我试图在Windows XP上调整emacs中的
dired find file
函数,这样当我从dired打开(比如)一个pdf文件时,它会启动Acrobat Reader的副本并用它打开该文件,而不是在emacs中打开它。但我无法确定要在
shell命令/调用过程中使用哪个变量。以下是我目前掌握的情况:

(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)
我知道我可以通过给它.exe文件的位置来硬编码它以启动Acrobat Reader。但我更希望有一些东西,它需要较少的搜索,并且在默认应用程序移动/更改时不会中断。我应该使用什么?

我通过谷歌找到了,这让我了解了一种使用RunDll的技术。我把它放在这里以防其他人好奇

下面是一段关键代码,它使用适当的应用程序打开
filename

(shell-command (concat "rundll32 shell32,ShellExec_RunDLL " (shell-quote-argument filename)))
这是我的完整解决方案。(请注意,
dired find file
只是一个不知道文件名的包装文件
find file
,因此您必须建议
find file
,而不是像问题中那样建议
dired find file
。如果您不希望
find file
的行为,您可能需要重写
dired find file)de>或编写更复杂的建议。)


Tom Smith的回答很好,但是您也可以使用文件名作为参数运行程序“start”

(shell-command (concat "start " (shell-quote-argument filename)))
  • 评估以下elisp
  • 运行方向(M-x方向)
  • 浏览到目录和文件
  • 使用文件上的点,按F3键将根据windows扩展名打开文件

    (defun w32浏览器(doc)(w32 shell执行1 doc))

    (加载“dired”后求值)(定义键dired模式映射[f3](lambda()(交互式)(w32浏览器(dired替换为字符串“/”\\“(dired获取文件名“)”)

  • 用于此,以及

    • C-RET使用其Windows文件关联应用程序打开当前行的文件

    • M-RET将Windows资源管理器打开到文件或文件夹

    • ^,当位于根目录(例如,
      C:\
      )中时,向上移动到所有Windows驱动器(本地和远程)的类似目录的列表


    前两个的命令可从
    w32 browser.el
    获得。(Dired+将它们绑定到这些键上。)第三个命令来自Dired+。

    org open file
    是一个独立于系统的外部开启器。有关如何进一步自定义,请参见
    org file apps

    要扩展“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)
    
    将允许您使用“C-u RET”从外部打开文件


    可在

    找到。我的.emacs中有:

    (setq dired-guess-shell-alist-user
      (list
        (list "\\.*$" "cmd /k")
      ))
    
    这将使用cmd.exe打开文件,cmd.exe将使用与文件扩展名关联的任何程序。已测试在Windows 8和GNU Emacs 24.2.1上运行。

    我会使用
    (w32 shell执行“打开”文件名)

    事实上,在我的init文件中,我有:

    (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)))
    

    它定义了一个命令,该命令(可以交互使用)根据
    xdg open
    使用默认应用程序打开一个文件,然后,如果我实际上在Windows上,则相应地重新定义该命令。

    确定吗?当我尝试此操作时,它不起作用-我只得到一个空的命令提示窗口。@汤姆:这是有道理的,因为
    start
    的第一个引用参数用作窗口标题。不喜欢加载后求值,但是+1对于w32 shell执行-这显然是正确的方法。当我按下``F3`时,它说的是定义kbd宏…
    ,我正在测试
    (setq-dired-guess-shell-alist-user'(“*”(concat“start”“\”“file”“))
    。(我遇到了带空格的文件名。)但是小缓冲区说
    没有定义M-Ret
    @ZhaoGang:谢谢。更正。忘记了前两个命令是在w32-browser.el中定义的。
    (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)))