 : scaffolding ( path -- path )
     "Creating scaffolding for " write dup <pathname> . ;
 
-: (scaffold-path) ( path string -- path )
-    [ dup file-name ] dip append append-path ;
-
-: scaffold-path ( path string -- path ? )
-    (scaffold-path)
+: scaffolding? ( path -- path ? )
     dup exists? [ not-scaffolding f ] [ scaffolding t ] if ;
 
 : scaffold-copyright ( -- )

    [ bl write ] each
    " ;" print ;

: set-scaffold-help-file ( path vocab -- )
    swap utf8 <file-writer> [
        scaffold-copyright
        [ help-file-string ] [ write-using ] bi
        write
    ] with-output-stream ;

: check-scaffold ( vocab-root string -- vocab-root string )
    [ check-root ] [ check-vocab-name ] bi* ;

: vocab>scaffold-path ( vocab-root string -- path )
    path-separator first CHAR: . associate substitute
    append-path ;

: prepare-scaffold ( vocab-root string -- string path )
    check-scaffold [ vocab>scaffold-path ] keep ;

: with-scaffold ( quot -- )
    [ H{ } clone using ] dip with-variable ; inline

: check-vocab ( vocab -- vocab )
    dup find-vocab-root [ no-vocab ] unless ;

PRIVATE>

: link-vocab ( vocab -- )
    check-vocab
    "Edit documentation: " write
    [ find-vocab-root ]
    [ vocab>scaffold-path ] bi
    "-docs.factor" (scaffold-path) <pathname> . ;

: help. ( word -- )
    [ (help.) ] [ nl vocabulary>> link-vocab ] bi ;

: scaffold-help ( string -- )
    [
        [ find-vocab-root ] [ check-vocab ] bi
        prepare-scaffold
        [ "-docs.factor" scaffold-path ] dip
        swap [ set-scaffold-help-file ] [ 2drop ] if
    ] with-scaffold ;

: scaffold-undocumented ( string -- )
    [ interesting-words. ] [ link-vocab ] bi ;

: scaffold-vocab ( vocab-root string -- )
    prepare-scaffold
    {
        [ drop scaffold-directory ]
        [ scaffold-main ]
        [ drop scaffold-authors ]
        [ nip require ]
    } 2cleave ;

SYMBOL: examples-flag


    natural-sort ;

: interesting-words. ( vocab -- )
    interesting-words [ (docs.) nl ] each ;

: docs-file-string ( vocab -- str2 )
    [
        {
            [ "IN: " write print nl ]
