On this page:
path->directory-relative-string
library-relative-directories
setup-relative-directories
Version: 5.0

4 Directories

Carl Eastlund <cce@ccs.neu.edu>

 (require unstable/dirs)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

This library defines utilities dealing with the directory paths used by the Racket distribution.

(path->directory-relative-string path 
  [#:default default 
  #:dirs dirs]) 
  (or/c string? (one-of/c default))
  path : path-string?
  default : any/c = (if (path? path) (path->string path) path)
  dirs : (listof (cons/c (-> path?) any/c))
   = library-relative-directories
Produces a string rendering of path, replacing distribution-specific paths (normally: collections, user-installed collections, or PLanet cache) with short abbreviations.

The set of paths and their abbreviations may be overridden by the #:dirs option, which accepts an association list. Its keys must be thunks which produce a path. Its values may be either #f for no abbreviation (the directory prefix is simply omitted) or any other value to be displayed in the output. For instance, "document.txt" relative to a path abbreviated "path" would be rendered as "<path>/document.txt".

If the path is not relative to one of the given directories, the default return value is a string rendering of the unmodified path. This default may be overridden by providing default.

Examples:

  > (path->directory-relative-string
     (build-path "source" "project.rkt"))

  "source/project.rkt"

  > (path->directory-relative-string
     (build-path (current-directory) "source" "project.rkt"))

  "<collects>/unstable/source/project.rkt"

  > (path->directory-relative-string
     (build-path "/" "source" "project.rkt"))

  "/source/project.rkt"

  > (path->directory-relative-string
     (build-path "/" "source" "project.rkt")
     #:default #f)

  #f

  > (path->directory-relative-string
     (build-path "/" "source" "project.rkt")
     #:dirs (list
             (cons (lambda () (build-path "/" "source"))
                   'src)))

  "<src>/project.rkt"

Represents the default directory substitutions for path->directory-relative-string. By default, the collections directory is replaced by collects, the user-installed collections directory is replaced by user, and the PLaneT cache is replaced by planet.

Represents the directory substitutions used by setup-plt. The collections directory is omitted, the user-installed collections directory is replaced by user, and the PLaneT cache is replaced by planet.