分析对比windows原装的emacs与wsl2上运行的GUI版本

wsl2打开windows的应用为啥不行?很简单啊。用explorer.exe就行了,写了小脚本用了很久,没有遇过任何问题。https://hkvim.com/post/windows-setup/

;;;###autoload

(defmacro wsl--open-with (id &optional app dir)
  `(defun ,(intern (format "wsl/%s" id)) ()
     (interactive)
     (wsl-open-with ,app ,dir)))

(defun wsl-open-with (&optional app-name path)
  "Send PATH to APP-NAME on WSL."
  (interactive)
  (let* ((path (expand-file-name
                (replace-regexp-in-string
                 "'" "\\'"
                 (or path (if (derived-mode-p 'dired-mode)
                              (dired-get-file-for-visit)
                            (buffer-file-name)))
                 nil t)))
         (command (format "%s `wslpath -w %s`" 
(shell-quote-argument app-name) path)))
    (shell-command-to-string command)))
(wsl--open-with open-in-default-program "explorer.exe" buffer-file-name)
(wsl--open-with reveal-in-explorer "explorer.exe" default-directory)

dired下,然后wsl/open-in-default-program,就可以用explorer打开文件了。

9 个赞