Modifying smart indent behaviour

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
rskar
Posts: 4
Joined: Fri Jul 27, 2007 3:55 pm

Modifying smart indent behaviour

Post by rskar »

Hi,

I am currently evaluating ZeusEdit for use at my day job. At my day job there are code standards related to indenting that I can't get SmartIndenting to work with. If I set tab size to 8 and indent size to 4 I want SmartIndenting to work like this:

Code: Select all

if( test_condition ) {
    //Start of this line is 4 spaces in from the start of the previous line
    //This line is lined up with the line above it
    some code here;
} //This brace is lined up with the 'i' of the if
// this line isn't indented anymore

if( test_condition_2 {
    some more code;
    if( test_condition_3 ) {
        //This line is 4 spaces in from the if on the line above
        even more code here;
    } else {//again, this open brace lined up with the i of the if it 
corresponds to
        //This line is 4 spaces in from the open brace on the line above
    }
}
It seems that SmartIndenting is using the tab stop to set the indent, not the indent value. Is there anyway I can change this?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

It should not matter but do you have the tabs as space option off or on (i.e. are there tabs in the document or only spaces) :?:

The indent value represents the size of the first tab stop from column 1. So with an indent of 4 and a tab size of 8 Zeus will tab to column locations 5 then to 13, 21,29 etc.

So if I setup zeus with an indent of 4 and tab size of 8 if I enter this code:

Code: Select all

if (test) {<enter her>
{
Zeus will generate this code:

Code: Select all

if (test) {
     |< cursor here
}
When the if startment is at column 1 then the next tab will be at 5 so the cursor goes to column file. When the if statement is at column 5 the next tab stop is at 13 so the cursor will end up at this column.

Cheers Jussi
rskar
Posts: 4
Joined: Fri Jul 27, 2007 3:55 pm

Post by rskar »

jussij wrote:It should not matter but do you have the tabs as space option off or on (i.e. are there tabs in the document or only spaces) :?:
I have the tabs as spaces option off, which is what I want (I want tabs in the document).
jussij wrote: So if I setup zeus with an indent of 4 and tab size of 8 if I enter this code:

Code: Select all

if (test) {<enter her>
{
Zeus will generate this code:

Code: Select all

if (test) {
     |< cursor here
}
When the if startment is at column 1 then the next tab will be at 5 so the cursor goes to column file. When the if statement is at column 5 the next tab stop is at 13 so the cursor will end up at this column.
Ok, so this isn't quite what I want and I'm wondering how I modify it. What I want is for the indent value to be the number of spaces (or the size of a tab) a line is indented from the line above it. So if I have an if statement starting on column 5 I want the indent to go to column 9, not 13.
Here's some example code (tab size 8, indent size 4):

Code: Select all

        if ( mycondition == true ) {
                   //this isn't in the correct spot...
        }

This is what I am looking for:

Code: Select all

        if ( mycondition == true ) {
            //this IS in the correct spot...
        }
So is there a way that I can change the default Zeus behavior?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

What I want is for the indent value to be the number of spaces (or the size of a tab) a line is indented from the line above it.
If the Smart indenting option is enabled then Zeus will take the white space from the line above to line up the new line. The line should be copied exactly including any combination of tabs or spaces.

You should be able to see this if you turn on the visual white space option using the View, White Space menu.
So if I have an if statement starting on column 5

After hitting enter Zeus will have placed the cursor at column 5 to match the indent from the line above.

Then as you typed in the if Zeus will copy the white space from the line above to prefix the if statement.
I want the indent to go to column 9, not 13.
The big question is what are the tab stops you expecting to see :?:

For example with the cursor at column 1 and hitting the tab key several times where do you expect the cursor land for each tab key :?:

In this example is column 5 the first tab stop or the second and what tab stop is column 9 :?:

The indent value defines the first tab stop and the tab size defines all subsequent tab stops. So for example if column 5 is tab stop one and column 9 is tab stop two then you would need an indent of 4 and the tab size is 4. The next tab stops would be column 13, 17 etc

But since the indent is the same as the tab size it is irrelevant so you can just leave the indent set to 0.

Also remember the enter an tab keys tie in several features. The enter key is using the smart indenting and the tab key is tied to the smart tabbing feature. You can turn off the smart indenting using the option in the Templates panel and you can turn of the smart tabbing by re-mapping the Tab key.

So again I think the real question is what tab stops do you expect to see :?:

Cheers Jussi
rskar
Posts: 4
Joined: Fri Jul 27, 2007 3:55 pm

Post by rskar »

jussij wrote:
So again I think the real question is what tab stops do you expect to see :?:
I want the tab stops to be at column 9, column 17, column 25, column 33, etc... but I sort of want the indenting to be independent of that. Basically I wan the indenting to work the way it does in Visual Studio. Here's the difference:
Visual studio (tab size 8, indent size 4):

Code: Select all

    if( some condition ) {
        |< visual studio puts the cursor here, the if starts in column 5, this line starts on column 9
        if( my second level condition ) {
            |< //again, visual studio puts the cursor here, the if above starts in column 9 this line starts on column 13
        }
    }
In Zeus:

Code: Select all

    if( some condition ) {
               |< Zeus puts the cursor here, in column 13
               if( my next condition ) {
                         |< Zeus puts the cursor here, in column 21
               }
    }
If I just turn off the SmartIndenting then I have to do the indenting myself which is a task that I expect the editor to handle. If I have to write a script to modify the behavior or SmartIndenting, I'm fine with that but I'm not really sure how to write the script.

Actually after doing a little more experimentation with Visual Studio it appears as though Visual Studio is putting tab stops every 4 columns even though the tab size is set to 8. If I set the tab size to 4 and indent to 0 in Zeus then it behaves the same was as Visual Studio does with tab size set to 8 and indent set to 4. I didn't realize that Visual Studio was so strange with respect to how tabs and indents work.
rskar
Posts: 4
Joined: Fri Jul 27, 2007 3:55 pm

Post by rskar »

Ok, after a little more investigation I think that I've got Visual Studio's handling of indent and tab sizes figured out. The indent size sets the tab stop, so there is a tab stop every 4 columns. The tab size seems to affect when an actual tab gets inserted as opposed to spaces.

If you just hit the tab key a few time what happens is the first time you hit it 4 spaces get inserted. The next time you hit it, a tab gets inserted. The time after that 4 spaces, then a tab, then 4 spaces, etc... So if you are within 4 columns of a multiple of a tab size, you get a tab, if there is a tab stop (which seems to be determined by the indent size) between a full tab size and where you currently are, you get spaces to the next tab stop (again, determined by the indent size, not the tab size).
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

If you just hit the tab key a few time what happens is the first time you hit it 4 spaces get inserted. The next time you hit it, a tab gets inserted.

That is bizaar behaviour :?

The only way you could get Zeus to do something similar would be to write a tab macro to replace the Zeus tab function something similar to the following:

Code: Select all

function key_macro()

  -- macro only works for documents
  local document = is_document()

  -- macro only works for read/write documents.
  local locked = is_read_only()

  if (locked == 1) or (document == 0) then
    -- let the tab handle the unexpected case
    Tab()
  else
    local TAB_SIZE = 4

    -- get cursor position
    local cursor = get_cursor_pos();

    -- look for the first tab case
    if (cursor <= TAB_SIZE) then
        -- put out a tabs worth of spaces
        for i = cursor, TAB_SIZE, 1 do
            write(" ")
        end
    else
        -- let tab do the rest
        --Tab()
        --or
        write("\t")
    end
  end
end

key_macro() -- run the macro
Cheers Jussi
Post Reply