Emacs can't start server - windows

I try to start emacs server on a Windows 8 machine. I downloaded vanilla emacs, and run it using runemacs.exe. Then I run M-x server-start and the execution of this command takes about 3 minutes, after that there's a ~/.emacs.d/server/server file with the following contents:
127.0.0.1:65118 5868
r#Twzr]X-VjCB`g\&t;U1<bj3X]}6!8XUz~P;{q9'AIj322!w0O1XK[/K4v>ZOK*
and emacs server doesn't run: when I try to open a file with emacsclientw.exe it says no server.
Apparently emacs tried to start a server but failed. I'm the owner of the ~/.emacs.d folder.

You're using a non-standard socket directory. By default, the sockets are stored in /tmp/emacsXYZQ (where XYZQ is a number). emacsclient cannot be expected to know where you put the sockets, so you need to tell it (if it's not the usual place). You can do this with the -s command.
emacsclient -s ~/.emacs.d/server/server
Normally, you'd make this more convienient by adding
EMACS_SERVER_FILE=~/.emacs.d/server/server
to your ~/.profile and using emacsclient normally, but I'm not sure what the windows analog of that would be.
references:
this SO question
emacsclient options docs

Related

WSL (Ubuntu): how to open localhost in browser from bash terminal

I am trying to open http://localhost in (any) browser from WSL bash terminal.
So far I have tried:
How can I open Google Chrome from the terminal with the URL "localhost:3000"?
"Couldn't find a file descriptor referring to the console" on Ubuntu bash on Windows
How to mention C:\Program Files in batchfile
No luck in setting up BROWSER variable for xdg-open, it responds to xdg-open http://localhost with /usr/bin/xdg-open: 851: /usr/bin/xdg-open: /c/"Program: not found.
I have tried escaping with \ and ^. Using %ProgramFiles(x86)% and ofcorse "Program Files (x86)". More or less it is the same answer every time... Any ideas how to set a work flow for opening browser in WSL?
So far I've ended up with:
/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe localhost
But I am looking for more elegant solution.
You can invoke the Windows command line from Bash and use Windows file association to open URL with the default Windows browser.
To do so just type in Bash:
cmd.exe /C start http://localhost
In my case this loads localhost in Chrome, note that the full URL is necessary for Windows to decide what to do.
This is similar to what open does in MacOS, hence you may find useful to directly alias the command and use it also for other type of files:
# add this to .bash_aliases
open='cmd.exe /C start'
Now you can open URL or open file.pdf directly from WSL.
Note: since you are simply redirecting commands to cmd.exe, it needs to have access to the file your working with. As a consequence the above solution will work when you find yourself in the Windows file system, but probably will fail when you are working with files in Linux partition (i.e. in the tmp or in the bin folder). This probably has been fixed in the new version of the WSL but I have not tested it.
You are almost there. Just add an alias for the windows chrome executable
http://www.linfo.org/alias.html
alias chrome="/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"
Now you can simply run chrome localhost and open chrome in any web location you desire.
To open localhost in browser from bash terminal, you need to configure wsl so that it defaults to whatever browser has been set as default in your windows 10 system.
You can do this by using some tools from wslu ("A collection of utilities for WSL").
For this purpose you need.
wslview (-u, --unregister "remove wslview as the default WSL web browser.
-r, --register "register wslview as the default WSL web browser.)
wslpath (-a "force result to absolute path format",
-u "translate from a Windows path to a WSL path (default)")
You need to register your preferred browsers like this...
For Google Chrome:
wslview -r $(wslpath -au 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')
For Microsoft Edge:
wslview -r $(wslpath -au 'C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe')
Now you can open localhost as x-www-browser localhost:8080 or www-browser localhost:8080 and x-www-browser or www-browser will default to whatever is your current windows 10 default browser provided it has been registered as described above.
Do not forget to indicate the port; localhost alone did not work for me.
To unregister any browser just change the -r flag to -u.
Have a look at wslview help: info wslview <enter> in the wsl terminal
and wslpath <enter> for help with wslpath.
Install wslu (A collection of utilities for WSL) https://github.com/wslutilities/wslu#feature and then add these two lines to your shell's RC file, e.g. .bashrc or .zshrc.
export DISPLAY=:0
export BROWSER=/usr/bin/wslview
You can set the BROWSER variable as you have done . But xdg-open won't work in WSL as the
xdg-openscripts are setup to work with unquoted environment variables ( in which case ,
the path breaks due to spaces in the pathname ).
You can use the wsl-opennpm utility to do the same for WSL .
Once you have npm installed , install wsl-open utility :
sudo npm install -g wsl-open
To open any URL with default Windows Browser :
wsl-open http://google.com
You can also set wsl-open as default program for a file type in WSL :
wsl-open -w // sets wsl-open as the Shell Browser
Then you can use the standard xdg-open for URLs as well with default windows browser :
xdg-open http://google.com
I created a script that basically forwards xdg-open to powershell -c start
Not tested much though.
sudo tee /usr/local/bin/xdg-open <<EOF
#!/bin/sh
powershell.exe -c start "'\$#'"
EOF
sudo chmod +x /usr/local/bin/xdg-open
Cheers
Oliver
Came across this article that worked for me:
https://towardsdatascience.com/running-jupyter-notebook-on-wsl-while-using-firefox-on-windows-5a47ebfae4c1
In short:
Step 1 - Generate config for Jupyter Notebook:
jupyter notebook --generate-config
Step 2 - Edit the config file using "nano" or other editor
The config fileshould be under your home directory under ".jupyter" folder:
~/.jupyter/jupyter_notebook_config.py
Step 3 - Disable launching browser by redirecting file
First comment out the line, then change True to False:
c.NotebookApp.use_redirect_file = False
Step 4 - add a line to your .bashrc file to set the BROWSER path
export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
For me it was Chrome under my Windows Program File. Otherwise any linux installation under WSL doesn't have a native browser to launch, so need to set it to the Windows executable.
Step 5 - restart .bashrc
source .bashrc
That should work!
https://github.com/microsoft/WSL/issues/3632#issuecomment-690061348
export BROWSER='eval "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"'
xdg-open https://google.com # nice work
solved the spaced path problem.
it worked for me.
Now you can simple use :
sensible-browser http://www.google.com
it already comes with wsl and it opens the default browser in windows
ps: you can also use wslview . to open the file explorer from the bash terminal
i'll give you a suggestion, it could be opened via visual studio code in wsl. And install the live server plugin.
Ok so first of all, I don't use windows anymore so I can't post a full solution that I've personally tested, but back when I did use windows, I use to do this and it worked. (This should probably be a comment, but a while back I deleted some unaccepted answers and lot the associated reputation :/)
Solution:
Don't try to launch your windows programs from inside WSL, instead install the linux version of the program and an X server, such as Xming. Here is an example tutorial for forwarding X apps back to Xming on windows.
Summarized, install Xming (on Windows). Then export the DISPLAY variable:
export DISPLAY=:0
Install google-chrome inside WSL and launch it via the CLI. It should show up on your desktop.
Note: There's also a way to use PuTTY alongside XMing for remote viewing, but you'll need to disable Windows firewalls and install the full openssh-server inside WSL first.

Opening Cygwin with Windows bat file and running script file

I require a tunnel between my windows machine to a UNIX server and wish to automate the process so that on startup the tunnel will be generated for me.
I installed Cygwin with ssh and autossh to connect to the remote server, built up the connection manually, and have confirmed that the connection works. The process involves 3 commands, which isn't a lot but something that would be great to have automated.
After creating a .sh script file, which includes my autossh connection commands, and saving it using Notepad ++ as a UNIX document (to avoid any potential conflicts regarding the file ending), I can navigate to this script in Cygwin and call bash script.sh. After which the connection is made and I can work on my server.
My problem comes when creating my bat file:
start /d "C:\cygwin\bin\" mintty.exe "C:\Users\user\Documents\Dev\" script.sh
The first part up to and including the .exe file works to open the Cygwin window, but I have been unsuccessful in feeding the script into it. I even tried including a --bash command before referencing the script file as follows, but I received an error that the command is unknown:
start /d "C:\cygwin\bin\" mintty.exe --bash "C:\Users\andrew\Documents\Development\" tunnel.sh
Does anyone know if and how it is possible to open a Cygwin window and call a script file within this window? This is my first time creating a bat file, so I hope this is perhaps a newbie problem that no one even bothers to post a solution online for...
you don't need start.
assuming your Cygwin is in C:\cygwin
you need just:
chdir c:\cygwin\bin
mintty /usr/bin/bash -l -c /cygdrive/c/Users/user/Documents/Dev/script.sh

emacs server file empty after starting emacs server

I am on OSX, and I have Emacs 24.5 for Mac.
I setup the server path, and start the server in my init.el:
(setq server-socket-dir "~/.emacs.d/server")
(server-start)
but when I run emacsclient somefile, I have this error:
emacsclient: can't find socket; have you started the server?
To start the server in Emacs, type "M-x server-start".
emacsclient: No socket or alternate editor. Please use:
--socket-name
--server-file (or environment variable EMACS_SERVER_FILE)
--alternate-editor (or environment variable ALTERNATE_EDITOR)
I then searched around and non works for me. I then dig into the server file which is ~/.emacs.d/server/server. and I found it is totally empty...
I believe that is the reason thatemacsclient` cannot find the server, any one had similar and knows how to solve it?
thanks
U found the issue, the emacsclient I used is the osx's own copy at usr/bin/emacsclient, not the one with the emacs 24.5
I add the line below to my .profile and works now
alias emacsclient="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"

emacsclient unable to find emacs server

I have this setup for emacs on my Mac.
1. Downloaded the distro from http://emacsformacosx.com/.
2. Followed the tips here http://emacsformacosx.com/tips to set up emacs and emacsclient appropriately.
However the following sequence of steps does not work for me:
1. emacs filename - opens up the file
2. emacsclient -n filename - gives me an error saying that I have not started up the server. But I do have (server-start) in my .emacs file. So I am not sure why I am getting this error.
Nevertheless, I did C-x restart-server in the emacs window and then tried to use emacsclient to attach to it (to open another file) but I still get the same error.
Other things I have tried:
1. Added (setq server-socket-dir (format "/tmp/emacs%d" (user-uid))) and say that the server was starting up in the /tmp location when I launch emacs.
2. Tried various args for emacsclient (new frame, attach to existing frame etc). All give me the same error.
My guess is that emacsclient is unable to find the server I have started up. But I am not sure how to confirm this and/or how to fix it.
Any ideas?
Thanks.
So turns out that adding the line specifying the socket was a mistake. Removing it worked for me and emacsclient was able to find the emacs server just fine.
Another way I tested it was leaving the socket line in and then using the -s option with emacsclient to connect to that specific location (/tmp/emacs501/server) and that worked too.

How to start GNU Octave with GUI through Cygwin from a desktop icon?

Since GNU Octave comes wit a GUI since versions 3.8.0, I thought I should check it out.
So since I run Windows and could only find Octave 3.8 for Cygwin, I installed Cygwin and the packages octave, xinit, xlaunch and gnuplot (according to this page, but I don't know if all those packages are needed).
Then, when trying to start Octave with the GUI from Cygwin with octave --force-gui, I initially got the error message
octave: X11 DISPLAY environment variable not set
and Octave would start in console mode. So I found this page, which told me to run
echo "export DISPLAY=:0.0" >>~/.bash_profile
from Cygwin, to permanently get rid of the error message, which worked. However, then I instead got this error message:
octave: unable to open X11 DISPLAY
The same page also said that you have to run the X Server by going to Start -> Cygwin-X -> XWin Server. That worked, but since I don't want the xterm terminal to start since it is not needed, I found this page which told me to run
touch ~/.startxwinrc
from Cygwin to create an empty .startxwinrc file, to prevent the xtrem terminal from starting by default, which worked. The same page also mentioned that the X Server can be started directly from Cygwin with the command startxwin.
So, now I can start Octave with the GUI from Cygwin, simply by running
startxwin
octave --force-gui
However, I would like to just be able to double click on a desktop icon to get everything up and running.
So, to my question: Can I somehow put this in a script file, which when I run it, will be opened in Cygwin so that the commands in the script file will be run in Cygwin? And is there some way to automatically close the X Server after Octave has terminated? I've tried writing a file octave.bat, which starts Cygwin and gives a second batch file as argument, which in turn contains the commands I want to execute. But when I run the first script, I just get bombarded with command prompts (not Cygwin prompts), and the all say
'startxwin' is not recognized as an internal or external command, operable program or batch file.
Why is the second script not opened in Cygwin, and how can I achieve what I want as simply as possible?
Please grab Octave from here: http://mxeoctave.osuv.de/
The installer should configure everything for you.
GNU Octave offers now Windows binary itself. Go to ftp://ftp.gnu.org/gnu/octave/windows/
You have to put
c:\cygwin64\bin\mintty.exe /bin/sh -lc 'startxwin /bin/octave --force-gui'
in your windows batch file (please adapt the Cygwin path to your settings). That worked fine for me.
The call
c:\cygwin64\bin\bash --login -c "startxwin /bin/octave --force-gui"
did open Octave as desired but the GUI seemed to have response issues to the keyboard and froze after clicking into the editor.
I don't have any of the those commands installed with my Cygwin installation, so I can't test this by trying using the following an .bat file on your desktop:
c:\cygwin\bin\bash --login -c "startxwin octave --force-gui"
Replace c:\cygwin with the directory where you installed Cygwin.
If this leaves a console window on the screen try doing:
c:\cygwin\bin\bash --login -c "run startxwin octave --force-gui"

Resources