cindent problem for case sentence

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

cindent problem for case sentence

Hans-5
Dear Vimmers,

        I've met a problem with cindent for case sentence.
The option cinoption of GVim6.3.86 is cino="".

Below is the auto indention result:
-----------------------------------------------------
    switch (profiling_fsm)
    {
        char file_name[32];
        bool flag;

        case PROF_OPEN:
        switch (profiling_cnt) {
            case 1:
                strcpy(file_name, "mon.out");
                break;
                        case 2:
                                strcpy(file_name, "mon2.out");
                                break;
                        case 3:
                                strcpy(file_name, "mon3.out");
                                break;
                        default:
                                error_msg("No such file!");
                                break;
                }
                flag = false;
                profiling_fsm = PROF_SEEK_GIO;
                break;
                default:
                error_msg("profiling FSM in unknown state!");
                break;
        }
----------------------------------------------------------
Why the outer case code block has 0 character indention, while
the inner case code block has shiftwidth indention?

Thanks!

Yorkwar
20051014

Reply | Threaded
Open this post in threaded view
|

Re: cindent problem for case sentence

Jürgen Krämer

Hi,

Yorkwar wrote:

>
> I've met a problem with cindent for case sentence.
> The option cinoption of GVim6.3.86 is cino="".
>
> Below is the auto indention result:
> -----------------------------------------------------
>     switch (profiling_fsm)
>     {
>         char file_name[32];
>         bool flag;
>
>         case PROF_OPEN:
>         switch (profiling_cnt) {
>             case 1:
>                 strcpy(file_name, "mon.out");
>                 break;
> case 2:
> strcpy(file_name, "mon2.out");
> break;
> case 3:
> strcpy(file_name, "mon3.out");
> break;
> default:
> error_msg("No such file!");
> break;
> }
> flag = false;
> profiling_fsm = PROF_SEEK_GIO;
> break;
> default:
> error_msg("profiling FSM in unknown state!");
> break;
> }
> ----------------------------------------------------------
> Why the outer case code block has 0 character indention, while
> the inner case code block has shiftwidth indention?

this behaviour seems to be caused by the variable definitions at the
start of the first switch block. Putting them outside the block gives
the correct indent. If you want to/must restrict the scope of these
variables, you can put braces around the outer switch block.

Regards,
J�rgen

--
J�rgen Kr�mer                              Softwareentwicklung
HABEL GmbH & Co. KG                        mailto:[hidden email]
Hinteres �schle 2                          Tel: +49 / 74 61 / 93 53 - 15
78604 Rietheim-Weilheim                    Fax: +49 / 74 61 / 93 53 - 99