Skip to content

Instantly share code, notes, and snippets.

@cdaven
Last active December 17, 2023 11:33
Show Gist options
  • Star 39 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save cdaven/135298087efb0ffc5dab93fd56249b38 to your computer and use it in GitHub Desktop.
Save cdaven/135298087efb0ffc5dab93fd56249b38 to your computer and use it in GitHub Desktop.
Setting up Spacemacs on Windows 10

Install Emacs First

Download emacs-w64 and extract somewhere, e.g. a tools or apps folder like C:\Users\<user>\tools\emacs.

Select Emacs' Home

Emacs and many other applications store its configuration in the user's "home" folder. Translated directly from the Unix world, that is %UserProfile% (C:\Users\<user>), but Windows prefers %AppData% instead (C:\Users\<user>\AppData\Roaming).

For simplicity's sake, override this by specifying the HOME environment variable explicitly. Emacs and some other applications (e.g. MinGW) lets this override the default.

I recommend setting HOME to %UserProfile%, and installing Spacemacs there. This is not what Microsoft/Windows recommends, but it works unless you want to use a "roaming" profile.

Note that this could mean that you must copy configuration files for other applications from %AppData% to %UserProfile%.

Install Spacemacs

Open a command prompt and install Spacemacs:

cd %HOME%
git clone https://github.com/syl20bnr/spacemacs .emacs.d

Install font

Spacemacs uses the font Source Code Pro by default, which can be downloaded from Google Fonts. Extract the TTF files, select them in Explorer, right-click and select "Install".

Alternatively, use another font by editing your .spacemacs file:

dotspacemacs-default-font '("Consolas"

Install dependencies

Install some dependencies via Chocolatey:

choco install pt diffutils zip

(Note that the font Source Code Pro is also available via Chocolatey, but it didn't work as well as installing it manually from Google Fonts.)

Running Emacs

Emacs is an oddball on Windows, but you can make it work with a few environment variables:

Variable Value
HOME %UserProfile%
EMACS_SERVER_FILE %HOME%\.emacs.d\server\server
ALTERNATE_EDITOR The full path to emacs\bin\runemacs.exe (including the filename)

They are not always necessary, but unless you set them, Emacs will behave strangely from time to time.

From the Start Menu

Create a start menu shortcut in %AppData%\Microsoft\Windows\Start Menu with this "Target": %ALTERNATE_EDITOR% (which points to runemacs.exe from above).

You can set "Start in" to a folder where you keep most of your documents or files, for convenience.

From the Task Bar

Start Emacs and right-click the icon in the task bar and "pin it". Then right-click the icon again, and right-click the Emacs icon in the popup menu and select Properties.

Change the "Target" filename to runemacs.exe, and change the "Start in" to a folder where you keep most of your documents or files, for convenience.

"Open With" Emacs

Right-click a file that you want to open with Emacs, and select Open With, Choose another app, then Look for another app on this PC. Navigate to emacs\bin\emacsclientw.exe and select it.

Then, open the Registry Editor and edit the default string value in HKEY_CURRENT_USER\Software\Classes\Applications\emacsclientw.exe\shell\open\command. Insert the -n option between emacsclientw.exe and "%1". (This will avoid the question "This Emacs session has clients; exit anyway?" when exiting.)

Non-ASCII Characters in Paths

Emacs will not work well if your paths contain non-ASCII characters, either in your environment variables, or the paths to the files that you open.

If e.g. your username, like mine, contains non-ASCII characters, a simple workaround is to create a directory junction with ASCII only. Open a command prompt as Administrator.

cd \Users
mklink /j Andre André

This example lets you use C:\Users\Andre interchangeably with C:\Users\André.

Upgrade Spacemacs

Open a command prompt and pull the latest Spacemacs:

cd %AppData%\.emacs.d
git pull

Restart Emacs.

@dalanicolai
Copy link

dalanicolai commented Jul 28, 2021

Hi! Thanks for this guide. I would just like to comment that I have tried to get Emacs on windows in 3 different ways:

Your way (described here): things worked differently than on GNU/linux (i.e. the package manager chocolatey. I was not aware of chocolatey, but I wonder if it provides e.g. djvulibre for djvu mode). I don't remember exactly, but I do remember that getting pdf-tools to work, and installing an alternative for the locate command took all quite some extra work.

Then I tried several the VM approaches (i.e. hyper V and Virtualbox). For that hyper V was a pain(/was impossible to make it interoperate/communicate with Windows).
Virtualbox worked great, but was slow and my CPU was constanly above 90%.

Finally I tried with WSL(1 and 2) i.c.w. the vcxsrv x-server using this guide. Installation was a breeze, everything works very fast and exactly like on real linux (pdf-tools and djvu-mode work exactly like on linux). Interoperability is perfect (copy paste and reading windows folder from Emacs etc.). Therefore I would really recommend to go for the WSL approach.

@Jeff-avatar
Copy link

Hi @dalanicolai, I tried your suggestion. It worked great with WSL1 except for one thing: I would like to use org-download to insert screenshots to org-mode documents, but the issue is that I cannot launch a Linux screenshot application to do that since there is no Linux GUI (See https://zzamboni.org/post/how-to-insert-screenshots-in-org-documents-on-macos/ for details about how to use org-download on Mac). Any ideas to accomplish that? Thanks.

@dalanicolai
Copy link

@Jeff-avatar I am not sure, as I never use Windows (just I have installed Emacs there once for some reason). Anyway, I guess you can just use some windows command line screenshot tool (e.g. this one), by customizing org-download-screenshot-method. The command takes some /clip argument (or whatever it is called), so I guess you probably have to check the formatting e.g. by edebugging org-download-screenshot. Anyway, I would first simply try to make a screenshot using the shell-command function, to see whether simply using C:\Windows\System32\SnippingTool.exe /clip works already, or you have to adapt that command somewhat. Good luck!

@Jeff-avatar
Copy link

@dalanicolai Thanks very much. I followed your suggestion and figured out a way to do that. The following is my code snippet,

(defun my-org-screenshot ()
  (interactive)
                                        ; create .pic directory if does not exist.
  (unless (file-exists-p "./pic")
    (make-directory "./pic"))
  (setq filename
        (concat
         (make-temp-name
          (concat (buffer-file-name)
                  "_"
                  (format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
  (setq filename (concat "./pic/" (file-name-nondirectory filename)))
  (shell-command "powershell.exe snippingtool /clip")
  (shell-command (concat "powershell.exe -command \"Add-Type -AssemblyName System.Windows.Forms;if ([System.Windows.Forms.Clipboard]::ContainsImage()) {\\$image = [System.Windows.Forms.Clipboard]::GetImage();[System.Drawing.Bitmap]\\$image.Save('" filename "',[System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'clipboard content saved as file'} else {Write-Output 'clipboard does not contain image data'}\""))
  (insert (concat "[[file:" filename "]]"))
  (org-display-inline-images))

BTW: I also borrowed some code from here, https://gist.github.com/cdaven/135298087efb0ffc5dab93fd56249b38

@dalanicolai
Copy link

dalanicolai commented Jul 26, 2022

@Jeff-avatar Haha, I see you have just created your own screenshot command. Well, that is a perfect option of course also... looks good!

Is that link supposed to link to this post, b.t.w?

@centuryx476
Copy link

Hello,
I followed this step by step and it worked like a charm.
The version number of spacemacs is 0.999.0@28.2
But isn't the correct version of spacemacs 0.200.13 ?
What am I doing wrong ?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment