Glavin001/atom-beautify

Add Fortran language support

Glavin001 opened this issue · 3 comments

@janmolnar has forked Atom Beautify and added a beautifier for Fortran. May be worth taking a look into.
See janbernloehr@a7b5799

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.

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:

  1. Create a new Language file in https://github.com/Glavin001/atom-beautify/tree/master/src/languages
  2. Configure the new language. Example for JavaScript language: https://github.com/Glavin001/atom-beautify/blob/master/src/languages/javascript.coffee#L8
    • name - name of Language
    • namespace - used as a prefix for scoping the options, such as option indent_size becomes js_indent_size for JavaScript language with namespace js
    • grammars - array of supported grammars. Used with extensions to determine if this file is this language or not. Grammars are prioritized over extensions, such that the grammar JavaScript is recognized before js 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 is js. 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.
  3. Add the language file to the list of language names. For instance, c-sharp.coffee file becomes c-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

  1. Create a new beautifier subclass in https://github.com/Glavin001/atom-beautify/tree/master/src/beautifiers directory
  2. Implement beautifier:
    • See examples of beautifiers:
    • options - the key represents the Language's name, so Fortran. The value could be true (supports all options), false (supports language, with no options), or an object 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 a Promise (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), and options is an object of all of the options in their form as described by your Language definition (see Configure the new language above).
  3. Add beautifier to list of beautifierNames: https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/index.coffee#L34
  4. Add test example files in https://github.com/Glavin001/atom-beautify/tree/master/examples

I have to go. Let me know if you have any questions!

Published to v0.27.10