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

**URL:** <https://swi-prolog.discourse.group/t/emacs-not-handling-ctrl-d-correctly-for-closing-user/3669>\
**Category:** Tools\
**Tags:** emacs\
**Created:** [March 2, 2021, 10:54am UTC](https://swi-prolog.discourse.group/t/emacs-not-handling-ctrl-d-correctly-for-closing-user/3669 "2021-03-02T10:54:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dstrohmaier](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dstrohmaier/32/3339_2.png) [@dstrohmaier](https://swi-prolog.discourse.group/u/dstrohmaier)\
**Post date:** [March 2, 2021, 10:54am UTC](https://swi-prolog.discourse.group/t/emacs-not-handling-ctrl-d-correctly-for-closing-user/3669/1 "2021-03-02T10:54:52Z")

</div>

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:

```prolog
?- [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](https://stackoverflow.com/questions/52412614/how-to-send-ctrld-into-emacs-eshell)  
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)

```prolog
?- [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.

---

<div class="post-metadata">

**Author:** ![mjano314](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/mjano314/32/2621_2.png) [@mjano314](https://swi-prolog.discourse.group/u/mjano314)\
**Post date:** [March 4, 2021, 8:29pm UTC](https://swi-prolog.discourse.group/t/emacs-not-handling-ctrl-d-correctly-for-closing-user/3669/2 "2021-03-04T20:29:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [March 4, 2021, 10:46pm UTC](https://swi-prolog.discourse.group/t/emacs-not-handling-ctrl-d-correctly-for-closing-user/3669/3 "2021-03-04T22:46:49Z")

</div>

^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.
