Loading ...
Sorry, an error occurred while loading the content.

[patch] switch indentation problem

Expand Messages
  • David Bustos
    In Vim 6.0at, with cindent on and cino=:0l1, the following switch statement is indented thusly: func(int x) { switch (x) { case 1: statement1; case CONST: {
    Message 1 of 2 , Sep 1, 2001
    • 0 Attachment
      In Vim 6.0at, with cindent on and cino=:0l1, the following switch
      statement is indented thusly:

      func(int x)
      {
      switch (x) {

      case 1:
      statement1;

      case CONST: {
      statement2;
      }

      default:
      statement3;
      }
      }

      The problem is statement3. It's being aligned with the { in the
      "case CONST:" line when I want it to be aligned with statement1. I
      believe this is a bug. I've come up with a patch to fix it by making
      get_c_indent() continue past the "case CONST:" line rather than stopping
      at it. I'm not sure if this is the Right Way to do it, but it works and
      should give someone who knows get_c_indent() better than I a starting
      point.


      David Bustos


      --- - Sat Sep 1 11:25:58 2001
      +++ vim60at/src/misc1.c Sat Sep 1 11:23:19 2001
      @@ -5624,6 +5624,8 @@
      }
      }

      + iscase = cin_iscase(l);
      +
      /*
      * Get indent and pointer to text for current line,
      * ignoring any jump label.
      @@ -5636,7 +5638,7 @@
      /* See remark above: "Only add ind_open_extra.." */
      if (*skipwhite(l) == '{')
      amount -= ind_open_extra;
      - lookfor = LOOKFOR_TERM;
      + lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM;

      /*
      * If we're at the end of a block, skip to the start of
    • Bram Moolenaar
      ... It makes sense. But only when l1 is in cinoptions . I ll add a check for ind_keep_case_label being set. -- ARTHUR: I command you as King of the
      Message 2 of 2 , Sep 1, 2001
      • 0 Attachment
        David Bustos wrote:

        > In Vim 6.0at, with cindent on and cino=:0l1, the following switch
        > statement is indented thusly:
        >
        > func(int x)
        > {
        > switch (x) {
        >
        > case 1:
        > statement1;
        >
        > case CONST: {
        > statement2;
        > }
        >
        > default:
        > statement3;
        > }
        > }
        >
        > The problem is statement3. It's being aligned with the { in the
        > "case CONST:" line when I want it to be aligned with statement1. I
        > believe this is a bug. I've come up with a patch to fix it by making
        > get_c_indent() continue past the "case CONST:" line rather than stopping
        > at it. I'm not sure if this is the Right Way to do it, but it works and
        > should give someone who knows get_c_indent() better than I a starting
        > point.

        It makes sense. But only when "l1" is in 'cinoptions'. I'll add a check
        for ind_keep_case_label being set.

        --
        ARTHUR: I command you as King of the Britons to stand aside!
        BLACK KNIGHT: I move for no man.
        The Quest for the Holy Grail (Monty Python)

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim )))
        \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
      Your message has been successfully submitted and would be delivered to recipients shortly.