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
9
7
10
**NOTE:** I'm looking for help to maintain this repository, see [#127](https://github.com/pseewald/fprettify/issues/127).
8
11
9
-
10
12
## Features
11
13
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
-
14
+
- Auto-indentation.
15
+
- 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.
16
+
- Consistent amount of whitespace around operators and delimiters.
17
+
- Removal of extraneous whitespace and consecutive blank lines.
18
+
- Change letter case (upper case / lower case conventions) of intrinsics
19
+
- Tested for editor integration.
20
+
- By default, fprettify causes whitespace changes only and thus preserves revision history.
21
+
- fprettify can handle cpp and [fypp](https://github.com/aradi/fypp) preprocessor directives.
21
22
22
23
## Limitations
23
24
24
-
* Works only for modern Fortran (Fortran 90 upwards).
25
-
* Feature missing? Please create an issue.
26
-
25
+
- Works only for modern Fortran (Fortran 90 upwards).
26
+
- Feature missing? Please create an issue.
27
27
28
28
## Requirements
29
29
30
-
* Python 3 (Python 2.7 no longer supported)
31
-
*[ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file
32
-
30
+
- Python 3 (Python 2.7 no longer supported)
31
+
-[ConfigArgParse](https://pypi.org/project/ConfigArgParse): optional, enables use of config file
33
32
34
33
## Examples
35
34
36
35
Compare `examples/*before.f90` (original Fortran files) with `examples/*after.f90` (reformatted Fortran files) to see what fprettify does. A quick demonstration:
37
36
38
-
```Fortran
37
+
```Fortran
39
38
program demo
40
39
integer :: endif,if,elseif
41
40
integer,DIMENSION(2) :: function
@@ -50,8 +49,10 @@ print*,endif
50
49
endif
51
50
end program
52
51
```
52
+
53
53
⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩ `fprettify` ⇩⇩⇩⇩⇩⇩⇩⇩⇩⇩
54
-
```Fortran
54
+
55
+
```Fortran
55
56
program demo
56
57
integer :: endif, if, elseif
57
58
integer, DIMENSION(2) :: function
@@ -67,65 +68,74 @@ program demo
67
68
end program
68
69
```
69
70
70
-
71
71
## Installation
72
72
73
73
The latest release can be installed using pip:
74
-
```
74
+
75
+
```sh
75
76
pip install --upgrade fprettify
76
77
```
77
78
78
79
Installation from source requires Python Setuptools:
79
-
```
80
+
81
+
```sh
80
82
./setup.py install
81
83
```
82
84
83
85
For local installation, use `--user` option.
84
86
85
-
86
87
## Command line tool
87
88
88
89
Autoformat file1, file2, ... inplace by
89
-
```
90
+
91
+
```sh
90
92
fprettify file1, file2, ...
91
93
```
94
+
92
95
The default indent is 3. If you prefer something else, use `--indent n` argument.
93
96
94
97
In order to apply fprettify recursively to an entire Fortran project instead of a single file, use the `-r` option.
95
98
96
99
For more options, read
97
-
```
100
+
101
+
```sh
98
102
fprettify -h
99
103
```
100
104
101
-
102
105
## Editor integration
103
106
104
107
For editor integration, use
105
-
```
108
+
109
+
```sh
106
110
fprettify --silent
107
111
```
112
+
108
113
For instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:
## Deactivation and manual formatting (experimental feature)
115
120
116
121
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:
122
+
117
123
```fortran
118
124
A = [-1, 10, 0, &
119
125
0, 1000, 0, &
120
126
0, -1, 1]
121
127
```
128
+
122
129
In order to manually align the columns, fprettify needs to be deactivated by
130
+
123
131
```fortran
124
132
A = [-1, 10, 0, & !&
125
133
0, 1000, 0, & !&
126
134
0, -1, 1] !&
127
135
```
136
+
128
137
or, equivalently by
138
+
129
139
```fortran
130
140
!&<
131
141
A = [-1, 10, 0, &
@@ -134,10 +144,8 @@ A = [-1, 10, 0, &
134
144
!&>
135
145
```
136
146
137
-
138
147
## Contributing / Testing
139
148
140
149
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