Kaz Kylheku
1/5/2016 2:37:00 PM
On 2016-01-05, BartC <bc@freeuk.com> wrote:
> On 05/01/2016 04:59, Kaz Kylheku wrote:
>
>> $ ./txr
>> This is the TXR Lisp interactive listener of TXR 129.
>> Use the :quit command or type Ctrl-D on empty line to exit.
>
> That's interesting. I got reprimanded by Richard Heathfield in c.l.c
> last year for saying that you type Ctrl-D at the 'start' of a line. He
> said that as the line doesn't yet exist, you can't have the start of it.
>
> I wonder if talking about an 'empty' line is any different? He said
> Ctrl-D is something you type /after/ the previous line is completed.
>
> (Anyway I'm now apparently in his killfile because of that disagreement.)
That was likely in relation to the Unix TTY EOF signal. I seem to recall
the discussion. My Ctrl-D is different in that usually it is
the visual edit key for "erase character under the cursor, and shift the
remaining ones left". The exit semantics of Ctrl-D (which is always
Ctrl-D regardless of the EOF character configured in the TTY) only
applies when the edit buffer is completely empty, for the sake of
complying with a common convention.
(I should put in a check to suppress the exit semantics if the last
command was a successfully executed deletion via Ctrl-D, so that if the
user uses keyboard repeat to delete everything in the current line, it
won't exit.)
In the case of canonical Unix TTY input, Ctrl-D (or whatever character
is configured for that role) just means "cause the read system call to
bail immediately, returning whatever characters have been accumulated
into the caller's buffer already".
If this occurs when no characters have been accumulated, then read
returns 0, which looks like end-of-file. Indeed, no line of
input is obtained, since no input is obtained at all.
That doesn't mean that there never existed a line at all! The TTY user
can edit the input line, then backspace over it and issue Ctrl-D. The
process doesn't know about the line, but the line certainly existed in
the operating system kernel.
If Ctrl-D is used in the middle of a line of input, then the
process is resumed with exactly that input coming out of read,
without any terminating newline. This is useful from time to time, like
in interactively testing how some program reacts to the last line of
input not being properly terminated.