Skip to content

Commit 8305eca

Browse files
committed
path-utils: update docs
1 parent 55644ac commit 8305eca

File tree

1 file changed

+71
-50
lines changed

1 file changed

+71
-50
lines changed

gui-lib/framework/main.rkt

Lines changed: 71 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,57 @@
535535
@{Opens a dialog that queries the user about exiting. Returns the user's
536536
decision.})
537537

538+
(proc-doc/names
539+
path-utils:generate-backup-name
540+
(path? . -> . path?)
541+
(filename)
542+
@{
543+
Generates a path for a backup file based on @racket[filename].
544+
545+
@index{'path-utils:backup-dir}
546+
The value of @racket[(preferences:get 'path-utils:backup-dir)]
547+
determines the directory of the resulting path.
548+
The value of this preference must be either a path
549+
satisfying @racket[complete-path?] and @racket[directory-exists?],
550+
in which case it is additionally checked to ensure that the
551+
directory has not been deleted since the preference was set,
552+
or @racket[#f] (the default).
553+
When the preference contains a valid path,
554+
the resulting path will use that directory;
555+
otherwise, and by default,
556+
the result will use the same directory as @racket[filename].
557+
558+
The final element of the resulting path is derived from @racket[filename].
559+
When @racket[(preferences:get 'path-utils:backup-dir)] does not specify
560+
an extant directory, the final element of @racket[filename] is
561+
used directly as the base for the new element.
562+
Otherwise, the base is formed by transforming the complete path to @racket[filename]
563+
(resolved, if necessary, relative to @racket[(current-directory)])
564+
according to the following @deftech{encoding scheme}:
565+
@itemlist[#:style 'ordered
566+
@item{A @racket[separator-byte] is selected: @litchar{!} by default,
567+
but a list of visually-appealing one-byte characters are
568+
tried if @litchar{!} occurs in the complete path to
569+
@racket[filename].}
570+
@item{Every seperator between path elements is replaced with
571+
@racket[separator-byte], as are any other occurances of the
572+
reserved separator character (@litchar{\} on Windows or
573+
@litchar{/} on Unix or Mac OS), e.g. in the name of the root directory.}
574+
@item{A single @racket[separator-byte] is added at the beginning
575+
so that the seperator can be unambiguously identified.}
576+
@item{If the result of the previous step is excessively long, it
577+
may be shortened by replacing some bytes in the middle with
578+
@racket[(bytes-append separator-byte #"..." separator-byte)]
579+
(i.e. @litchar{!...!} with @litchar{!} as the @racket[separator-byte]).}]
580+
581+
In either case, the final path element is formed from the base
582+
in a platform-specific manner:
583+
@itemlist[
584+
@item{On Unix and Mac OS, a @litchar{~} is added to the end.}
585+
@item{On Windows, the extension (in the sense of @racket[path-replace-extension])
586+
is replaced with @litchar{.bak}.}]
587+
})
588+
538589
(proc-doc/names
539590
path-utils:generate-autosave-name
540591
(-> (or/c #f path-string? path-for-some-system?) path?)
@@ -544,69 +595,39 @@
544595

545596
@index{'path-utils:autosave-dir}
546597
The value of @racket[(preferences:get 'path-utils:autosave-dir)]
547-
determines the directory of the resulting path.
548-
When the preference value is @racket[#f] (the default),
549-
result will use the same directory as the @racket[filename]
598+
determines the directory of the resulting path
599+
in much the same way as @racket[path-utils:generate-backup-name]
600+
with @racket['path-utils:backup-dir].
601+
When the preference value is @racket[#f] (the default) or a
602+
directory that no longer exists, the
603+
result will use the same directory as @racket[filename]
550604
(or, when @racket[filename] is @racket[#f], the directory determined by
551605
@racket[(find-system-path 'doc-dir)]).
552-
Otherwise, when @racket[(preferences:get 'path-utils:autosave-dir)]
553-
returns a path satisfying @racket[complete-path?] and
554-
@racket[directory-exists?], the autosave file will be saved in
555-
that directory.
556-
A relative @racket[filename] will be resolved based on
557-
the value of @racket[(current-directory)].
606+
Otherwise, the resulting path will use the directory specified by the preference.
558607

559608
When @racket[filename] is @racket[#f], the final element of the
560609
resulting path will be an automatically-generated unique name.
610+
561611
Otherwise, the final path element will be derived from @racket[filename].
562-
When @racket[(preferences:get 'path-utils:autosave-dir)] returns
563-
@racket[#f], the original file name will be used directly as the base;
564-
otherwise, base will be the complete path to @racket[filename],
565-
encoded by replacing each seperator (@litchar{\} on Windows or
566-
@litchar{/} on Unix or Mac OS) with @litchar{!}.
567-
This base is transformed into the final path element in a
568-
platform-specific manner:
612+
When @racket[(preferences:get 'path-utils:autosave-dir)] does not return
613+
an extant directory, the last element of @racket[filename] will be
614+
used directly as the base for the new element.
615+
When a valid autosave directory is specified, the base will be
616+
the complete path to @racket[filename],
617+
transformed according to the same @tech{encoding scheme} as
618+
with @racket[path-utils:generate-backup-name].
619+
In either case, the final path element is formed from the base
620+
in a platform-specific manner:
569621
@itemlist[
570622
@item{On Unix and Mac OS, a @litchar{#} is added to the start
571-
and end of the file’s name, then a number is added after the
623+
and end, then a number is added after the
572624
ending @litchar{#}, and then one more @litchar{#} is appended
573625
after the number.
574626
The number is selected to make the autosave filename unique.}
575-
@item{On Windows, the file’s extension is replaced with a number
576-
to make the autosave filename unique.}
627+
@item{On Windows, the file’s extension (in the sense of @racket[path-replace-extension])
628+
is replaced with a number to make the autosave filename unique.}
577629
]})
578630

579-
(proc-doc/names
580-
path-utils:generate-backup-name
581-
(path? . -> . path?)
582-
(filename)
583-
@{
584-
Generates a path for a backup file based on @racket[filename].
585-
586-
@index{'path-utils:backup-dir}
587-
The value of @racket[(preferences:get 'path-utils:backup-dir)]
588-
determines the directory of the resulting path in much the same
589-
way as @racket[path-utils:generate-autosave-name] responds to
590-
the preference @racket['path-utils:autosave-dir]:
591-
when the value is @racket[#f] (the default), the directory of
592-
@racket[filename] is used, and otherwise the directory from the
593-
preference is used.
594-
595-
The final element of the resulting path is generated from
596-
@racket[filename] in a platform-specific manner:
597-
@itemlist[
598-
@item{On Unix and Mac OS, a @litchar{~} is added to the end
599-
of the file’s name.}
600-
@item{On Windows, the file’s extension is replaced
601-
with @litchar{.bak}.}]
602-
In either case, when @racket[(preferences:get 'path-utils:backup-dir)]
603-
returns a non-false value, the result of the above transformation
604-
is combined with the complete path of @racket[filename],
605-
encoded by replacing seperators with @litchar{!} as with
606-
@racket[path-utils:generate-autosave-name], to form the final
607-
path element.
608-
})
609-
610631
(parameter-doc
611632
finder:dialog-parent-parameter
612633
(parameter/c (or/c false/c (is-a?/c dialog%) (is-a?/c frame%)))

0 commit comments

Comments
 (0)