You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fprettify is an auto-formatter for modern Fortran code that imposes strict whitespace formatting, written in Python.
6
10
7
11
**NOTE:** I'm looking for help to maintain this repository, see [#127](https://github.com/pseewald/fprettify/issues/127).
8
12
9
-
10
13
## Features
11
14
12
-
* Auto-indentation.
13
-
* Line continuations are aligned with the previous opening delimiter `(`, `[` or `(/` or with an assignment operator `=` or `=>`. If none of the above is present, a default hanging indent is applied.
14
-
* Consistent amount of whitespace around operators and delimiters.
15
-
* Removal of extraneous whitespace and consecutive blank lines.
16
-
* Change letter case (upper case / lower case conventions) of intrinsics
17
-
* Tested for editor integration.
18
-
* By default, fprettify causes whitespace changes only and thus preserves revision history.
19
-
* fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.
20
-
15
+
- Auto-indentation.
16
+
- Line continuations are aligned with the previous opening delimiter `(`, `[` or `(/` or with an assignment operator `=` or `=>`. If none of the above is present, a default hanging indent is applied.
17
+
- Consistent amount of whitespace around operators and delimiters.
18
+
- Removal of extraneous whitespace and consecutive blank lines.
19
+
- Change letter case (upper case / lower case conventions) of intrinsics
20
+
- Tested for editor integration.
21
+
- By default, fprettify causes whitespace changes only and thus preserves revision history.
22
+
- fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.
21
23
22
24
## Limitations
23
25
24
-
* Works only for modern Fortran (Fortran 90 upwards).
25
-
* Feature missing? Please create an issue.
26
-
26
+
- Works only for modern Fortran (Fortran 90 upwards).
27
+
- Feature missing? Please create an issue.
27
28
28
29
## Requirements
29
30
30
-
* Python 3 (Python 2.7 no longer supported)
31
-
*[ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file
32
-
31
+
- Python 3 (Python 2.7 no longer supported)
32
+
-[ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file
33
33
34
34
## Examples
35
35
36
36
Compare `examples/*before.f90` (original Fortran files) with `examples/*after.f90` (reformatted Fortran files) to see what fprettify does. A quick demonstration:
37
37
38
-
```Fortran
38
+
```Fortran
39
39
program demo
40
40
integer :: endif,if,elseif
41
41
integer,DIMENSION(2) :: function
@@ -50,8 +50,10 @@ print*,endif
50
50
endif
51
51
end program
52
52
```
53
+
53
54
⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
54
-
```Fortran
55
+
56
+
```Fortran
55
57
program demo
56
58
integer :: endif, if, elseif
57
59
integer, DIMENSION(2) :: function
@@ -67,65 +69,80 @@ program demo
67
69
end program
68
70
```
69
71
70
-
71
72
## Installation
72
73
73
74
The latest release can be installed using pip:
74
-
```
75
+
76
+
```sh
75
77
pip install --upgrade fprettify
76
78
```
77
79
78
80
Installation from source requires Python Setuptools:
79
-
```
80
-
./setup.py install
81
+
82
+
```sh
83
+
pip install .
81
84
```
82
85
83
86
For local installation, use `--user` option.
84
87
88
+
If you use the [Conda](https://docs.conda.io/) package manager, fprettify is available from the [conda-forge](https://conda-forge.org/) channel:
89
+
90
+
```sh
91
+
conda install -c conda-forge fprettify
92
+
```
85
93
86
94
## Command line tool
87
95
88
96
Autoformat file1, file2, ... inplace by
89
-
```
97
+
98
+
```sh
90
99
fprettify file1, file2, ...
91
100
```
101
+
92
102
The default indent is 3. If you prefer something else, use `--indent n` argument.
93
103
94
104
In order to apply fprettify recursively to an entire Fortran project instead of a single file, use the `-r` option.
95
105
96
106
For more options, read
97
-
```
107
+
108
+
```sh
98
109
fprettify -h
99
110
```
100
111
101
-
102
112
## Editor integration
103
113
104
114
For editor integration, use
105
-
```
115
+
116
+
```sh
106
117
fprettify --silent
107
118
```
119
+
108
120
For instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:
## Deactivation and manual formatting (experimental feature)
115
127
116
128
fprettify can be deactivated for selected lines: a single line followed by an inline comment starting with `!&` is not auto-formatted and consecutive lines that are enclosed between two comment lines `!&<` and `!&>` are not auto-formatted. This is useful for cases where manual alignment is preferred over auto-formatting. Furthermore, deactivation is necessary when non-standard Fortran syntax (such as advanced usage of preprocessor directives) prevents proper formatting. As an example, consider the following snippet of fprettify formatted code:
129
+
117
130
```fortran
118
131
A = [-1, 10, 0, &
119
132
0, 1000, 0, &
120
133
0, -1, 1]
121
134
```
135
+
122
136
In order to manually align the columns, fprettify needs to be deactivated by
137
+
123
138
```fortran
124
139
A = [-1, 10, 0, & !&
125
140
0, 1000, 0, & !&
126
141
0, -1, 1] !&
127
142
```
143
+
128
144
or, equivalently by
145
+
129
146
```fortran
130
147
!&<
131
148
A = [-1, 10, 0, &
@@ -134,10 +151,6 @@ A = [-1, 10, 0, &
134
151
!&>
135
152
```
136
153
137
-
138
154
## Contributing / Testing
139
155
140
156
The testing mechanism allows you to easily test fprettify with any Fortran project of your choice. Simply clone or copy your entire project into `fortran_tests/before` and run `python setup.py test`. The directory `fortran_tests/after` contains the test output (reformatted Fortran files). If testing fails, please submit an issue!
0 commit comments