smart code formatter

General FreeBASIC programming questions.
srvaldez
Posts: 2152
Joined: Sep 25, 2005 21:54

smart code formatter

Postby srvaldez » Jun 19, 2019 19:00

somehow, after editing a file on different OS's, I wound up with mixed spaces and tabs, does anyone know of a smart code reformatter that will replace spaces with tabs?
note that in some areas there are 3 spaces and at others 4 or 5 spaces.
I tried search and replace, but it will take me forever to finish, especially troublesome are tabs between asm instructions and operands, as the instructions vary in length, you may need 1 or 2 tabs between instruction and operand to make them line up.
jj2007
Posts: 1262
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: smart code formatter

Postby jj2007 » Jun 19, 2019 19:24

The RichMasm editor has an autoformat function, but it's very specialised on x86 assembler. It would be helpful if you posted a hundred lines of example code... how many lines is the source you want to reformat?
srvaldez
Posts: 2152
Joined: Sep 25, 2005 21:54

Re: smart code formatter

Postby srvaldez » Jun 19, 2019 20:08

there are about 2100 lines of code including spacers between functions/subs, it's a mix of FB code and inline asm.
jj2007
Posts: 1262
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: smart code formatter

Postby jj2007 » Jun 19, 2019 20:42

Do you want to make a test? If it's not confidential, upload it somewhere, otherwise post a hundred lines here. If you prefer, I can give you my email here, but it would disappear asap.
badidea
Posts: 1610
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: smart code formatter

Postby badidea » Jun 19, 2019 21:05

Sound like fun.
I can only give some advice on how to prevent it:
1) Always use an editor that shows white-space characters
2) Don't use tabs between statements (only for indentation)

I had a productive evening yesterday as well. After 1 hour of coding, I accidentally deleted it all by pasting some other code over it instead of inserting. Discovered it only later after saving and closing the file.
srvaldez
Posts: 2152
Joined: Sep 25, 2005 21:54

Re: smart code formatter

Postby srvaldez » Jun 20, 2019 11:35

@jj2007
I don't want to post code here, no need to give people a headache, thanks for the offer though, in the meantime, several iterations of search&replace does the job.
offtopic, I found that it's easy to call the mingw sscanf and sprintf to input/output 80-bit reals.
RockTheSchock
Posts: 226
Joined: Mar 12, 2006 16:25

Re: smart code formatter

Postby RockTheSchock » Jun 20, 2019 15:41

Regular expressions are very useful:
search pattern: ^(\t*)[ ]{3,5}
replace with: $1\t

Explanation:
linebeginning followed by arbitrary number of tabs followed by 3-5 spaces and
replaced by preveoiusly found tabs + one tab replacing 3-5 spaces.

search and replace several times with notepad++

Spaces converted to Tabs+Spaces
5S -> 1
3S -> 1
4S -> 1
2S -> 2S
6S -> 1T+1S
8S -> 2T
srvaldez
Posts: 2152
Joined: Sep 25, 2005 21:54

Re: smart code formatter

Postby srvaldez » Jun 20, 2019 15:54

@RockTheSchock
thank you
TJF
Posts: 3486
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: smart code formatter

Postby TJF » Jun 28, 2019 17:44

Geany has a feature to replace tabs by spaces and vice versa, asking for the tab width before operation. It also supports addaption of line ends. Find the features in the 'document' menu.

And it supports regular expressions for search/replace.

Regards
srvaldez
Posts: 2152
Joined: Sep 25, 2005 21:54

Re: smart code formatter

Postby srvaldez » Jun 28, 2019 17:55

@TJF
thanks for the tip :-)

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests