How to set X-server for emacs/0, edit/1 works on terminal

emacs/0, edit/1 works well in Gnu Emacs ediprolog mode. However, they don’t work on terminal with the message attached below. I am not familiar with setting X-server. Is there any tutoroial enough to fix this.

Thank you for help.

  % swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.11-24-g382b43850-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- emacs.
[PCE fatal: @display/display: Failed to connect to X-server at `': No permission to contact X-server?
* You MUST be running the X11 Windowing environment.  If you are,   *
* check the setting of your DISPLAY environment variable as well    *
* the access rights to your X11 server.  See xauth(1) and xhost(1). *
	in: 	<No exception goal>
Host stack:
 [15] pce_principal:send(@emacs_mark_list/emacs_bookmark_editor, append(new(_15504, dialog)))
 [14] Send-method on @emacs_mark_list/emacs_bookmark_editor: emacs_bookmark_editor->initialise
 [13] '$c_call_prolog'
 [12] pce_principal:new(@emacs_mark_list/emacs_bookmark_editor, emacs_bookmark_editor)
 [11] Send-method on @emacs/emacs: emacs->initialise(@emacs_buffers/dict)
% The following threads wouldn't die: [main]

I have found a solution on the net, though I don’t understand meaning.

open /Applications/Utilities/
ssh -Y <user-name>@<host>
export DISPLAY=:0.0

The above “solution” was my illusion. It did not work.

On, This is OK.
M-x shell
?- emacs.

On terminal. This is not OK.
M-x shell
?- emacs.
(The same error message)

This works ! Put the one line just before the swipl command.

% export DISPLAY=:0.0
% swipl
?- emacs.
1 Like

It worked for me, on Ubuntu 18.0.4, with the DISPLAY value of :0 or :0.0.

So, I tried DISPLAY values of localhost:0.0 and … and I got the same error messages as you got.

I suspect that this has to do with firewall settings (if DISPLAY is :0, it probably does a direct connection and doesn’t use TCP/IP).

The trouble disappeared after deleting all dot files related to X-window setting, and giving Full Disk Access security via Preference Pane on macOS Big Sur.

% echo $DISPLAY

I have looked into my .zshrc file, and found strange line commented out.

# export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0
export DISPLAY=:0.0

Anyway only thing that I can say is that the problem disappeared after trying several things without knowing what I was doing. I am unfamiliar with TCP/IP and network related things. Thanks a lot for your analysis.