# MBeautifier
MBeautifier is a lightweight M-Script based MATLAB source code formatter usable directly in the MATLAB Editor.
![Basic working](https://cloud.githubusercontent.com/assets/12681120/20592407/904cb1d6-b22d-11e6-93dd-1637c3738e50.png)
Main features
-------------
- Padding operators and keywords with white spaces
- Configurable indentation character and level. Indentation using the Smart Indent functionality of the MATLAB Editor
- Removal/addition of continuous empty lines
- Inserting missing element separators (commas) in matrix and cell array initializations
- Insert missing continuous symbol line in matrix and cell array initializations
- In-lining continuous lines
- Formats the current page of the MATLAB Editor or only a selection in the MATLAB Editor or file(s)
- While everything above is configurable in a single XML file
Deployment and Configuration
----------------------------
Simply add the root directory to the MATLAB path.
### Configuration
The configuration can be modified by editing the `MBeautifier\resources\settings\MBeautyConfigurationRules.xml` file.
#### Configuration rules
Currently three types of configuration rules are implemented: `Operator padding rule`, `Keyword padding rule` and `Special rule`.
#### Operator padding rules
Each `OperatorPaddingRule` represents the formatting rules for one single operator and consists of a key, the string that should be replaced and a string that should be used for the replacement.
<OperatorPaddingRule>
<Key>NotEquals</Key>
<ValueFrom>~=</ValueFrom>
<ValueTo> ~= </ValueTo>
</OperatorPaddingRule>
The example above shows the rule for the "not equals" operator. The `ValueFrom` node stores the operator `~=` and the `ValueTo` node stores the expected format: the operator should be preceded and followed by a white-space character.
#### Keyword padding rules
Each `KeyworPaddingRule` represents the formatting rules for one single keyword and consists the keyword itself, and a numeric value of the needed white-space padding on the right side.
<KeyworPaddingRule>
<Keyword>properties</Keyword>
<RightPadding>1</RightPadding>
</KeyworPaddingRule>
The example above shows the rule for the keyword "properties". The `RightPadding` node stores the expected right padding white space amount: the keyword should be preceded by one white space character.
> Note: Not all of the keywords are listed - only the ones where controlling padding makes sense.
#### Special rules
These rules are basically switches for certain functionalities of MBeautifier.
The current list of special rules:
##### Special rules regarding new lines
- **MaximalNewLines**: Integer value. MBeautifier will remove continuous empty lines. This rule can be used to specify the maximal number of maximal continuous empty lines.
- **SectionPrecedingNewlineCount**: Integer value. Defines how many empty lines should precede the section comments (`%% `). Negative values mean no special formatting is needed (the final format is defined by the input and the MaximalNewLines rule). For any number "X" bigger or equal to zero: section comments will be preceded exactly by X empty lines.
- **SectionTrailingNewlineCount**: Integer value. Defines how many empty lines should follow the section comments (`%% `). Negative values mean no special formatting is needed (the final format is defined by the input and the MaximalNewLines rule). For any number "X" bigger or equal to zero: section comments will be followed exactly by X empty lines.
- **EndingNewlineCount**: Integer value. Defines how many empty lines should be placed on the end of the input. Negative values mean no special formatting is needed (the final format is defined by the input and the MaximalNewLines rule). For any number "X" bigger or equal to zero: input will trailed exactly by X empty lines.
- **AllowMultipleStatementsPerLine**: [1|0]. If set to 1, MBeautifier will allow multiple statements per line (`a = 1; b = 2;`), otherwise it will break every statement into a new line. Defaults to "0".
##### Special rules regarding matrix and cell array separators
- **AddCommasToMatrices**: [1|0]. Indicates whether the missing element separator commas in matrices should be inserted. For example: `[1 2 3]` will be formatted as `[1, 2, 3]`.
- **AddCommasToCellArrays**: [1|0]. Indicates whether the missing element separator commas in cell arrays should be inserted. For example: `{1 2 3}` will be formatted as `{1, 2, 3}`.
##### Special rules arithmetic operators
- **MatrixIndexing_ArithmeticOperatorPadding**: [1|0]. Indicates whether the arithmetic operators should be padded by white spaces (using the operator padding rules), when they are used to index matrices. For example: `matrix(end+1) = 1` can be formatted as `matrix(end+1) = 1` when value is set to 0, or as `matrix(end + 1) = 1` if value is set to 1.
- **CellArrayIndexing_ArithmeticOperatorPadding**: [1|0]. Indicates the same as `MatrixIndexing_ArithmeticOperatorPadding` but for cell arrays.
##### Special rules regarding continous lines
- **InlineContinousLines**: [1|0]. If set to 1, MBeautifier will in-line continuous line operators ("...") everywhere except in matrices (inside [] brackets) and in curly brackets ({}) - these cases are handled by the next two options. In-lining means: the "..." operator will be removed and the next line will be copied into its place.
- **InlineContinousLinesInMatrixes**: [1|0]. Same as **InlineContinousLines**, but only has effect inside brackets ("[]").
- **InlineContinousLinesInCurlyBracket**: [1|0]. Same as **InlineContinousLines**, but only has effect inside curly brackets ("{}").
##### Special rules regarding indentation
- **IndentationCharacter**: [white-space|tab]. Specifies which character should be used for auto-indentation: white space or tabulator. Defaults to "white-space".
- **IndentationCount**: Integer value. Specifies the level of auto-indentation (how many **IndentationCharacter** means one level of indentation). Defaults to "4".
- **Indentation_TrimBlankLines**: [1|0]. Specifies if blank lines (lines containing only white space characters - as result of auto-indentation) should be trimmed (made empty) by MBeautifier. Defaults to "1" as it can lead to smaller file sizes.
- **Indentation_Strategy**: ['AllFunctions'|'NestedFunctions'|'NoIndent']. Controls the "Function indenting format" preference of the MATLAB editor used by MBeautifier: changes the indentation level of the functions' body. Possible values: "AllFunctions" - indent the body of each function, "NestedFunctions" - indent the body of nested functions only, "NoIndent" - all of the functions' body will be indented the same amount as the function keyword itself.
#### Directives
MBeautifier directives are special constructs which can be used in the source code to control MBeautifier during the formatting process. The example below controls the directive named `Format` and sets its value to `on` and then later to `off`.
a = 1;
% MBeautifierDirective:Format:Off
longVariableName = 'where the assigement is';
aligned = 'with the next assignment';
% MBD:Format:On
someMatrix = [1 2 3];
The standard format of a directive line is:
- following the pattern: `<ws>%<ws>MBeautifierDirective<ws>:<ws>:NAME<ws>:<ws>VALUE<ws>[NEWLINE]` or : `<ws>%<ws>MBD<ws>:<ws>:NAME<ws>:<ws>VALUE<ws>[NEWLINE]`where
- `<ws>` means zero or more optional white space characters
- `NAME` means the directive name (only latin letters, case insensitive)
- `VALUE` means the directive value (only latin letters, case insensitive)
- must not contain any code or any trailing comment (only the directive comment above)
- must not be inside a block comment
- must not be inside any line continousment
- the keyword `MBeautifierDirective` is freely interchangable with `MBD`
> **Note: Directive names which are not present in the
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。 Matlab(Matrix Laboratory)是一种专为数值计算和科学与工程应用而设计的高级编程语言和环境。在算法开发和实现方面,Matlab具有以下一些好处: 1. 丰富的数学和科学函数库:Matlab提供了广泛的数学、信号处理、图像处理、优化、统计等领域的函数库,这些函数库可以帮助开发者快速实现各种复杂的数值计算算法。这些函数库提供了许多常用的算法和工具,可以大大简化算法开发的过程。 2. 易于学习和使用:Matlab具有简单易用的语法和直观的编程环境,使得算法开发者可以更快速地实现和测试他们的算法。Matlab的语法与数学表达式和矩阵操作非常相似,这使得算法的表达更加简洁、清晰。 3. 快速原型开发:Matlab提供了一个交互式的开发环境,可以快速进行算法的原型开发和测试。开发者可以实时查看和修改变量、绘制图形、调试代码等,从而加快了算法的迭代和优化过程。这种快速原型开发的特性使得算法开发者可以更快地验证和修改他们的想法。 4. 可视化和绘图功能:Matlab具有强大的可视化和绘图功能,可以帮助开发者直观地展示和分析算法的结果。开发者可以使用Matlab绘制各种图形、曲线、图像,以及创建动画和交互式界面,从而更好地理解和传达算法的工作原理和效果。 5. 并行计算和加速:Matlab提供了并行计算和加速工具,如并行计算工具箱和GPU计算功能。这些工具可以帮助开发者利用多核处理器和图形处理器(GPU)来加速算法的计算过程,提高算法的性能和效率
资源推荐
资源详情
资源评论
收起资源包目录
MBeautifier是一个MATLAB源代码格式化器、美化器.zip (26个子文件)
MBeautifier-master
resources
testdata
testfile.m 2KB
testfile_bugs.m 289B
settings
MBeautyConfigurationRules.xml 8KB
LICENSE 34KB
CONTRIBUTING.md 535B
MBeautify.m 19KB
CODE_OF_CONDUCT.md 3KB
MBeautyShortcuts.m 7KB
+MBeautifier
+Configuration
OperatorPaddingRule.m 3KB
SpecialRule.m 400B
KeywordPaddingRule.m 590B
Configuration.m 5KB
DirectiveChangeType.m 95B
CharacterArrayStringMemento.m 372B
Constants.m 378B
DirectiveDirector.m 2KB
MFormatter.m 53KB
StringMemory.m 4KB
GeneralFormattingDirective.m 662B
NoDirectiveChanged.m 221B
DirectiveChange.m 983B
StringArrayStringMemento.m 364B
MIndenter.m 10KB
StringMemento.m 288B
Directive.m 701B
README.md 11KB
共 26 条
- 1
资源评论
若明天不见
- 粉丝: 1w+
- 资源: 272
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功