Add Fortran language support
Glavin001 opened this issue · 3 comments
Glavin001 commented
@janmolnar has forked Atom Beautify and added a beautifier for Fortran. May be worth taking a look into.
See janbernloehr@a7b5799
janbernloehr commented
Please tell me if there is something I should do to make this happen. The current implementation invokes emacs to format the fortran script. In this way I can format code part of legacy projects in a consistent way.
Glavin001 commented
You could submit a Pull Request adding Fortran support 😃.
I am still working on the documentation for this. Here's a quick overview.
How to add a Language:
- Create a new Language file in https://github.com/Glavin001/atom-beautify/tree/master/src/languages
- Configure the new language. Example for
JavaScript
language: https://github.com/Glavin001/atom-beautify/blob/master/src/languages/javascript.coffee#L8name
- name of Languagenamespace
- used as a prefix for scoping the options, such as optionindent_size
becomesjs_indent_size
forJavaScript
language with namespacejs
grammars
- array of supported grammars. Used withextensions
to determine if this file is this language or not. Grammars are prioritized over extensions, such that the grammarJavaScript
is recognized beforejs
and the beautifier with the same grammar as the file will be used over another that does not support the grammar and only the extension.extensions
- array of extensions, without.
(dot), such that.js
isjs
. Used to determine if a file is this language. Useful if there is no supported grammar in Atom for this language.options
- I'd recommend looking at https://github.com/Glavin001/atom-beautify/blob/master/src/languages/javascript.coffee#L30 for examples.
- Add the language file to the list of language names. For instance,
c-sharp.coffee
file becomesc-sharp
. See https://github.com/Glavin001/atom-beautify/blob/master/src/languages/index.coffee#L21
Now your Language is available and can be detected and beautifiers can support it.
How to add a Beautifier for a Language
- Create a new beautifier subclass in https://github.com/Glavin001/atom-beautify/tree/master/src/beautifiers directory
- Implement beautifier:
- See examples of beautifiers:
- Prettydiff is a good example of complex options: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/prettydiff.coffee
- PHP-CS-Fixer is a good example of a CLI beautifier with arguments: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/php-cs-fixer.coffee#L15-L39
options
- the key represents the Language's name, soFortran
. The value could betrue
(supports all options),false
(supports language, with no options), or anobject
whose keys are option keys and values are complex mappings. If you need to use these, let me know.true
is probably what you want.- The
beautify
function should return aPromise
(use@Promise
as shown). The arguments passed are:text
, the source code from Atom's Text Editor,language
is a string of the language's name (Fortran
), andoptions
is an object of all of the options in their form as described by your Language definition (seeConfigure the new language
above).
- See examples of beautifiers:
- Add beautifier to list of
beautifierNames
: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/index.coffee#L34 - Add test example files in https://github.com/Glavin001/atom-beautify/tree/master/examples
- You can put your test in
nested-jsbeautifyrc
directory, https://github.com/Glavin001/atom-beautify/tree/master/examples/nested-jsbeautifyrc - create a new directory for your tests, named something like
Fortran
original
andexpected
directory containing files that are named the same. Prefix underscore (_
) disables a test. See https://github.com/Glavin001/atom-beautify/tree/master/examples/simple-jsbeautifyrc/php/original for instance.- change any options you need in your namespace, such as
fortran
, in https://github.com/Glavin001/atom-beautify/blob/master/examples/nested-jsbeautifyrc/.jsbeautifyrc - Run tests in Atom with command
Window: Run package spec
- You can put your test in
I have to go. Let me know if you have any questions!
Glavin001 commented
Published to v0.27.10