-
Notifications
You must be signed in to change notification settings - Fork 22
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collecting possible formatting styles #23
Comments
well, I have a little idea: Maybe we can look for format from ready-made MMA code.
|
I accidently find this: GU`FM = NotebookPut[
Notebook[
{GeneralUtilities`MakeFormattedBoxes@#}
, StyleDefinitions -> GeneralUtilities`Debugging`PackagePrivate`$DefinitionNotebookStyleDefinitions]
]&;
SetAttributes[GU`FM, HoldAllComplete] This is a built-in formatter XD. |
This can be a temporarily method that does not look bad. |
My style of formatting indentationtab whitespacesIt usually depends on the precedence of the operators compared to their neighbour.
empty linesFor the definition related to the same symbol, one lines between them. Otherwise, two lines. For logically different/independent definitions, they will be in different cell groups. line wrappingFor not only very long expressions, but also many expressions (such as If[...]) which is not too short, I will wrap it like this:
For nested long expression, I will break the outer one:
dangling operator / delimiterWhen the last argument is long, I never put
When it's an operator before the bracket, usually no line-break.
When it's a bracket:
put binary operators at the end of the linesNever. It may mislead the understanding of precedences. If it's too long, I will use the normal expression form instead of the operator.
Alternatively, I sometimes define a new variable or use
semi-colon (so called CompoundExpression)Keep it as it is. |
I found it not suitable for users like me who expect the formatter to do its least work to damage the code structure, because,
|
I would like to give users the freedom to customize their format flavor, by importing a set of rules written by yourself. But for now, I think I can start by implementing the indentation and empty lines, which seems easier. |
Any progress? 👀 |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
This issue is to collect different formatting styles of Wolfram Language. The current state of the language server is not capable to do complicate formatting (not even simple ones, because I haven't implemented any lol). I know that Brenton (@bostick the author of AST and Lint) is working on a code formatter (see the end of the video, and I definitely admire his ambition to do notebook manipulation 🤣 but I haven't known whether his formatter will let users define their own styles.
Since people have different appetites this issue welcomes ALL possible styles that we can format the wolfram language into. YES, all possible styles. I didn't say I would accept or implement all of them, just for the aesthetic purpose.
A code block or screenshot to illustrate the style is recommended.
Here are some features we can start thinking from:
indentation
whitespaces
F@a
vsF @ a
same for (//
)a ~Join~ b
vsa ~ Join ~ b
i++
vsi ++
same for other unary operators"str"<>"ing"
vs"str" <> "ing"
(same for~~
)empty lines
Adding two lines will make a separate cell for the code block if you open the
.wl
/.wls
file in Mathematica. Thus it is recommended to split up differentFunctions into cells.
line wrapping
first parameter dangling if it doesn't exceeds 80 chars after wrapping
wrap from the end of the line
dangling operator / delimiter
]
at the end of the line]
at the begining of the line{
,(
,<|
at the end of the line&&
,||
,<>
,~~
, etcsemi-colon (so called
CompoundExpression
)The text was updated successfully, but these errors were encountered: