README.markdown @ 8524e8a06be6 v1.0.0

Version 1.0.0
author Steve Losh <>
date Sun, 10 Feb 2019 18:15:17 -0500
parents 4bf539032265
children a9ab8d792a4d

   _.─'      ( )      `──.
 ,'    ( )         ( )    `.
;          -------          :
:  ( )    |.......|    ( )  ;
 ╲         -------         ╱
  `.   ( )         ( )   ,'
 ,' `──.     ( )     _.─' `.
;       `───────────'       :
:  ( )    |       |    ( )  ;
 ╲         \_____/         ╱
  `.   ( )         ( )   ,'
    `──.     ( )     _.─'

Bobbin is a simple word-wrapping library for strings in Common Lisp.  It depends
only on `split-sequence`.

It aims to be simple, work nicely for the majority of cases, and degrade
gracefully for edge cases.  It is not particularly concerned with speed — if you
need very high-performance word wrapping Bobbin is not for you.

* **License:** MIT
* **Documentation:** <> (this `README`)
* **Mercurial:** <>
* **Git:** <>


Bobbin's API only has a single function:

    (bobbin:wrap string-or-strings width)

The simplest way to use Bobbin is to pass it a string:

    (bobbin:wrap "hello, world!" 10)

Every line in the string returned by `wrap` will contain at most `width`
characters (not including the newline itself).

### Philosophy

Bobbin will try to break lines at whitespace.  It will only break a word in the
middle if there's no other choice.  It does not try to hyphenate or parse

    (bobbin:wrap "This is a test of Bobbin's line-breaking." 10)
    "This is a
    test of

Initial whitespace (e.g. indentation) will be preserved, unless even the first
word cannot be fit if it were included.  Bobbin does not try to indent any
broken lines, but this may be added in the future:

    (bobbin:wrap "    foo bar baz" 10)
    "    foo
    bar baz"

    (bobbin:wrap "    thisisjusttoolong" 10)

Whitespace between words will be preserved, unless a line is broken at that
point.  This does the right thing for those of us who put two spaces after
a period, [as God intended](

    (bobbin:wrap "there  are  two  spaces  between  these  words" 12)
    "there  are
    two  spaces
    these  words"

Existing line breaks in the text are preserved.  Bobbin will only ever *add*
line breaks, never remove them:

    (bobbin:wrap (format nil "foo~%bar baz frob") 7)
    bar baz

### Lists

For convenience, you can also pass `wrap` a list of strings.  Each string is
treated as a separate line and wrapped as described above.  The results are
returned as a (flat) list of lines, each of which will be no more than `width`
characters long:

    (bobbin:wrap '("here is a line." "" "and here is another line") 8)
    ("here is"
     "a line."
     "and here"

The strings in the list may contain newlines themselves — they will be split and
the result will still be one flat list of lines.  You can use this to trick
Bobbin into returning a list even when you're just passing it one string, by
wrapping the input in a list:

    (defparameter *foo* (format nil "foo and bar~%cat and mouse"))

    (bobbin:wrap *foo* 8)
    "foo and
    cat and

    (bobbin:wrap (list *foo*) 8)
    ("foo and"
     "cat and"


* Handle tab characters.
* Handle non-printing characters.
* Handle wide characters.
* `unwrap` function to make writing paragraphs easier.
* Maybe reindent broken lines?
* Add `skip-p` argument to allow raw lines.