fortran-lang / vscode-fortran-support

Fortran language support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran
MIT License
217 stars 30 forks source link

Add a FORTRAN formatter #29

Closed yonadav closed 3 years ago

yonadav commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

krvajal commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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...

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

han190 commented 5 years ago

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 commented 5 years ago

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

PR are welcome

han190 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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.