cynede / gentoo-wsl

WSL Overlay (Running Gentoo on Windows Kernel)
55 stars 2 forks source link

Tips for emacs #3

Open sunjoong opened 7 years ago

sunjoong commented 7 years ago

USE flags for emacs

Emacs works well unless using gtk3 and dbus. I have no idea why gtk3 making problem but it is. So, it's my woking USE flags;

SUNJOONG-DESKTOP ~ # emerge -pv emacs
[ebuild   R    ] app-editors/emacs-24.5-r3:24::gentoo  USE="X gfile gtk inotify libxml2 png ssl svg toolkit-scroll-bars xft xpm zlib -Xaw3d -acl -alsa (-aqua) -athena -dbus -games -gconf -gif -gpm -gsettings -gtk3 -gzip-el -hesiod -imagemagick -jpeg -kerberos -livecd -m17n-lib -motif -pax_kernel (-selinux) -sound -source -tiff -wide-int" 0 KiB
SUNJOONG-DESKTOP ~ #

bash.exe shortcut

There is a shortcut of bash.exe named "Bash on Ubuntu on Windows" in your Start Menu like "C:\Users\sunjoong\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" directory. You know, sunjoong is my user name, so do with your username in your case. Change the shortcut name to "Bash on Gentoo on Windows" for looking good.

The target attribute of that shortcut is C:\Windows\System32\bash.exe \~

Append "-l" option like this; C:\Windows\System32\bash.exe \~ -l

Then, \~/.bash_profile file will work.

UPDATE: I heard bash.exe will launch bash login shell starting 16184, https://github.com/Microsoft/BashOnWindows/issues/2067#issuecomment-299619151 ; so you might not need to append -l option after then.

\~/.bash_profile

This is my \~/.bash_profile; SUNJOONG-DESKTOP \~ # cat \~/.bash_profile # This file is sourced by bash for login shells. The following line # runs your .bashrc and is recommended by the bash info pages. if [[ -f \~/.bashrc ]] ; then . \~/.bashrc fi

/mnt/c/Windows/System32/tasklist.exe /fi 'imagename eq vcxsrv.exe' \ 2> /dev/null \ | grep 'No tasks are running' > /dev/null if [ $? -eq 0 ]; then /mnt/c/Program\ Files/VcXsrv/vcxsrv.exe \ :0 -multiwindow -clipboard -wgl &> /dev/null &disown fi export DISPLAY=:0 SUNJOONG-DESKTOP \~ #

I had installed VcXsrv Windows X Server. My \~/.bash_profile check whether X server be running and run X server if not running.

runemacs.exe

I'm using a modified runnig emacs wrapper. This is a source - runemacsWSL.zip. This is a compiled binary - runemacs.zip. It acts like "bash.exe -l -c emacs". So, I can run emacs by mouse double-clicking with this wrapper and \~/.bash_profile.

UPDATE: https://github.com/Cynede/gentoo-wsl/issues/3#issuecomment-296996400 UPDATE: https://github.com/Cynede/gentoo-wsl/issues/3#issuecomment-299623300

Microsoft Edge as emacs browse-url-browser-function

This is a part of my emacs init file;

(defun browse-url-edge (url &optional new-window)
  (shell-command
   (concat "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe "
           "start microsoft-edge:'\\\"" url "\\\"'")))

(custom-set-variables
 '(browse-url-browser-function 'browse-url-edge)
 '(inhibit-startup-screen t))

(setq default-directory "/mnt/c/Users/sunjoong/Desktop")

You could notice browse-url-edge function and browse-url-browser-function . That makes set external web brower to Microsoft Edge. The inhibit-startup-screen and default-directory make emacs looking other windows program. You know, sunjoong is my user name, so do with your username in your case.

cnd commented 7 years ago

awesome, maybe we should use github wiki with links in README?

sunjoong commented 7 years ago

@mpkh - good. sure.

sunjoong commented 7 years ago

Two days aga, I had modified runemacs.exe originally from emacs package. With that and ~/.bash_profile trick, I could run emacs by mouse, so good. But, what if other program like xterm?

I wrote a vbscript code for more general purpose.

It check and run VcXsrv Windows X Server and set DISPLAY environment variable, so ~/.bash_profile trick does not be needed.

Make a shortcut of this code with attribute target like this;

XRun.vbs emacs

XRun.vbs is this code and emacs is for running. If you want to run xterm, do like this;

XRun.vbs xterm

Code of XRun.vbs is;

Option Explicit

Dim Object
Dim Args
Dim i

Const VcXsrv = "C:\Program Files\VcXsrv\vcxsrv.exe"

Args = ":0 -multiwindow -clipboard -wgl"
Set Object = GetObject ("winmgmts:")
for each i in Object.InstancesOf ("Win32_Process")
  if StrComp (i.ExecutablePath, VcXsrv, 1) = 0 then
    Args = ""
    exit for
  end if
next
Set i      = Nothing
Set Object = Nothing

Set Object = CreateObject ("Shell.Application")
if StrComp (Args, "") then
  Object.ShellExecute VcXsrv, Args, "", "open", 0
end if

Args = "~ -c 'export DISPLAY=:0;"
for i = 0 to WScript.Arguments.Count -1
  Args = Args & " " & WScript.Arguments (i)
next
Args = Args & "'&"

Object.ShellExecute "bash.exe", Args, "", "open", 0
Set Object = Nothing

WScript.Quit
sunjoong commented 7 years ago

Today, I found it cannot launch browse-url-edge elisp function with above XRun.vbs code. I modified runemacs.c again not to need ~/.bash_profile trick. New runemacs.exe check and launch VcXsrv Windows X Server, and then launch emacs with DISPLAY=:0 by itself.

New source code is runemacsWSL.zip, and new pre-compiled binary is runemacs.zip.