Tabs as spaces not working as expected

If reporting a bug with the Zeus IDE please post the details here. Please do not post questions here.
Post Reply
engicoder
Posts: 10
Joined: Wed May 18, 2011 1:54 pm

Tabs as spaces not working as expected

Post by engicoder »

Zeus 3.97f on Windows 7

The C/C+ document type has the "Tabs as spaces" option checked. I assume that this option means that the tab character should never be inserted when pressing tab, but rather a number of spaces will be inserted.
I am seeing tab characters inserted when this option is checked.
The behavior is not consistent. Sometimes it inserts spaces, sometimes tabs. I haven't been able to work out any hard rules. It does seem like tabs will be inserted more often if the line already has tabs in it. It also seems to affect template actions if the start of the template already had a tab in it. Furthermore, if text cut from another source containing text is pasted, the tabs remain and seem to trigger future tab insertion.
I can give you one recreate scenario:
  • Open a C document.
    Paste a line with a tab followed by a '{' (open bracket) from another file.
    Press enter after the '{'. The template completion will contain tabs.
I can provide a sample if that would help. It contains tabs and if you play around with it, I am sure you will find instances where tabs are inserted instead of spaces.

I really don't want any tabs to exist in the document, ever, if Tabs as spaces is checked. Is this what you intended?

Ben

Note: I can work around this by doing a blank replace '\t' with spaces from time to time.
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

The behavior is not consistent.

It should be consistent and predictable.
Sometimes it inserts spaces, sometimes tabs. I haven't been able to work out any hard rules.

This is the Smart Indent working and the rule it uses is to copy the whitespace from line above.

If you turn on the View, White space menu option you will see that the Smart Indent is using the white space details from the line above to indent the new line.
Furthermore, if text cut from another source containing text is pasted, the tabs remain and seem to trigger future tab insertion.

The insert tabs as spaces option by design only effects how the Tab keyboard key works. If has no other effect what so ever on tab characters.

Cheers Jussi
engicoder
Posts: 10
Joined: Wed May 18, 2011 1:54 pm

Post by engicoder »

I do love the Smart Indent feature. One oddity is that if the previous line starts with a TAB and I press enter at the end of that line and then TAB at the start of the next (with Tabs as spaces on) it will still insert a TAB character. I think the Smart Indent overrides it.
I happy to live with that. My problem really started when I cut and pasted some code with TABs in it into my code where I didn't want TABs...from that point on, the Smart Indent was just doing its job. My lesson is too make sure I replace tabs when I cut and paste from other sources (like websites)

Thanks again for the help
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Ben,
I do love the Smart Indent feature.
So do I :)
I think the Smart Indent overrides it.
It certainly does. The reason for this is I don't want Zeus to force the user to use tabs any particular way.

For example, consider a user who likes to use tabs as an indent only character (some say this is the only way to uses tabs).

For that user, it is easy enough to write a replacement tab keyboard macro that only inserts tabs if the cursor is at the first column location.

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
        message("This macro only works for writable document files.");
        beep();
        return;
    end

    if (get_cursor_pos() == 1) then
        -- put in an actual tab character no matter what the settings say
        TabHard()
    else
        -- leave the rest up to smart tabbing
        TabSmart()
    end
end

key_macro() -- run the macro
So for that user the tab key would only insert a tab character at the start of line and everywhere else tabs would be replaced by spaces. Also the smart indent would also honour this tab configuration.

So in other words with a bit of tweaking, Zeus should be able to handle tabs anyway the user desires.
My lesson is too make sure I replace tabs when I cut and paste from other sources (like websites)
I don't like hard tabs so I'm have the exact same issue :)

In situations like this, what I tend to do is use search and replace, searching for \t and just replacing it with whitespace.

For cases where the above search an replace destroys the formatting, I then tend to use the Macros, Re-indent and re-style code menu as this macro will also removes tabs if the tabs as spaces option is on.

Cheers Jussi
Post Reply