CodeFormat["code"]
formats a string of WL code returning a string.
CodeFormat[File[src]]
formats a file of WL code returning a string.
Details and Options
Examples
Basic Examples
Options
Airiness
"IndentationString"
"LineWidth"
"NewlineString"
Possible Issues
Related Guides
CodeFormatter`
CodeFormatter`
CodeFormat
CodeFormat["code"]
formats a string of WL code returning a string.
CodeFormat[File[src]]
formats a file of WL code returning a string.
Details and Options
- The following options can be given:
-
Airiness 0 high-level control of amount of whitespace and newlines "IndentationString" " " string to use for indentation "LineWidth" 78 width of lines before line breaking occurs "NewlineString" "\n" string to use for newlines "NewlinesBetweenCommas" Automatic low-level control for newlines between commas "NewlinesBetweenSemicolons" Automatic low-level control for newlines between semicolons "NewlinesBetweenOperators" Automatic low-level control for newlines between operators "NewlinesInComments" Automatic low-level control for newlines in comments "NewlinesInControl" Automatic low-level control for newlines in control structures "NewlinesInGroups" Automatic low-level control for newlines in groups "NewlinesInScoping" Automatic low-level control for newlines in scoping constructs - Airiness can be a value between -1 and 1.
- Settings for "IndentationString" must result in equivalent code.
- Settings for "NewlineString" must result in equivalent code.
- Possible settings for the low-level newline options are:
-
Automatic use default behavior that relies on heuristics Insert always insert newlines Delete always delete newlines - Values for Airiness map directly to different values for low-level newline options.
- Airiness of 0 is equivalent to all low-level newline options having value Automatic.
- Airiness of -1 is equivalent to all low-level newline options having value Delete.
- Airiness of 1 is equivalent to all low-level newline options having value Insert.
Examples
open all close allBasic Examples (1)
Options (4)
Airiness (1)
Needs["CodeFormatter`"]CodeFormat["If[a[], b[], c[]]", Airiness -> 0]CodeFormat["If[a[], b[], c[]]", Airiness -> -1]CodeFormat["If[a[], b[], c[]]", Airiness -> 1]"IndentationString" (1)
Needs["CodeFormatter`"]CodeFormat["If[a[], b[], c[]]", "IndentationString" -> " "]CodeFormat["If[a[], b[], c[]]", "IndentationString" -> ""]Settings that do not result in equivalent code are not allowed:
CodeFormat["If[a[], b[], c[]]", "IndentationString" -> "xxx", PerformanceGoal -> "Quality"]"LineWidth" (1)
Needs["CodeFormatter`"]CodeFormat["{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}", "LineWidth" -> 120]CodeFormat["{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100}", "LineWidth" -> 20]"NewlineString" (1)
Needs["CodeFormatter`"]CodeFormat["If[a[], b[], c[]]", "NewlineString" -> "
"]Settings that do not result in equivalent code are not allowed:
CodeFormat["If[a[], b[], c[]]", "NewlineString" -> "xxx", PerformanceGoal -> "Quality"]Possible Issues (1)
Needs["CodeFormatter`"]A string representing a file path is treated as code.
CodeFormat["ExampleData/Collatz.m"]File paths must use the File wrapper.
CodeFormat[File["ExampleData/Collatz.m"]]