![[Home]](https://www.emacswiki.org/images/logo218x38.png)
This page is about different ways to integrate Emacs into MS Windows:
Put the Emacs ‘bin’ folder in the Windows PATH environment variable (right-click Computer, Properties, Advanced, Environment Variables). This also simplifies other methods mentioned on this page (no explicit paths needed then).
Use this code for a desktop/task-bar shortcut. Right-click in a file folder, select New → Shortcut, and enter:
c:\path\to\emacs\bin\emacsclientw.exe -c -n -a c:\path\to\emacs\bin\runemacs.exe
This shortcut will connect to Emacs daemon if it is running, otherwise opens a new frame.
-c tells emacs to create a new frame instead of trying to use an existing frame. -n means no wait - don't wait for the server to return -a EDITOR specifies to the emacsclientw.exe which editor to run if emacs.exe is not running. An empty string starts a new server if needed
This may not work correctly on Windows 7. See MsWindowsSevenProblems
Note: If the path contains a blank (whitespace) things get a little bit more complicated and one should use quotes or use 8.3 filenames (e.g. C:\Progra~1 for C:\Program Files). Also, it works omitting the alternative editor completely. In this case the emacsclient tries to launch a new emacs server anyway:
"c:\path\to\emacs\bin\emacsclientw.exe" -c -n -a ""
On Windows 10 and later pinning shortcut created by installer to Windows taskbar will pin runemacs.exe, when clicked such pin will spawn other process (emacs.exe) and create another un-pinned same-looking icon on taskbar. To avoid this:
1. Remove (unpin) any Emacs pinned icons from taskbar
2. Start Emacs from Start menu (or run runemacs.exe directly)
3. Pin newly created taskbar icon, right-click it and in context menu right-click “emacs” and select “Properties”
4. In shown dialog in Target field replace emacs.exe with runemacs.exe and click Apply
Sorry, but I don’t understand this. Is the problem you cite only for a *“shortcut created by installer”*? If so, what does that mean (what installer; what’s special about such a shortcut)?
I just create a shortcut manually to Z:\Emacs-26.3\bin\runemacs.exe --debug-init (or whatever), and then pin that shortcut to the Task Bar. I have Windows 10, and I have no problem if I do that. – DrewAdams
Do you pin the shortcut (1) by going to Start menu while Emacs not running and right clicking shortcut and selecting “Pin to taskbar”, or (2) directly by running Emacs from that shortcut (no matter if yours or installer but pointing to runemacs.exe) right-clicking icon that it created on taskbar and selecting “Pin to taskbar”?. In case (1) when you click such taskbar pin it will not activate (underline) as Emacs starts but instead create another Emacs icon for emacs.exe on taskbar (problem). In case (2) emacs.exe will be pinned and clicking such pin will activate pin and not create another icon (ok) but will also show command line window (problem). These can be avoided by steps described above on both Windows 10 and 11. Sorry if it’s not clear, English is not my first language.
Did quick search on the Internet and I am not alone who has this problem (and came to this solution): https://www.reddit.com/r/emacs/comments/8b9rvc/windows_emacs_in_taskbar_avoid_having_two_icons/
– blami
I just do the same thing I’ve always done, in previous versions of Windows (back at least through Windows XP). I create a shortcut to `runemacs.exe` in the same folder as that executable. And I pin that shortcut to the task bar. Then I just click that pinned icon to start a new Emacs session.
No matter how many sessions I create, they all get piled onto the same icon that’s created for the sessions (this icon is over to the right - it’s not the icon that’s pinned). Even if I create sessions in other ways than using a shortcut pinned to the task bar, and even if they’re for other Emacs releases, they’re all piled into the same icon (at the right). – DrewAdams
You may want to add a command to “Open in Emacs” when you right click on files in Explorer. There are several solutions to that which you can find here: MsWindowsGlobalContextMenu
NOTE: After following the instructions below, emacs client doesn’t work properly. For example, clicking on a .org file will create a new emacs window, even when one is already running (Windows 10, July 2019, Emacs 26.2).
To open text files with the emacs daemon, run cmd.exe as administrator use the commands and ‘ftype’ and ‘assoc’:
ftype txtfile=emacsclientw -na runemacs "%1" ftype EmacsLisp=emacsclientw -na runemacs "%1" ftype CodeFile=emacsclientw -na runemacs "%1" assoc .txt=txtfile assoc .text=txtfile assoc .log=txtfile assoc .org=txtfile assoc .el=EmacsLisp assoc .c=CodeFile assoc .h=CodeFile
See WThirtyTwoFileAssociations for more info.
This seems to works:
git config --global core.editor "C:/path/to/emacsclientw.exe --alternate-editor='C:/path/to/runemacs.exe' '%*'"
Be sure not to add -n to the command here. A non-blocking editor call will cause Git to fail, since it thinks you entered an empty commit message.
A quick and dirty way to replace all notepad.exe calls from any application (and your file manager) would be to use the Registry:
1. Start regedit.exe
2. Go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion?\Image File Execution Options
3. Add a new key named notepad.exe
4. Add (in there) a new string named Debugger and use this value: emacsclientw.exe -na runemacs.exe -F (requires emacsclientw to be in your PATH)
Note that this will pretty much break the usual -F behavior but it is needed as emacsclientw has no -z parameter (yet).
Check out fakecygpty. This is your best bet to get ‘term’/‘ansi-term’ working with a proper shell on Windows with Win32 Emacs.
You will need Cygwin installed to build it.
Open Windows Explorer with `Win+E’ and navigate to `shell:startup’. Create a new file `StartEmacsServer.bat’ using the right click context menu. Right click this new file, select “Edit”, and insert:
rem Sets HOME for current shell if you haven't set HOME environment variable already set HOME=%APPDATA% del /q %HOME%\.emacs.d\server\* C:\path\to\emacs\bin\runemacs.exe --daemon --chdir %HOME%
‘rem’ is the Windows batch keyword for comments. This script sets a HOME environment variable for the current cmd process, meaning it will not exist beyond the running of the script. It then deletes the folder which contains Emacs server information. ‘/q’ means “quiet”; the user is not prompted whether to delete. You can use double quotes to provide single quotes around the path, in case it contains spaces. Finally, `runemacs.exe’ is called with the ‘--daemon’ flag, starting a background instance. If you want to modify/debug this script, put ‘pause’ at the end and the prompt will remain open.
Double clicking the script will start a new Emacs daemon. To create a new frame, make a shortcut for `emacsclientw.exe’. Right click on the shortcut and select “Properties”. Set the “Target” as:
C:\path\to\emacs\bin\emacsclientw.exe -create-frame
This tells `emacsclientw.exe’ to create a new frame within the Emacs daemon process. If it fails, no alternative editor is to be opened. Use this shortcut as the main entry point to Emacs.
Sometimes it is useful to be able to start up default autonomous copy of Emacs (not client/server), for example if you play with your config file and something gets messed up.
Create a new shortcut to “emacs.exe”. Right click newly created shortcut and choose properties. In target field type: "X:\path\to\emacs\bin\emacs.exe" --debug-init Close properties dialog.
Emacs runs surprisingly well within the Windows command prompt over SSH. I had challenges, however, setting the HOME directory and initializing init.el. Emacs also complained about wanting to use `cmdproxy.exe’. My solution was to create this batch file, place it the default connection directory, and run it immediately on login:
rem EmacsOnSSH.bat rem Sets HOME for current shell; didn't seem to take, but won't hurt to set it set HOME=%APPDATA% rem Set SHELL to the Emacs provided cmdproxy, rather than the default cmd. set SHELL="C:\emacs-27.1-x86_64\libexec\emacs\27.1\x86_64-w64-mingw32\cmdproxy.exe" rem Forced the default directory by first changing dirs cd %APPDATA% rem The init didn't automatically load, regardless of where I started. So, call it explicitly C:\emacs-27.1-x86_64\bin\emacs.exe -nw -load .emacs.d\init.el