#2281 Code formatter

ahhatem Wed 7 May 2014

Does anyone have a code formatter that I can easily use with VIM?

SlimerDude Wed 7 May 2014

I use the keyboard myself! :D

But, um, sorry no. I don't know of any code formatters for Fantom.

brian Wed 7 May 2014

There are various editor support files under /adm/tools. There is VIM formatter too, see bitbucket link

ahhatem Thu 8 May 2014

I am already using the syntax file but I don't think it does code formatting. Right?

matthew Mon 12 May 2014

Not sure if you are aware, but VIM has some capabilities built-in for code formatting/indentation

http://vim.wikia.com/wiki/Indent_a_code_block

While the VIM distribution includes a fan.vim syntax highlighting file, it does not ship with fantom indentation rules (it would be in $VIM_HOME/indent/).

The java rules might be good enough for fantom, and you could try that. If you end up creating some indentation rules that work well for fantom be sure to post and let us know where we can get them.

ahhatem Mon 12 May 2014

Yes, I am aware of it, if you add semicolumns in all statements it works in many cases but not all... It still has many problems... I may try to enhance the java formatter, it should be quite close to Fantom's.

ahhatem Mon 12 May 2014

I found that tweaking the C formatter by adding this at the end of the fan.vim helps in making the default formatter ignore correctly the lack of semi columns... still has problems in many cases but at least the general structure is better...

This is extracted from go formatter.

" C indentation is mostly correct
setlocal cindent

" Options set:
" +0 -- Don't indent continuation lines (because Go doesn't use semicolons
"       much)
" L0 -- Don't move jump labels (NOTE: this isn't correct when working with
"       gofmt, but it does keep struct literals properly indented.)
" :0 -- Align case labels with switch statement
" l1 -- Always align case body relative to case labels
" J1 -- Indent JSON-style objects (properly indents struct-literals)
" (0, Ws -- Indent lines inside of unclosed parentheses by one shiftwidth
" m1 -- Align closing parenthesis line with first non-blank of matching
"       parenthesis line
"
" Known issue: Trying to do a multi-line struct literal in a short variable
"              declaration will not indent properly.
setlocal cinoptions+=+0,L0,:0,l1,J1,(0,Ws,m1

I will try to solve the issues as I go forward...

mkarmona Sun 8 Feb 2015

I've just created a bitbucket repo to use with NeoBundle. Syntax file from fantom zip. Any comments are welcome.

Login or Signup to reply.