Skip to content

Add a FORTRAN formatter #29

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

Closed
yonadav opened this issue Feb 6, 2018 · 13 comments · Fixed by #256
Closed

Add a FORTRAN formatter #29

yonadav opened this issue Feb 6, 2018 · 13 comments · Fixed by #256

Comments

@yonadav
Copy link

yonadav commented Feb 6, 2018

An amazing implementation of FORTRAN editing.
A FORTRAN formatter would be very helpful enhancement (at least for the free format FORTRAN code file structure, FORTRAN 90 and up) .
Format document and format selected like in the c/c++ extension.

@krvajal
Copy link
Collaborator

krvajal commented Feb 7, 2018

Formatting source code is a very opinionated thing and each one has his own code style. Also I don't have the time to implement a formatting algorithm. But PR are welcome 👍

@yonadav
Copy link
Author

yonadav commented Feb 11, 2018

Full formatting, like in many Visual Studio implementations, is indeed complex and in many cases a matter of personal preference. I actually ment only post indenting of a code that was originally written without indentation or a non consistant indentation.
Also syntax highlighting does not support some of he modern keywords and constructs like bind, value, reference, enum (and consequently enumerator).
Indentation while typing does not support type declaration, select case statement, and enum.

I fixed some of the syntax highlighting privately on my vc code installation and the auto indentation as well. however, I failed to indent the internal case whithin a select case statment more than the select case.
I never used github before (besided complaining ... and openning issues)
Should I open a pull request for those modifications? (I will have to learn how, but there is a first time for everything)

@alexandresardinha
Copy link

@yonadav I suggest you read this: https://guides.github.com/activities/forking/
It's pretty simple!

@krvajal
Copy link
Collaborator

krvajal commented Mar 19, 2018

@yonadav would you like to open an issue for the auto indentation issues that you are having with the new Fortran keywords you mentioned about here?

@krvajal
Copy link
Collaborator

krvajal commented Oct 15, 2018

@yonadav are you still willing to share your fixes?
I can guide you through the process of how to contribute to the project if you want to.

@yonadav
Copy link
Author

yonadav commented Oct 15, 2018

Thanks for the offer but I currently don't have the time to do that.
I had some thoughts in the past to replace emacs (we write in Linux) with VSCode, it is fast lite and modern. Although emacs is old it supports all modern FORTRAN (at least up to F2003) keywords, indentations, and auto indentation of selected region, subprogram or whole file.

@pedro-ricardo
Copy link
Collaborator

pedro-ricardo commented Oct 16, 2018

Adding this here just to keep it for future reference:
emacs has a F90 formatter that uses the following eviroment variables to format the file...

  • Associate indent
    // Indentation applied to ASSOCIATE blocks

  • Continuation indent
    // Indentation applied to continuation lines

  • Critical indent
    // Indentation applied to BLOCK and CRITICAL blocks

  • Do indent
    // Indentation applied to DO blocks

  • If indent
    // Indentation applied to IF, SELECT CASE, WHERE and FORALL blocks

  • Program indent
    // Indentation applied to PROGRAM, MODULE, SUBROUTINE, FUNCTION blocks

  • Type indent
    // Indentation applied to TYPE, ENUM, INTERFACE and BLOCK DATA blocks

In our case, the number of spaces in each indentation can be set based on VSCode editor.tabSize configuration for example.

@han190
Copy link
Contributor

han190 commented Dec 10, 2018

Thanks for create this useful extension!
I agree with @yonadav . The only reason I am still using Emacs for Fortran is because it has a nice formatter. It would be nice if you could just add an option for us to use Emacs indentation directly by importing executable Emacs path. (Like atom-beautify)

@pedro-ricardo
Copy link
Collaborator

pedro-ricardo commented Dec 10, 2018

@han190 This feature here is desirable for everyone, but we are short in developers right now 👎 . Your idea is simpler, probably easier to implement, it could be a nice first step 👍 . Thank you!
Like said before :

PR are welcome

@han190
Copy link
Contributor

han190 commented Dec 11, 2018

Guys, there is an alternative/crappy fix if you are really annoyed by the indentation. Go ahead and copy the file from here:
https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/fortran-beautifier/emacs-fortran-formating-script.lisp
Save it under any directory you like, for example, /Users/usrname/.emacs-batch-f90-indent.lisp. Then as introduced by the file, open a terminal from VS-code and type
emacs -batch -l ~/.emacs-batch-f90-indent.lisp -f f90-batch-indent-region *.f90
or you can alias the command with some shortcut and save it to bash file. I know it is crappy but at least I don't have to switch between VS-code and Emacs when editing Fortran files.

@JHenneberg
Copy link

according to this post auto indent is possible in VS Code
https://code.visualstudio.com/updates/v1_14#_auto-indent-on-type-move-lines-and-paste

It looks very similar to the ATOM version. There is also a language-fortran package availuable for ATOM which has the indention rules already integrated, so they could be copyed from there.
https://github.com/dparkins/language-fortran/blob/master/settings/language-fortran.cson

@gnikit
Copy link
Member

gnikit commented Oct 14, 2019

A decent solution that has worked for me in the past, especially with large projects, is fprettify https://github.com/pseewald/fprettify. Although it focuses mostly on formatting whitespaces.

@wvermin
Copy link

wvermin commented May 3, 2020

Check out https://sourceforge.net/projects/findent/ . That is a very fast fortran indenting program, also converts from fixed format to free format and vice-versa and understands fortran 66 until fortran 2018.

gnikit added a commit that referenced this issue Sep 21, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
@gnikit gnikit mentioned this issue Sep 21, 2021
4 tasks
@gnikit gnikit linked a pull request Sep 21, 2021 that will close this issue
4 tasks
gnikit added a commit that referenced this issue Oct 1, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
gnikit added a commit that referenced this issue Oct 3, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
gnikit added a commit that referenced this issue Oct 12, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
gnikit added a commit that referenced this issue Oct 15, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
gnikit added a commit that referenced this issue Oct 19, 2021
Adds support for `findent` and `fprettify`. Fixes #29.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants