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,74 @@ 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
-
```
81
+
82
+
```sh
80
83
./setup.py install
81
84
```
82
85
83
86
For local installation, use `--user` option.
84
87
85
-
86
88
## Command line tool
87
89
88
90
Autoformat file1, file2, ... inplace by
89
-
```
91
+
92
+
```sh
90
93
fprettify file1, file2, ...
91
94
```
95
+
92
96
The default indent is 3. If you prefer something else, use `--indent n` argument.
93
97
94
98
In order to apply fprettify recursively to an entire Fortran project instead of a single file, use the `-r` option.
95
99
96
100
For more options, read
97
-
```
101
+
102
+
```sh
98
103
fprettify -h
99
104
```
100
105
101
-
102
106
## Editor integration
103
107
104
108
For editor integration, use
105
-
```
109
+
110
+
```sh
106
111
fprettify --silent
107
112
```
113
+
108
114
For instance, with Vim, use fprettify with `gq` by putting the following commands in your `.vimrc`:
## Deactivation and manual formatting (experimental feature)
115
121
116
122
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:
123
+
117
124
```fortran
118
125
A = [-1, 10, 0, &
119
126
0, 1000, 0, &
120
127
0, -1, 1]
121
128
```
129
+
122
130
In order to manually align the columns, fprettify needs to be deactivated by
131
+
123
132
```fortran
124
133
A = [-1, 10, 0, & !&
125
134
0, 1000, 0, & !&
126
135
0, -1, 1] !&
127
136
```
137
+
128
138
or, equivalently by
139
+
129
140
```fortran
130
141
!&<
131
142
A = [-1, 10, 0, &
@@ -134,10 +145,6 @@ A = [-1, 10, 0, &
134
145
!&>
135
146
```
136
147
137
-
138
148
## Contributing / Testing
139
149
140
150
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