Emacs not handling ctrl-d correctly for closing [user]

I’m using: GUI Emacs version 27.1 (SWI-Prolog version 8.2.1) on Windows.

I want to use the [user] pseudo-file but have a problem exiting it without killing the whole Prolog process. Pressing ctrl-d kills the whole Prolog process (if I do it in a new line after the clause, in the same clause I get an emacs “End of Buffer” error).

An example looks like this:

?- [user].
|: food(apple).
|: 
% user://1 compiled 0.00 sec, 1 clauses
true.

?- 

% halt

Process prolog finished

As you can see, pressing ctrl-d closes the pseudo-file, but then goes a step further and halts the prolog process, which of course defeats the whole point.

I tried the solutions from here: How to send ctrl+D into Emacs' Eshell? - Stack Overflow
and the ctrl-q option leads to the special character to be shown in the buffer but not closing the pseudo-file (until I hit the ctrl-d without anything)

?- [user].
|: food(apple).
|: ^D
|: 
|: 
|: 
ERROR: user://1:11:0: Syntax error: Unexpected end of file
|: 
% user://1 compiled 0.02 sec, 1 clauses
true.

?- 

% halt

Process prolog finished

I also tried whether this error happens on the WSL, and it does not.

You can leave “user mode/module” (don’t know the proper name) by writing end_of_file. as the last line.

^C ^D (ctrl-c ctrl-d) works for me on Ubuntu when I run swipl under the emacs shell. When I use emacs under Windows (or with the Linux Subsystem), this often does one exit too many - exits swipl and also exits the emacs shell.