]> gitweb.factorcode.org Git - factor.git/commitdiff
prettyprint.config: set some output limits by default. Use the new without-limits...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 19 Feb 2010 23:18:16 +0000 (12:18 +1300)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 19 Feb 2010 23:18:16 +0000 (12:18 +1300)
basis/prettyprint/config/config-docs.factor
basis/prettyprint/config/config.factor
basis/prettyprint/prettyprint-docs.factor
basis/prettyprint/prettyprint.factor
basis/tools/deploy/config/editor/editor.factor

index ccc63c61cbaa3a35d71384de603c397b6f8ba2e6..7cd4b31c8bfb2c6b604376636aae29b0b39c4a3c 100644 (file)
@@ -1,5 +1,5 @@
 USING: help.markup help.syntax io kernel
-prettyprint.sections words ;
+prettyprint.sections words quotations ;
 IN: prettyprint.config
 
 ABOUT: "prettyprint-variables"
@@ -31,3 +31,11 @@ HELP: boa-tuples?
 
 HELP: c-object-pointers?
 { $var-description "Toggles whether C objects such as structs and direct arrays only print their underlying address. If this flag isn't set, C objects will attempt to print their contents. If a C object points to invalid memory, it will display only its address regardless." } ;
+
+HELP: with-short-limits
+{ $values { "quot" quotation } }
+{ $description "Calls a quotation in a new dynamic scope with prettyprinter limits set to produce a single line of output." } ;
+
+HELP: without-limits
+{ $values { "quot" quotation } }
+{ $description "Calls a quotation in a new dynamic scope with prettyprinter limits set to produce unlimited output." } ;
index dd61e3e23d2f06e299f29e3711220522859c4114..a8848f9061d4dcf2e6994dfc16bfaab547b197a7 100644 (file)
@@ -1,8 +1,6 @@
-! Copyright (C) 2003, 2008 Slava Pestov.
+! Copyright (C) 2003, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays generic assocs io kernel math
-namespaces sequences strings vectors words
-continuations ;
+USING: kernel namespaces ;
 IN: prettyprint.config
 
 ! Configuration
@@ -18,4 +16,28 @@ SYMBOL: c-object-pointers?
 
 4 tab-size set-global
 64 margin set-global
+15 nesting-limit set-global
+100 length-limit set-global
 10 number-base set-global
+string-limit? on
+
+: with-short-limits ( quot -- )
+    [
+        1 line-limit set
+        15 length-limit set
+        2 nesting-limit set
+        string-limit? on
+        boa-tuples? on
+        c-object-pointers? on
+        call
+    ] with-scope ; inline
+
+: without-limits ( quot -- )
+    [
+        nesting-limit off
+        length-limit off
+        line-limit off
+        string-limit? off
+        c-object-pointers? off
+        call
+    ] with-scope ; inline
index bd2c4bd924d9dffd0546952f07a6c95436e5812a..33e1857260e0d15967fe570ee98c842a888744d1 100644 (file)
@@ -38,12 +38,9 @@ ARTICLE: "prettyprint-variables" "Prettyprint control variables"
     boa-tuples?
     c-object-pointers?
 }
-"Note that the " { $link short. } " and " { $link pprint-short } " variables override some of these variables."
-{
-    $warning "Treat the global variables as essentially being constants. Only ever rebind them in a nested scope."
-    $nl
-    "Some of the globals are safe to change, like the tab size and wrap margin. However setting limits globally could break code which uses the prettyprinter as a serialization mechanism."
-} ;
+"The default limits are meant to strike a balance between readability, and not producing too much output when large structures are given. There are two combinators that override the defaults:"
+{ $subsections with-short-limits without-limits }
+"That the " { $link short. } " and " { $link pprint-short } " words wrap calls to " { $link . } " and " { $link pprint } " in " { $link with-short-limits } ". Code that uses the prettyprinter for serialization should use " { $link without-limits } " to avoid producing unreadable output." ;
 
 ARTICLE: "prettyprint-limitations" "Prettyprinter limitations"
 "When using the prettyprinter as a serialization mechanism, keep the following points in mind:"
index 7b1538b1dcf1c46b1a29e7ecbbfe3e63d11018c9..23cf956a1d71afa3364c4c03b22d8bbd6a1bfefa 100644 (file)
@@ -26,13 +26,7 @@ IN: prettyprint
 : unparse-use ( obj -- str ) [ pprint-use ] with-string-writer ;
 
 : pprint-short ( obj -- )
-    H{
-       { line-limit 1 }
-       { length-limit 15 }
-       { nesting-limit 2 }
-       { string-limit? t }
-       { boa-tuples? t }
-    } clone [ pprint ] bind ;
+    [ pprint ] with-short-limits ;
 
 : unparse-short ( obj -- str )
     [ pprint-short ] with-string-writer ;
index 78d86a470744bc9101071a7c3ae80a5ceb2414c5..e10d20e8b3828ee567f6e10a21d40b7a9a0f302d 100644 (file)
@@ -1,7 +1,8 @@
-! Copyright (C) 2008 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: assocs io.pathnames kernel parser prettyprint sequences
-splitting tools.deploy.config vocabs.loader vocabs.metadata ;
+USING: assocs io.pathnames kernel parser prettyprint
+prettyprint.config sequences splitting tools.deploy.config
+vocabs.loader vocabs.metadata ;
 IN: tools.deploy.config.editor
 
 : deploy-config-path ( vocab -- string )
@@ -13,7 +14,7 @@ IN: tools.deploy.config.editor
     parse-fresh [ first assoc-union ] unless-empty ;
 
 : set-deploy-config ( assoc vocab -- )
-    [ unparse-use string-lines ] dip
+    [ [ unparse-use ] without-limits string-lines ] dip
     dup deploy-config-path set-vocab-file-contents ;
 
 : set-deploy-flag ( value key vocab -- )