ELASTIC-NEWLINE

Proposal

Add an ELASTIC-NEWLINE function. (ELASTIC-NEWLINE [stream]) is like :(CLHS FRESH-LINE) but the other way around: It outputs a conditional newline on the stream that is annulled if the next output on the stream happens to be a newline. More precisely, (ELASTIC-NEWLINE [stream]) causes a newline to be output right before the next character is written on the stream, if this character is not a newline. The newline is also output if the next operation on the stream is :(CLHS FRESH-LINE), :(CLHS FINISH-OUTPUT), :(CLHS FORCE-OUTPUT) or :(CLHS CLOSE). Whether the newline is output eagerly (at the moment ELASTIC-NEWLINE is called) or lazily (right before the next output operation), i.e. whether the visible cursor will be positioned in the new line already or trailing on the previous line, is implementation depedent.

The functionality of ELASTIC-NEWLINE is also available through the :(CLHS FORMAT) directive ~. .

The motivation of ELASTIC-NEWLINE is that it allows for interoperability with code that uses different newline conventions, without adding spurious blank lines. Code that uses (format t "~&A line of text.~.") interoperates nicely with code that uses the convention (format t "A line of text.~%") but also with code that uses the convention (format t "~%A line of text.").

Available in CLISP.


Topics: document proposed extensions to ANSI