{{{  used variables
; let-single-blank   ``. '' is not replaced with ``.  ''
; fill-column        # chars in block
; fill-start         start of lines
; fill-begin         first char in block
; fill-end           last char in block
; fill-x
; fill-count
}}}
{{{  set-fill-column
(deffun set-fill-column
(
  {{{  initalize fil-column to 72 if never used before
  if counter-0 fill-column ( set-counter fill-column 72 ) fi
  }}}
  read-repeat fill-x
  if counter>0 fill-x (
    {{{  use numeric argument if any
    set-counter fill-column 1
    sum-counter fill-column fill-x
    }}}
  ) else (
    {{{  or set fill-end = cursor position
    store-pos fill-x
    set-counter fill-end 0
    sum-counter fill-end fill-x
    O_START_OF_LINE
    store-pos fill-start
    goto-counter fill-x
    inv-counter fill-start
    sum-counter fill-end fill-start
    add-counter fill-end 1
    }}}
    add-counter fill-end -20
    if counter>0 fill-end (
      {{{  use it if greater than 20
      set-counter fill-column 20
      sum-counter fill-column fill-end
      }}}
    ) else (
      {{{  else prompt for the correct value
      prompt-counter fill-end ( "set-fill-column: " )
      if not(counter>0 fill-end) ( message-exit "oops ) fi
      set-counter fill-column 0
      sum-counter fill-column fill-end
      }}}
    ) fi
  ) fi
))
}}}
{{{  inv-fullstop-expand
(deffun inv-fullstop-expand
(
  if counter-0 let-single-blank (
    set-counter let-single-blank 1
  ) else (
    set-counter let-single-blank 0
  ) fi
))
}}}
{{{  splitt-line
(defmac splitt-line
(
  goto-counter fill-end
  O_RIGHT
  set-counter fill-count 0
  sum-counter fill-count fill-column
  {{{  look for a splitt-position
  while and(counter>0 fill-count,not(test-char " )) (
    O_LEFT
    add-counter fill-count -1
  )
  if counter-0 fill-count (message-exit "oops) fi
  }}}
  O_RETURN
  goto-counter fill-begin
  delspaces
))
}}}
{{{  fill-line
(defmac fill-line
(
  {{{  how many chars needed, which position in next line
  O_END_OF_LINE
  store-pos fill-count
  O_LEFT
  if and(counter-0 let-single-blank,test-char ".) (add-counter fill-count 1) fi
  inv-counter fill-count
  sum-counter fill-count fill-end
  set-counter fill-x 0
  sum-counter fill-x fill-count
  sum-counter fill-x fill-begin
  }}}
  O_DOWN
  goto-counter fill-x
  if test-end-line (
    {{{  next line to short
    goto-counter fill-start
    delspaces
    O_DELETE
    "  ;
    O_LEFT
    O_LEFT
    if test-char ". (O_RIGHT " ) fi
    }}}
  ) else (
    {{{  line long enough
    {{{  search splitt positions
    while and(counter>0 fill-count,not(test-char " )) (
      O_LEFT
      add-counter fill-count -1
    )
    }}}
    if counter>0 fill-count (
      {{{  can splitt
      O_RETURN
      goto-counter fill-begin
      delspaces
      O_UP
      goto-counter fill-start
      delspaces
      O_DELETE
      "  ;
      O_LEFT
      O_LEFT
      if test-char ". (O_RIGHT " ) fi
      O_DOWN
      }}}
    ) fi
    }}}
  ) fi
))
}}}
{{{  handle-fullstop-blank
(defmac handle-fullstop-blank (
  if counter-0 let-single-blank (
    {{{  expand ``. '' to ``.  ''
    O_START_OF_LINE
    while not(test-end-line) (
      {{{  maybe expand ``. ''
      if test-char ". (
        O_RIGHT
        if test-char "  (
          O_RIGHT
          if not(test-char " ) (" ) fi
        ) fi
      ) fi
      }}}
      O_RIGHT
    )
    }}}
  ) fi
))
}}}
{{{  fill-paragraph
(deffun fill-paragraph (
  if not(test-text) (message-exit "oops) fi
  if counter-0 fill-column  (set-counter fill-column 72) fi
  {{{  set start/begin/end
  O_START_OF_LINE
  store-pos fill-begin
  O_RETURN
  O_UP
  O_START_OF_LINE
  store-pos fill-start
  O_DEL_LINE
  set-counter fill-end -1
  sum-counter fill-end fill-begin
  sum-counter fill-end fill-column
  }}}
  handle-fullstop-blank
  while test-text (
    {{{  handle one line
    goto-counter fill-begin
    if or(or(test-char " ,test-char ".),not(test-begin-line)) (exit) fi
    goto-counter fill-end
    O_RIGHT
    if test-end-line (
      {{{  fill or leave
      O_LEFT
      if test-end-line (
        {{{  fill it
        O_DOWN
        goto-counter fill-begin
        if or(or(or(test-char " ,test-char ".),not(test-text)),
              not(test-begin-line))
          (exit)
        fi
        handle-fullstop-blank
        O_UP
        fill-line
        }}}
      ) else (
        {{{  line exact ok
        O_DOWN
        handle-fullstop-blank
        }}}
      ) fi
      }}}
    ) else (
      splitt-line
    ) fi
    }}}
  )
))
}}}
{{{  previous-paragraph
(deffun previous-paragraph (
  O_UP
  set-counter fill-x 0
  {{{  skip comments
  while counter-0 fill-x (
    while and(not(test-top),not(test-text)) (
      if test-fold-line (
        O_OPEN_FOLD
        while not(test-end-fold) (O_DOWN)
      ) fi
      O_UP
    )
    O_START_OF_LINE
    if not(test-char ".) (set-counter fill-x 1) else (O_UP) fi
  )
  }}}
  O_START_OF_LINE
  set-counter fill-x 0
  {{{  skip current paragraph
  while counter-0 fill-x (
    if or(or(test-char " ,test-char ".),not(test-begin-line)) (
      set-counter fill-x 1
      O_DOWN
    ) else (
      O_UP
      if test-top (message-exit "oops) fi
    ) fi
  )
  }}}
))
}}}
{{{  next-paragraph
(deffun next-paragraph (
  O_START_OF_LINE
  {{{  skip current paragraph
  store-pos fill-begin
  if test-text (set-counter fill-x 1) else (set-counter fill-x 0) fi
  while counter>0 fill-x (
    goto-counter fill-begin
    if or(or(test-char " ,test-char ".),not(test-begin-line)) (
      set-counter fill-x 0
    ) else (
      O_DOWN
    ) fi
  )
  }}}
  {{{  skip 'comments'
  while counter-0 fill-x (
    while and(not(test-bottom),not(test-text)) (
      if test-fold-line ( O_OPEN_FOLD ) fi
      O_DOWN
    )
    O_START_OF_LINE
    if not(test-char ".) (set-counter fill-x 1) else (O_DOWN) fi
  )
  }}}
  if not(test-text) (message-exit "oops) fi
))
}}}
