Subject: Re: bug#65886: 29.1; pgtk emacs should assume --no-window-system when there is no window system

From: Po Lu <[email-masked]>
Date: Tue, 12 Sep 2023 15:43:59 +0800

"Trent W. Buck" <[email-masked]> writes:

> What I actually want is for "git mergetool" to open emacs in my terminal, not popup a GUI window.
> Because teaching /usr/lib/git-core/mergetools/emerge to (sometimes!) pass "-nw" to emacs seemed fiddly,
> I used to achieve this via a quick-and-dirty hack:
>
>     DISPLAY= git mergetool
>
> Right now this doesn't work in my pgtk emacs:
>
>     bash5$ DISPLAY= WAYLAND_DISPLAY= emacs -Q
>
>     (emacs:3064023): Gtk-WARNING **: 14:59:49.225: cannot open display: 
>
>     bash5$ env -i TERM="$TERM" emacs -Q
>
>     (emacs:3064224): Gtk-WARNING **: 15:00:32.320: cannot open display: 
>
> If there is no valid GUI and there is a valid terminal,
> I want emacs to open in the terminal -- not to error.

Unfortunately, this isn't possible without employing window system
specific APIs, the avoidance of which served as the impetus for the PGTK
port and still remains one of its principal design objectives.  Refer to
bug#63555, which details both the reason the approach taken by the X
port cannot function under PGTK, and why GDK's own initialization
functions are inadequate.

> Non-pgtk GTK emacs does this, i.e. this is a regression/inconsistency.

This is because here, Emacs knows exactly which GDK backend will be
loaded (X11) and what environment variable to check.