From 47922f0da36ad36eaa3cb0979cf91c735a9e0405 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sun, 8 Sep 2013 11:04:46 -0500 Subject: [PATCH] make the 'name field of color scheme be more forgiving and improve the example in the docs to be more fool-proof for copy/paste original commit: 8311b620b4aa2ce7ce566174efb258e704ee8463 --- pkgs/gui-pkgs/gui-lib/framework/main.rkt | 30 ++++++++++++++++--- .../gui-lib/framework/private/color-prefs.rkt | 4 ++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/pkgs/gui-pkgs/gui-lib/framework/main.rkt b/pkgs/gui-pkgs/gui-lib/framework/main.rkt index 1c502dc9..5ba8247d 100644 --- a/pkgs/gui-pkgs/gui-lib/framework/main.rkt +++ b/pkgs/gui-pkgs/gui-lib/framework/main.rkt @@ -29,7 +29,7 @@ framework/private/decorated-editor-snip)) (require (for-doc racket/base scribble/manual framework/private/mapdesc - setup/getinfo racket/pretty)) + setup/getinfo racket/pretty string-constants)) (provide-signature-elements (prefix application: framework:application-class^) @@ -1887,7 +1887,8 @@ color scheme. Each hash table should have keys that specify details of the color scheme, as follows: @itemlist[@item{@racket['name]: must be either a string or a symbol; - if it is a symbol, it is passed to @racket[dynamic-string-constant] + if it is a symbol and @racket[string-constant?], + it is passed to @racket[dynamic-string-constant] to get the name; otherwise it is used as the name directly. If absent, the name of the directory containing the @filepath{info.rkt} file is used as the name.} @@ -1920,8 +1921,29 @@ (define-values (base name dir?) (split-path pth)) (define info (get-info/full base)) (unless info (error 'framework/main.rkt "could not find example for modern color scheme")) - (parameterize ([pretty-print-columns 60]) - (codeblock (pretty-format (info 'framework:color-schemes)))))}) + (define key 'framework:color-schemes) + (define datum (info key)) + (define name-as-string-datum + (let loop ([datum datum]) + (cond + [(list? datum) + (for/list ([datum (in-list datum)]) + (loop datum))] + [(hash? datum) + (for/hash ([(k v) (in-hash datum)]) + (if (and (equal? k 'name) (string-constant? v)) + (values k (dynamic-string-constant v)) + (values k (loop v))))] + [else datum]))) + (define sp (open-output-string)) + (parameterize ([pretty-print-columns 60] + [current-output-port sp]) + (pretty-write + `(define ,key + ',name-as-string-datum))) + (codeblock + (string-append "#lang info\n" + (get-output-string sp))))}) (proc-doc/names color-prefs:set-current-color-scheme diff --git a/pkgs/gui-pkgs/gui-lib/framework/private/color-prefs.rkt b/pkgs/gui-pkgs/gui-lib/framework/private/color-prefs.rkt index dba65bd5..d2b930e3 100644 --- a/pkgs/gui-pkgs/gui-lib/framework/private/color-prefs.rkt +++ b/pkgs/gui-pkgs/gui-lib/framework/private/color-prefs.rkt @@ -646,7 +646,9 @@ (define mapping (hash-ref one-scheme 'colors '())) (define example (hash-ref one-scheme 'example default-example)) (register-color-scheme (if (symbol? name) - (dynamic-string-constant name) + (if (string-constant? name) + (dynamic-string-constant name) + (symbol->string name)) name) white-on-black-base? mapping