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

indent/vim.vim does not work when ignorecase is 1

Expand Messages
  • matsushita shougo
    Hi, I found the problem in indent/vim.vim. ... The match uses =~ and !~ instead of =~ and !~ . So if set ignorecase, the indentation is wrong. I fixed
    Message 1 of 6 , Aug 2, 2012
    • 0 Attachment
      Hi, I found the problem in indent/vim.vim.

      > elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
      > let ind = ind + &sw
      > else
      > let line = getline(lnum)
      > let i = match(line, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>')
      > if i >= 0
      > let ind += &sw
      > if strpart(line, i, 1) == '|' && has('syntax_items')
      > \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$'
      > let ind -= &sw
      > endif
      > endif

      The match uses "=~" and "!~" instead of "=~" and "!~".
      So if set ignorecase, the indentation is wrong.
      I fixed the problem. Would you check it?
      Note: Same problem may be in other indentation plugins. But I don't check.

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Bram Moolenaar
      ... Good idea. I like the use of try/finally. ... At least now we have a solution that can be applied to other plugins as well. -- panic( Foooooooood
      Message 2 of 6 , Aug 2, 2012
      • 0 Attachment
        Matsushita Shougo wrote:

        > Hi, I found the problem in indent/vim.vim.
        >
        > > elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
        > > let ind = ind + &sw
        > > else
        > > let line = getline(lnum)
        > > let i = match(line, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>')
        > > if i >= 0
        > > let ind += &sw
        > > if strpart(line, i, 1) == '|' && has('syntax_items')
        > > \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$'
        > > let ind -= &sw
        > > endif
        > > endif
        >
        > The match uses "=~" and "!~" instead of "=~" and "!~".
        > So if set ignorecase, the indentation is wrong.
        > I fixed the problem. Would you check it?

        Good idea. I like the use of try/finally.

        > Note: Same problem may be in other indentation plugins. But I don't check.

        At least now we have a solution that can be applied to other plugins as
        well.

        --
        panic("Foooooooood fight!");
        -- In the kernel source aha1542.c, after detecting a bad segment list

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ an exciting new programming language -- http://www.Zimbu.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • ZyX
        ... Why don t fix the problem by explicitely using [=!][~=][#?] everywhere? I just always use # and ? for string comparison, no matter whether it is
        Message 3 of 6 , Aug 2, 2012
        • 0 Attachment
          четверг, 2 августа 2012 г., 16:07:29 UTC+4 пользователь Shougo написал:
          > Hi, I found the problem in indent/vim.vim.
          >
          >
          >
          > > elseif getline(lnum) =~ '^\s*aug\%[roup]' && getline(lnum) !~ '^\s*aug\%[roup]\s*!\=\s\+END'
          >
          > > let ind = ind + &sw
          >
          > > else
          >
          > > let line = getline(lnum)
          >
          > > let i = match(line, '\(^\||\)\s*\(if\|wh\%[ile]\|for\|try\|cat\%[ch]\|fina\%[lly]\|fu\%[nction]\|el\%[seif]\)\>')
          >
          > > if i >= 0
          >
          > > let ind += &sw
          >
          > > if strpart(line, i, 1) == '|' && has('syntax_items')
          >
          > > \ && synIDattr(synID(lnum, i, 1), "name") =~ '\(Comment\|String\)$'
          >
          > > let ind -= &sw
          >
          > > endif
          >
          > > endif
          >
          >
          >
          > The match uses "=~" and "!~" instead of "=~" and "!~".
          >
          > So if set ignorecase, the indentation is wrong.
          >
          > I fixed the problem. Would you check it?
          >
          > Note: Same problem may be in other indentation plugins. But I don't check.

          Why don't fix the problem by explicitely using "[=!][~=][#?]" everywhere? I just always use "#" and "?" for string comparison, no matter whether it is "=~", "is" or their opposites (yes, and I never use "=="/"!=" for string comparison). All the problems should be fixed by running

          perl -p -i -e 's/(?<=[!=]~)(?![?#])/#/g unless /^\s*setlocal/' indent/*.vim
          additionally reviewing changes when processing plugins for languages which contain this operator. The result seem to be harmless: http://bpaste.net/show/38213/.

          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Shougo
          ... Because, indent/vim.vim(and I think other plugins too) uses match(). This functions also uses ignorecase option. I can t fix it easily. So I used try
          Message 4 of 6 , Aug 2, 2012
          • 0 Attachment
            > Why don’t fix the problem by explicitely using “[=!][~=][#?]” everywhere? I just always use “#” and “?” for string comparison, no matter whether it is “=~”, “is” or their opposites (yes, and I never use “==”/“!=” for string comparison). All the problems should be fixed by running
            >

            Because, indent/vim.vim(and I think other plugins too) uses match(). This functions also uses 'ignorecase' option.
            I can't fix it easily. So I used try finally block and changed ignorecase option.

            >
            >
            > perl -p -i -e 's/(?<=[!=]~)(?![?#])/#/g unless /^\s*setlocal/' indent/*.vim
            >
            > additionally reviewing changes when processing plugins for languages which contain this operator. The result seem to be harmless: http://bpaste.net/show/38213/.

            So I think your changes is incomplete.

            Thanks your reply.

            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • ZyX
            ... Bad. I now must go and change all match(), matchstr(), matchlist() and matchend() calls at least in all of my plugins. Thanks for pointing this out. It is
            Message 5 of 6 , Aug 2, 2012
            • 0 Attachment
              пятница, 3 августа 2012 г., 5:42:30 UTC+4 пользователь Shougo написал:
              > > Why don't fix the problem by explicitely using "[=!][~=][#?]" everywhere? I just always use "#" and "?" for string comparison, no matter whether it is "=~", "is" or their opposites (yes, and I never use "=="/"!=" for string comparison). All the problems should be fixed by running
              >
              > >
              >
              >
              >
              > Because, indent/vim.vim(and I think other plugins too) uses match(). This functions also uses 'ignorecase' option.
              >
              > I can't fix it easily. So I used try finally block and changed ignorecase option.

              Bad. I now must go and change all match(), matchstr(), matchlist() and matchend() calls at least in all of my plugins. Thanks for pointing this out.

              It is still not impossible to do with a perl (ir)regular expression, but if you do grep there you will see that there are not many such calls that need to be fixed. This patch (http://bpaste.net/show/38266/) was produced by
              perl -p -i -e 's#(match(?:str|list|end)?\((?:[^([,]+|\(([^(\[]+|\((?2)*\)|\[(?2)*\])|\[(?2)*\])+,\s*(?:\[(?:\\.|[^\]])+\]|('')(?=(?:(?:(?!\\[cC])[^''])+?|'''')*?(?<!\\)(?<!\\[_z])[a-zA-Z](?![^\[\]]*\]))|(")(?=(?:(?:(?!\\\\[cC])[^"])+?|\\")*?[a-zA-Z](?![^\[\]]*\]))))#"$1".(($1 =~ /"$/)?("\\\\c"):("\\c"))#ge and print STDERR "$.:$_"' *.vim~sdl.vim

              (http://bpaste.net/show/38268/ in case it gets spoiled) and it is much smaller. There are some missed things where variables are used in the pattern. I should have used vimgrep, it would be faster then constructing the above monster.

              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • ZyX
              ... Missed one thing here: it should be ( C ):( C ) , not ( c ):( c ) -- You received this message from the vim_dev maillist. Do not top-post!
              Message 6 of 6 , Aug 5, 2012
              • 0 Attachment
                пятница, 3 августа 2012 г., 9:05:09 UTC+4 пользователь ZyX написал:
                > пятница, 3 августа 2012 г., 5:42:30 UTC+4 пользователь Shougo написал:
                >
                > > > Why don't fix the problem by explicitely using "[=!][~=][#?]" everywhere? I just always use "#" and "?" for string comparison, no matter whether it is "=~", "is" or their opposites (yes, and I never use "=="/"!=" for string comparison). All the problems should be fixed by running
                >
                > >
                >
                > > >
                >
                > >
                >
                > >
                >
                > >
                >
                > > Because, indent/vim.vim(and I think other plugins too) uses match(). This functions also uses 'ignorecase' option.
                >
                > >
                >
                > > I can't fix it easily. So I used try finally block and changed ignorecase option.
                >
                >
                >
                > Bad. I now must go and change all match(), matchstr(), matchlist() and matchend() calls at least in all of my plugins. Thanks for pointing this out.
                >
                >
                >
                > It is still not impossible to do with a perl (ir)regular expression, but if you do grep there you will see that there are not many such calls that need to be fixed. This patch (http://bpaste.net/show/38266/) was produced by
                >
                > perl -p -i -e 's#(match(?:str|list|end)?\((?:[^([,]+|\(([^(\[]+|\((?2)*\)|\[(?2)*\])|\[(?2)*\])+,\s*(?:\[(?:\\.|[^\]])+\]|('')(?=(?:(?:(?!\\[cC])[^''])+?|'''')*?(?<!\\)(?<!\\[_z])[a-zA-Z](?![^\[\]]*\]))|(")(?=(?:(?:(?!\\\\[cC])[^"])+?|\\")*?[a-zA-Z](?![^\[\]]*\]))))#"$1".(($1 =~ /"$/)?("\\\\c"):("\\c"))#ge and print STDERR "$.:$_"' *.vim~sdl.vim
                >
                >
                >
                > (http://bpaste.net/show/38268/ in case it gets spoiled) and it is much smaller. There are some missed things where variables are used in the pattern. I should have used vimgrep, it would be faster then constructing the above monster.

                Missed one thing here: it should be "("\\\\C"):("\\C")", not "("\\\\c"):("\\c")"

                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              Your message has been successfully submitted and would be delivered to recipients shortly.