Tab as spaces

Questions on using RSyntaxTextArea should go here.

Moderator: robert

Tab as spaces

Postby kriro » Tue Jan 26, 2010 2:58 pm

Hello,

is there a way to insert a tab as a specified number (=tab size) of spaces?

I feel that using real tabs on documents that pass through several different editors is often a nightmare, especially when those editors use different settings for the tab size. Therefore my aim is to remove tabs from documents altogether and replace them with spaces already at "tab insertion" time. That makes the formatting consistent - at least with fixed-width fonts.

I have not found an option to do just that so far. Is this a feature you would consider for a future release, or should I go about it myself?

Looking through the code I found instances of hard-coded "\t" insertions in the indent actions. Essentially, my idea was to replace any hard-coded "\t" insertion by a new function call like getTabRespresentation(), where this method would either return a single tab character or the corresponding number of spaces, depending on some preference setting.

Where in the hierarchy would I best start to subclass to implement this? Currently, it looks like overriding just those actions is not enough as they are hard-referenced from the respective editor classes that use them in final arrays (which I'd need to "override" as well). I have the feeling this makes me more dependent on a specific release of RSTA than I want - but maybe I just haven't thought it through enough yet. Any tips, ideas or caveats in this regard?

Thanks
Christian
kriro
 
Posts: 3
Joined: Wed Dec 16, 2009 7:13 pm

Re: Tab as spaces

Postby robert » Tue Jan 26, 2010 6:26 pm

Hi Christian,

This functionality is already built in:

Code: Select all
textArea.setTabSize(4);
textArea.setTabsEmulated(true); // Whether pressing tab should really just insert spaces


You can also convert all tabs in a document into the correct number of spaces:

Code: Select all
textArea.convertTabstoSpaces();
textArea.convertSpacesToTabs(); // Not what you want to do, but in case you want to go back and forth


Let me know if this fits your needs!
User avatar
robert
 
Posts: 805
Joined: Sat May 10, 2008 5:16 pm

Re: Tab as spaces

Postby kriro » Tue Jan 26, 2010 8:53 pm

Of course, this is exactly what I was looking for!

Oh well - must have been blind... :oops:

Thanks,
Christian
kriro
 
Posts: 3
Joined: Wed Dec 16, 2009 7:13 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 2 guests

cron