# In-system help

The unit at text/help.fs provides "help ( "..." -- )". Unless it's called at the
end of a line (directly followed by a LF), it reads the next word as an
argument. It then opens the appropriate documentation using [text/ged], which
means that this system needs the Grid [io/grid].

When invoked without argument (followed directly by a newline), it simply opens
doc/index.txt. Otherwise, it looks up the word in the system dictionary.

If found, it checks which unit that word is associated with. If there's a unit,
open the documentation associated with the unit ("doc/<unitname>.txt"). If
there's no associated unit, open "doc/dict.txt".

If the word is not found, try opening "doc/<word>.txt". If that file is not
found, abort with error.

For example, "help read" would open, unless shadowed, "doc/io/stream.txt".
"help emul/virtio" would open "doc/emul/virtio.txt".

The target help file is opened with "?edload", thus preserving existing edbuf
contents.

## text/ged enhancements

Upon loading this unit, [text/ged] is enhanced with an additional key binding:
CTRL+E (Enter word under cursor). The input of that action is the word under the
cursor.

First, we try a straight open: if that word is a path to an existing file, we
just open it.

If not, we apply the "help" logic to it and try to open the resulting file.

"Opening" means calling "?edload" on the file, that is, possibly using a new
edbuf.

If all that fails, it does nothing.

## API

help ( "..." -- )
  Invoke help as described above.

helppath ( str -- str )
  Figure out the string path of "str" using the "help finding" logic described
  above, then yield a path to a file. The yielded path might not actually exist.

wrapdocpath ( str -- str )
  With "str" being a string like, for example, "lib/str", yield the
  associated help file path, for example "doc/lib/str.txt".

  If "str" contains a ".", the path is left untouched. If "str" already begins
  with "doc/", "doc/" is not prepended.

  If the word begins with a "[", we try to "dewrap" square brackets by looking
  for a matching "]" within the string. The contents then becomes what is in
  between those brackets, upon which the logic above is applied.

?load ( str -- f )
  If "str" exists in bootfs, load it in text/ed and yield f=1. Otherwise, f=0.
