rwallace
rwallace

Reputation: 33465

Output only one blank line

fresh-line outputs a newline only if we are not already at start of the line, in other words goes to the next line but never produces a blank line, in other words outputs a maximum of one consecutive newline character.

I need a function that outputs a blank line only if we have not just output one already, in other words outputs a maximum of two consecutive newline characters.

Or put another way, I'm looking for an idempotent blank-line function, one which will output exactly one blank line even if called several times.

What's the best way to do this?

Upvotes: 0

Views: 145

Answers (1)

Renzo
Renzo

Reputation: 27424

If I understand correctly your question, I think you can use the following property of fresh-line (see the manual):

fresh-line returns true if it outputs a newline; otherwise it returns false.

to define something like:

(defun my-fresh-line ()
  (unless (fresh-line)
    (terpri)))

If, on the other hand, you want always a blank line after the current written text, be it terminated with a new line or not, you can define something like:

(define blank-line ()
  (fresh-line)
  (terpri))

and then call it after the current output.

Upvotes: 1

Related Questions