From b542b922a0c5cd49b1aaa7e59a00e29582437651 Mon Sep 17 00:00:00 2001 From: Wojciech Kozlowski Date: Sat, 13 Aug 2022 22:39:14 +0200 Subject: [PATCH] Fix opening links from WSL --- config.el | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/config.el b/config.el index 16f69bb..fea7616 100644 --- a/config.el +++ b/config.el @@ -427,6 +427,29 @@ ;; Enable the fill column indicator. (add-hook 'prog-mode-hook #'display-fill-column-indicator-mode) +;; Allow Emacs in WSL to open links in a browser on the Windows host. +(when (and (eq system-type 'gnu/linux) + (string-match + "Linux.*Microsoft.*Linux" + (shell-command-to-string "uname -a"))) + (setq + browse-url-generic-program "/mnt/c/Windows/System32/cmd.exe" + browse-url-generic-args '("/c" "start") + browse-url-browser-function #'browse-url-generic) + + (defun +x/browse-url-of-dired-file () + "In Dired, ask a WWW browser to display the file named on this line." + (interactive) + (let ((tem (dired-get-filename t t))) + (if tem + (browse-url-of-file (concat "file://///wsl$/" + (getenv "WSL_DISTRO_NAME") + (expand-file-name tem))) + (error "No file on this line")))) + + (map! (:map dired-mode-map + "W" #'+x/browse-url-of-dired-file))) + ;; ----------------------------------------------------------------------------- ;; Global keybindings. ;; -----------------------------------------------------------------------------