- Emacs windows emacs file
- Emacs in Microsoft Windows FAQ
- Where to download emacs for Windows?
- Where is emacs’s init file?
- How to list environment variables?
- How to Set Environment Variable?
- Create a Environment Variable HOME
- Create a Emacs Init File
- How to find out if emacs init is loaded?
- How to Start Emacs by Command Line?
- How to start emacs in graphical user interface?
- How to start emacs with default dir at home dir?
- When i type Ctrl+Space, Windows switches me to other language input. What to do?
- When i type Ctrl + Alt + s , HP System info came up. How to disable that?
- How to run Bash shell or PowerShell inside emacs?
- Setting Environment Variable for Emacs Only
- Install Linux Tools
- Emacs: Init File Tutorial
- What’s Init File
- Where’s Init File
- Start Emacs Without Loading Init File
- Modify Init File Without Restarting Emacs
- Reload Init File
- Sample Init File
- Emacs Ms Windows Integration
- Run Emacs from a `cmd’ Window
- Create a shortcut
- Right-Click Context Menu
- Create File Associations
- Use `emacsclient’ to edit git commits
- Replace `notepad.exe’ calls
- Workaround to get `term’/`ansi-term’ working with `cmd.exe’ or Cygwin bash
- Run Emacs server automatically at windows startup
- Simple server setup
- Debug Version
- No-Window Mode Over SSH
Emacs windows emacs file
On Windows, the .emacs file may be called _emacs for backward compatibility with DOS and FAT filesystems where filenames could not start with a dot. Some users prefer to continue using such a name due to historical problems various Windows tools had in the past with file names that begin with a dot. In Emacs 22 and later, the init file may also be called .emacs.d/init.el . Many of the other files that are created by lisp packages are now stored in the .emacs.d directory too, so this keeps all your Emacs related files in one place.
All the files mentioned above should go in your HOME directory. The HOME directory is determined by following the steps below:
- If the environment variable HOME is set, use the directory it indicates.
- If the registry entry HKCU\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates.
- If the registry entry HKLM\SOFTWARE\GNU\Emacs\HOME is set, use the directory it indicates. Not recommended, as it results in users sharing the same HOME directory.
- If C:\.emacs exists, then use C:/ . This is for backward compatibility, as previous versions defaulted to C:/ if HOME was not set.
- Use the user’s AppData directory, usually a directory called AppData under the user’s profile directory, the location of which varies according to Windows version and whether the computer is part of a domain.
at the beginning of a file name is expanded to your HOME directory, so you can always find your .emacs file by typing the command C-x C-f
Emacs in Microsoft Windows FAQ
Where to download emacs for Windows?
Where is emacs’s init file?
You have to create it.
On
%HOMEPATH%\AppData\Roaming\.emacs The .emacs file is old emacs convention. %HOMEPATH%\AppData\Roaming\.emacs.d\init.el The .emacs.d\init.el is modern convention.
The init file may be byte-compiled, ending in .elc . If a fileName .elc exist, emacs will load those instead.
If you have the environment variable named HOME , then it’s at:
HOME should not be confused with HOMEPATH .
- HOMEPATH is standard Microsoft Windows environment variable.
- HOME is standard unix/linux environment variable. (doesn’t exist in Windows by default.)
How to list environment variables?
- Launch PowerShell: press the вќ–В Window key, then type powershell.
- in PowerShell prompt, type Get-Command env:
How to Set Environment Variable?
In PowerShell, run this:
Once you run it, you need to restart PowerShell for the variable to be available in current session, in case you want to start emacs from the PowerShell console.
Create a Environment Variable HOME
I highly recommend you create a environment variable named HOME. Because the HOME directory is heavily used by emacs from the unix convention.
Set the value of environment variable HOME to the same value as the environment variable HOMEPATH. For example: c:/Users/xah/
Create a Emacs Init File
I recommend you create a emacs init file at
How to find out if emacs init is loaded?
Put the following code in your init file:
If emacs starts with honeydew background color, then it’s loaded.
How to Start Emacs by Command Line?
Launch PowerShell , then type for example: C:\Users\xah\Downloads\emacs-27.1-x86_64\bin\runemacs
How to start emacs in graphical user interface?
Go to emacs folder, then in the “bin” dir, then click on file runemacs.exe
How to start emacs with default dir at home dir?
Create a Windows shortcut, then set the “Start in” field.
Windows 10 emacs shortcut
To create a file shortcut:
- Hold Alt then drag that runemacs.exe icon to desktop.
- In the newly created alias icon, right click to open file properties. Then, in the “Start in” field, enter your home directory.
- In the “Target” field, you can add emacs command line options. For example: %home%\apps\emacs-24.1\bin\runemacs.exe -q —load=%home%\ErgoEmacs_dev\init.el —load=%home%\.emacs . Here, i suppress loading init files by -q , but load ErgoEmacs init files, then load my personal init files.
When i type Ctrl+Space, Windows switches me to other language input. What to do?
You can disable the Windows shortcut that switches you among input methods of different languages.
On Microsoft Windows 10:
Press вќ–В Window , then type Advanced keyboard settings
вќ–В Window + i —> —> —> —> —> —> —> —> —> —> —> —> —> Windows 10 advanced keyboard settings 2021-02-03
Click on input language hot keys.
Windows 10 text services input language 2021-02-03
When i type Ctrl + Alt + s , HP System info came up. How to disable that?
How to run Bash shell or PowerShell inside emacs?
By default, the command named shell will run “cmd.exe” inside emacs.
You can use eshell.
For powershell, install the powershell package. [see Emacs: Install Package with ELPA/MELPA]
Setting Environment Variable for Emacs Only
Install Linux Tools
Some of emacs’s features require unix utilities. The essential ones are these:
- Spell checking requires unix ispell
- Checking difference between files require unix diff (called by diff )
- Search string in files requires unix grep (called by grep and others.).
- Listing files with particular suffix requires unix find (called by find-dired ).
There are several ways to get linux tools for Microsoft Windows.
- Install chocolatey package manager. This lets you install many unix command line tools easily. See Xah Windows Setup
- Install Windows Subsystem for Linux (WSL)
For old school you may try Cygwin Installing Cygwin Tutorial
Alternatively, i recommend not rely on unix
You can easily use PowerShell for unix find/grep/diff. See PowerShell vs Bash
If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial
Emacs: Init File Tutorial
This page shows you how to set up many preferences in emacs.
The following assume you are using GNU Emacs version 24.1 or later. [see Emacs 24.1 Features (released 2012-06)]
What’s Init File
Emacs init file is a file emacs loads when it starts up. It is used to customize emacs.
Emacs init file is also known as “dot emacs file”.
Where’s Init File
By default, there is no init file. You have to create the file yourself, and add things to it.
Create a file with this content:
On linux and Mac, by default, emacs look for init file at
/.emacs.d/init.el (this is modern, preferred, since
On Microsoft Windows:
It’s ok to delete your init file and start over. (make a backup first in case you want it back.)
Start Emacs Without Loading Init File
You can start emacs without loading init file. This is useful if you made a syntax error in your init file.
-q or —no-init-file Don’t load your personal init file. -Q or —quick same as —no-init-file —no-site-file —no-splash .
For Microsoft Windows 10, use PowerShell [PowerShell Basics] , or create a alias of the emacs icon, and in properties, set the launch options. [see Emacs in Microsoft Windows FAQ]
Modify Init File Without Restarting Emacs
For simple changes, you do not need to restart emacs.
After you added some new code to init file, just select the region, then Alt + x eval-region . [see Evaluate Emacs Lisp Code]
Then, the code/preference you added will become effective immediately.
Reload Init File
- Alt + x eval-buffer
- Alt + x load-file
Note, some packages, or elisp code, may behave differently when loaded twice. And some code may not work by simply running it by itself (it may assume some other code has been loaded before or after.).
If you have a problem, restart emacs.
Sample Init File
Here’s a sample init file, that sets all basics. No external packages are required.
2011-11-21 Thanks to Ivan Kozik (http://ludios.org/ivank/) for a tip.
If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial
Emacs Ms Windows Integration
This page is about different ways to integrate Emacs into MS Windows:
Run Emacs from a `cmd’ Window
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).
Create a shortcut
Use this code for a desktop/task-bar shortcut. Right-click in a file folder, select New → Shortcut, and enter:
This shortcut will connect to Emacs daemon if it is running, otherwise opens a new frame.
This may not work correctly on Windows 7. See MsWindowsSevenProblems
Right-Click Context Menu
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
Create File Associations
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’ :
Use `emacsclient’ to edit git commits
This seems to works:
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.
Replace `notepad.exe’ calls
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).
Workaround to get `term’/`ansi-term’ working with `cmd.exe’ or Cygwin bash
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.
Run Emacs server automatically at windows startup
The script creates a .bat file in your shell:startup folder. It also adds a line to delete any old emacs server data that may not have gotten cleaned, if the previous shutdown was dirty. Tested on Windows 10.
You can also open Explorer, type in shell:startup in the address bar, and press enter. In this startup folder, create a shortcut by right clicking and selecting new->shortcut. When asked for location, put the following: «X:\path\to\emacs\bin\runemacs.exe» —daemon where you have substituted the proper path to runemacs.exe. This shortcut will run at startup. You can double click on the shortcut to start the Emacs server if it is not already running.
Simple server setup
The following is an adaptation (clarification?) of the above. It’s not clear what language the above script is written in. Rather than create a script to write a 3 line script, this modification gives the smallest setup I could create.
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’ 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. Double quotes are used 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:
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. In the last line of the above script, correct the path to match your shortcut and delete the leading ‘rem’ to have a client frame open on startup.
Debug Version
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.
No-Window Mode Over SSH
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:
This work is licensed to you under version 2 of the GNU General Public License. Alternatively, you may choose to receive this work under any other license that grants the right to use, copy, modify, and/or distribute the work, as long as that license imposes the restriction that derivative works have to grant the same rights and impose the same restriction. For example, you may choose to receive this work under the GNU Free Documentation License, the CreativeCommons ShareAlike License, the XEmacs manual license, or similar licenses.