The shell takes spaces off both ends of a line, not just the front

Tab completion leaves a space after the word it finished, which is right
when another word is coming. When nothing else was coming, that space
stayed on the end of the line and a command taking a file name looked
for one whose name ended in a space:

  load greet.sbx      loaded, starting at 5000
  load greet.sbx      no such file      (the same line, finished with Tab)

Which took most of the good out of completion, since finishing a name
and pressing Return is the whole of what it is for. The existing tab
tests all typed more characters after completing, so none of them ever
submitted a completed line.

lineTrim already took the leading spaces off for indented blocks, so the
trailing ones come off in the same place, on the whole line, rather than
at each of the dozen commands that take a name. Walking back needs no
guard against running off the front: by then the first character cannot
be a space, and a line that was nothing but spaces has already become an
empty one.

CONSEQUENCE WORTH SEEING: echo no longer prints a trailing space it was
given, which is why cosmosTabPath's recording moved. That is the
conventional behaviour and it means what echo is handed is what somebody
would have typed, but it is a real change and not only a bug fix.

cosmosTrim covers a line completed and run straight away, the same
trailing space typed by hand, spaces at both ends at once, and a line of
nothing but spaces, which still has to do nothing rather than fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-09-05 12:23:28 -04:00
co-authored by Claude Opus 5
parent 8631a78229
commit 35c6708e46
7 changed files with 78 additions and 4 deletions
+4 -1
View File
@@ -169,7 +169,10 @@ skipping happens before names are filled in, so `$whatever` inside a branch nobo
is not a mistake, and a line nobody is running cannot fail.
**Lines may be indented**, which they could not be before there was anything to indent
inside. Leading spaces are taken off before anything looks at the line.
inside. Spaces are taken off both ends of a line before anything looks at it - the leading
ones so that a block can be indented, and the trailing ones because finishing a word with
Tab leaves a space behind it, and a command that takes a file name would otherwise be
looking for one whose name ends in a space.
## Names For Things:
+37
View File
@@ -3282,7 +3282,44 @@ lineTrimEmpty:
SETD.0 CommandLine
RSTA
STA.0
; ---- And the space at the other end, which finishing a word leaves behind ----
;
; Tab completion puts a space after the word it finished, because that is what you want when
; another word is coming. When nothing else is coming, that space stayed on the end of the
; line, and a command that takes a file name looked for one whose name ended in a space:
;
; load greet.sbx loaded, starting at 5000
; load greet.sbx no such file (the same line, completed with Tab)
;
; Which took most of the good out of completion, since finishing a name and pressing Return
; is the whole of what it is for. Taken off the WHOLE LINE rather than at each command that
; takes a name, for the same reason the leading spaces are: there are a dozen of those and
; they should not each have to know.
;
; SAFE TO WALK BACKWARDS WITHOUT A GUARD, and that is worth saying because it looks like it
; is not. Everything above has already run, so the first character is not a space - either
; the line never began with one, or the move loop took them off, or the line was nothing but
; spaces and the empty test below sends it home. So the walk back always meets a character
; that stops it before it reaches the front.
lineTrimDone:
SETD.0 CommandLine
LDA.0
BRA lineTrimEnded ; An empty line has no end to tidy.
lineTrimSeek:
INCD.0
LDA.0
BNA lineTrimSeek ; On the zero that ends the line.
lineTrimBack:
DECD.0
LDA.0
INIB 0x20
XOR
BNQ lineTrimEnded ; Not a space, so this is where the line really ends.
RSTA
STA.0 ; The space becomes the end of it, and the one before may go too.
BRI lineTrimBack
lineTrimEnded:
RET
; DP0 names a line and DP1 a word. Q is zero if the line's FIRST WORD is that word - which