You are not logged in.

#1 2009-01-05 09:39:36

onguarde
Member
Registered: 2008-09-14
Posts: 144

Auto Formatting of Source Code

Peace!

Is there a way to automatically format a given source code interactively while typing? As far as I know, it is only possible to enter if(/tab to get

if(  )
{

}

Is there a way to automatically format x=x+2; to

x = x + 2;/n

for easier reading without manually entering spacebar and enter at the end.

I am currently using the geany IDE.

http://en.wikipedia.org/wiki/Indent_style

Thanks!

Offline

#2 2009-01-05 10:14:56

u_no_hu
Member
Registered: 2008-06-15
Posts: 453

Re: Auto Formatting of Source Code

Almost all programmers editors(vim ,emacs etc) support auto indentaion for almost all programming languages....

but x=x+2..... i dont know if that is  possible...


Don't be a HELP VAMPIRE. Please search before you ask.

Subscribe to The Arch Daily News.

Offline

#3 2009-01-05 10:24:54

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Auto Formatting of Source Code

Is it really so much effort to press the space bar and enter button..?

Offline

#4 2009-01-05 22:17:17

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Auto Formatting of Source Code

It's certainly possible to make this happen. Inserting newlines and indenting automatically when ; is pressed would be especially easy. Automatic spacing around operators would be trickier, but possible. Probably when a char that only appears in an operator is pressed you could call a function that adds spaces or not depending on the context. It could add a space before unless there already is one or the preceding char is part of an operator, and could add one after in all cases. If the preceding char is a space and the char before that is part of an operator, it could delete the space.

However I find autocorrection more annoying than not.

Last edited by pauldonnelly (2009-01-05 22:18:27)

Offline

#5 2009-01-05 22:49:08

laplace
Member
From: West Germany
Registered: 2009-01-05
Posts: 22

Re: Auto Formatting of Source Code

it would take me around 15 minutes to write a programm that handle files and alter its structure this way, if you spend this amount of time you would have a convenient way wink

Offline

#6 2009-01-08 09:01:43

onguarde
Member
Registered: 2008-09-14
Posts: 144

Re: Auto Formatting of Source Code

Thanks for all the replies.

Barrucadu wrote:

Is it really so much effort to press the space bar and enter button..?

Well, it's not.... but it's really a hassle especially when it's unnecessary. It's pretty much a given I will press enter right after ";", might as well reduce it to 1 keystroke.

I'll need more research on this i guess..

Offline

#7 2009-01-08 12:18:43

Ruckus
Member
Registered: 2007-02-17
Posts: 204

Re: Auto Formatting of Source Code

To each his own style I suppose. Personally, I abhor editors that insert things without me asking. I do like editors that auto indent though. Geany is my personal favorite editor on Linux, EditPadPro is my favorite editor under Windows.

Offline

Board footer

Powered by FluxBB