reddit / emacs

Ask helps about opening files using Emacs in WSL2

crotoc · 2022-02-08 16:33
I have setup Emacs in WSL2, and it starts up flawlessly. Now I want to link the Emacs to .txt so that when I click on the txt file, Emacs (of WLS2) will open it for me. I know another option is to install Emacs for windows, but it's very slow. I would like to use a method to open windows files using Emacs in WSL2. Thanks guys!
diagonal-d · 2022-02-08 21:45
You can copy the start code for the wslg emacs from the shortcut mine was C:\\Windows\\System32\\wslg.exe \~ -d Ubuntu-20.04 emacs copy this into a .bat file e.g. wsl\_emacs.bat Right click on a txt file change the app to open (click through some options till you can select another app and the select dialog opens. Select your wsl\_emacs.bat file click OK. Double clicking on a .txt file will open a wsl console then emacs. Not pretty but it does open. One issue you may have is access between wsl2 filesystem (where emacs is running) and the windows filesystem can be slow apparently. I run a windows emacs and a wsl emacs and have found little difference between them (they both run the same init.el and ealry-init.el).
[deleted] · 2022-02-08 21:48
[deleted]
crotoc · 2022-02-09 04:14
This is exactly what I want! I will give it a try! Thanks bro!
thaenalpha · 2022-02-09 04:31
You can try "OpenInWSL" from Msstore.
crotoc · 2022-02-09 04:48
Will have a check as well! Thanks for bringing it up!
Blytheway · 2022-02-13 01:07
what version of emacs are you using?
crotoc · 2022-02-21 03:15
Using version 27 and 26.3
mpersico · 2022-02-25 17:41
How did you set it up? I've got Font 10x20 is not defined.
mpersico · 2022-02-25 18:02
NVM - stupid Xdefaults setting.
crinsane · 2022-05-31 16:39
>C:\\Windows\\System32\\wslg.exe \~ -d Ubuntu-20.04 emacs I figured that when selecting wsl-emacs.bat as the opening app, emacs pops up but the file content doesn't open. Do you have problem like this? Thanks
crotoc · 2022-05-31 18:54
Thank u/diagonal-d. After exploration I finally solve the problem and the speed is acceptable. The bat file is like followling: `@echo off` `setlocal EnableDelayedExpansion` `set "X="` `set X=%~1` `if defined X (` `set "X=!X:\=/!"` `set "X=!X:C:=/mnt/c!` `bash -lic 'emacs "!X!"'` `) else (` `bash -lic 'emacs'` `)` X is the file passing to the bat. If X is empty, just open emacs, or open X with emacs instead. Because the path in windows are different from in WSL, so I format the path of windows to wsl using several lines. To make it fancier, I use [Bat to Exe Converter V 3.0.8](https://github.com/tokyoneon/B2E) to convert the dat to exe. Add an icon and exe-format is set to be "Invisible" to hide shell console that is promoted by running a bat script. Please note that my script works under wslg (wsl-gui). Hope this help!
crotoc · 2022-05-31 19:01
By the way, you can use terminator/doublecmd by the same meaning, i.e. write a batch script: `@echo off` `bash -lic 'terminator`' convert to exe