help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to *properly* set up Emacs on Windows?


From: Óscar Fuentes
Subject: Re: How to *properly* set up Emacs on Windows?
Date: Tue, 08 Feb 2022 21:02:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Joost <joostkremers@fastmail.fm> writes:

> So, the tl;dr of it is this: What would I need to do to get Emacs
> running on Windows in such a way that easily access utilities such as
> git, diff and hopefully a few more (ag or rg would be nice, gcc and
> libgccjit for when I decide to move to Emacs 28) from within Emacs,
> and also have a graphical Emacs?
>
> The thing that prompted me to post this message is that I ran into the
> issue described here:
>
> https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-05/msg01296.html
>
> In short, the variable `package-gnupghome-dir` is set to
> "c:/Users/joost.kremers/.emacs.d/elpa/gnupg", but when I try to
> install / update packages, I get an error saying:
>
> keyblock resource 
> '/c/Users/joost.kremers/.emacs.d/elpa/c:/Users/joost.kremers/.emacs.d/elpa/gnupg/pubring.kbx':
>  No such file or directory
>
> Note the path.

Yes, it seems that MSYS2 got involved there.

> I can set `package-gnupghome-dir` to
> "/c/Users/joost.kremers/.emacs.d/elpa/gnupg" and that will fix this
> issue, but it doesn't feel like it's the right solution.

Why do you need to set package-gnupghome-dir at all?

> Eli Zaretski's comment in the message I linked to most likely applies
> to my case: "Looks like you are mixing MSYS2 executables and native
> Windows (a.k.a. "MinGW") executables [...]".
>
> To be honest, though, I'm not entirely sure how I got myself into that
> situation. I don't even have a good understanding of MSYS2 and MinGW
> and the differences between them.

MSYS2 is a Cygwin fork, so it is a POSIX emulation system, with some
features to interoperate with the rest of the Windows world. Those
features sometimes help, sometimes hurt.

MinGW produces "native" Windows stuff, therefore MinGW executables, as
any other regular Windows executable, do not understand MSYS2/Cygwin
POSIX paths like your "/c/Users/..." (which actually is a concatenation
of a POSIX path and a Windows PATH, because of the later "c:/Users..".

> I *think* it happened when I tried to use some external utilities from
> within Emacs, mainly git and diff, for which I modified my PATH
> variable.

First of all, undo those changes to PATH and any other change to .emacs
related to Windows support.

MSYS2 provides many utilities as MinGW packages.

For instance, if you installed emacs with:

$ pacman -S mingw-w64-x86_64-emacs

you should install those utilities as:

$ pacman -S mingw-w64-x86_64-grep
$ pacman -S mingw-w64-x86_64-diffutils
$ pacman -S mingw-w64-x86_64-ag

For communicating with ELPA:

$ pacman -S mingw-w64-x86_64-gnupg

For nativecomp support:

$ pacman -S mingw-w64-x86_64-libgccjit

You can use

$ pacman -Ss text

for listing packages that contain "text" on their name or description.

MSYS2 does not provide git as a MinGW package, so you have two options:
either install the MSYS2 package (pacman -S git) or install "Git for
Windows", which provide an almost native port. If the later, the
installer will ask if you want its executables added to PATH, either all
or just git.exe. My advice is to not modify PATH or to add just git.exe.
You can set vc-git-program to where git.exe is and VC will work without
git.exe on PATH.

If you opt for installing git from MSYS2, set vc-git-program. Do not add
MSYS2 /bin directory to PATH.

If you are a Magit user, you can also set magit-git-executable.

Now, a very important detail. Emacs does not follow the Windows
convention of searching executables from the current process' directory.
This means that you must explicitly tell Emacs where to look for all
those utilities. You can add c:\msys64\mingw64\bin (change it if you
installed MSYS2 elsewhere) to PATH or set PATH directly within Emacs:

(let ((dir invocation-directory))
  (setenv "PATH" (concat (getenv "PATH") path-separator dir))
  (setq exec-path (append exec-path (list dir))))))

It is important that emacs.exe bin is listed before any other directory
that may contain conflicting executables, so let's put it at the front
just in case.

You shouldn't need further modifications to your .emacs or to the
environment (*), so ask here before adding something else.

* If you want to use Git through ssh you need to setup a SSH client and
  tell Git about its existence, but that is unrelated to Emacs.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]