レナート   Wunschkonzert, Ponyhof und Abenteuerspielplatz   ﻟﻴﻨﺎﺭﺕ

Thu, 10 May 2007

Cuddle opening function braces, anyone?

Dear Lazyweb!

Does anyone know how I can teach GNU indent to cuddle opening function braces and the closing ')' of the argument list ? i.e.

int main(int argc, char* argv[]) {
}

instead of:

int main(int argc, char* argv[]) 
{
}

Any help appreciated!

posted at: 16:22 | path: /projects | permanent link to this entry | 12 comments


Posted by man indent at Thu May 10 17:18:41 2007
-br -ce

Posted by Lennart at Thu May 10 17:30:14 2007
man indent: there is nothing about function brace cuddling in the man page. Also, -br -ce doesn't work.

Posted by andy at Thu May 10 18:36:48 2007
Lennart, yes there is. Look under STATEMENTS in the manpage (http://torch.cs.dal.ca/~johnston/unix/indent.html):

Posted by andy at Thu May 10 18:41:22 2007
Sorry, my bad. I was thinking about if-statments.

Posted by not-quite-replying-to-the-question-man at Thu May 10 20:04:22 2007
apt-get install astyle ?

Posted by foo at Thu May 10 20:34:37 2007
It should be formatted as


int
main (int  argc,
  char *argv[])
{
}


anyway.

Posted by Benjamin at Thu May 10 23:30:58 2007
I have -brf in my .indent.pro for that, even though i can't find any trace of it in the man page

Posted by clee at Fri May 11 00:54:44 2007
Looks like `indent -brf -br -ce -kr` does that, or something close to it!

Posted by Ray Strode at Sat May 12 00:26:18 2007
I discovered uncrustify the other day (it's in fedora extras).

It's similar to indent, but uses a configuration file instead of command line options.  The default config is pretty well documented and has a toggle for what you're asking for.

Posted by Lennart at Mon May 14 00:22:19 2007
Benjamin: Thank you! -brf does the job! Perfect! I posted a Debian bug about this now (#423692).

Posted by Mattias at Mon May 14 15:57:14 2007
I was looking for this right now too. Great that you found the problem and filed a bug about it.
However.
I'm wondering how i get this behaviour:
  int main(int argc, char* argv[]) {
  ..
  }
instead of this
  int
  main(int argc, char* argv[]) {
  ..
  }

Ie. i'd like the type of the functions to be on the same line as the function name and argument list.

Posted by Mattias at Mon May 14 16:29:05 2007
-npsl was the flag for me. I just had to read the man page the third time to find it.
I'm obviously blind. :)

Leave a Comment:

Your Name:


Your E-mail (optional):


Comment:


As a protection against comment spam, please type the following number into the field on the right:
Secret Number Image

Please note that this is neither a support forum nor a bug tracker! Support questions or bug reports posted here will be ignored and not responded to!


It should be obvious but in case it isn't: the opinions reflected here are my own. They are not the views of my employer, or Ronald McDonald, or anyone else.

Please note that I take the liberty to delete any comments posted here that I deem inappropriate, off-topic, or insulting. And I excercise this liberty quite agressively. So yes, if you comment here, I might censor you. If you don't want to be censored your are welcome to comment on your own blog instead.


Lennart Poettering <mzoybt (at) 0pointer (dot) net>
Syndicated on Planet GNOME, Planet Fedora, planet.freedesktop.org, Planet Debian Upstream. feed RSS 0.91, RSS 2.0
Archives: 2005, 2006, 2007, 2008, 2009, 2010, 2011

Valid XHTML 1.0 Strict!   Valid CSS!