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

perl: indenting references (\@arr)

Expand Messages
  • Ronald
    perl-code containing references intends stange. For example: while ($ok) { if ($tbs) { &show( step 1 , @arr, [24,60,60]); &show( step 1 , @arr,
    Message 1 of 3 , Oct 30, 2011
    • 0 Attachment
      perl-code containing references intends stange.
      For example:

      <code>
      while ($ok) {
      if ($tbs) {
      &show("step 1", \@arr, [24,60,60]);
      &show("step 1", \@arr, [24,60,60]);
      &show("step 1", \@arr, [24,60,60]);
      &show("step 1", \@arr, [24,60,60]);
      &show("step 1", \@arr, [24,60,60]);
      &show("step 1", \@arr, [24,60,60]);
      }
      }
      </code>

      in /usr/share/vim/vim73/indent/perl.vim
      I found 2 lines:
      <code>
      let bracepos = match(line, '[(){}\[\]]', match...
      </code>
      It seems as '[(){}\[\]]' finds brackets 'and' backslashes!

      So I replaced these 2 lines with
      <code>
      let bracepos = BracePos(line, match...
      </code>
      and wrote a new function
      <code>
      " get position of () {} []
      function! BracePos(line, start)
      let l:min = strlen(a:line)+1

      for l:char in split('(){}[]', '\zs')
      let l:pos = match(a:line, l:char, a:start)
      if l:pos >= 0
      let l:min = min([l:min, l:pos])
      endif
      endfor

      if l:min == strlen(a:line)+1
      let l:min = -1
      endif

      return l:min
      endfunction
      </code>

      Now it works fine.

      I had checked it on my perl programs and it works for me.

      --
      You received this message from the "vim_use" 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
    • Andy Wokula
      ... Yes. How it reads with spaces: [ ( ) { } [ ] ] ... BUT ... -- Andy -- You received this message from the vim_use maillist. Do not top-post! Type your
      Message 2 of 3 , Oct 31, 2011
      • 0 Attachment
        Am 30.10.2011 20:34, schrieb Ronald:
        > It seems as '[(){}\[\]]' finds brackets 'and' backslashes!

        Yes. How it reads with spaces:
        [ ( ) { } \ [ \] ]

        :h /\]

        | To include a literal ']', '^', '-' or '\' in the collection, put a
        | backslash before it
        BUT
        | For '\' you can also let it be followed by
        | any character that's not in "^]-\bdertnoUux".

        --
        Andy

        --
        You received this message from the "vim_use" 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
      • Rgg
        Thanks to Andy. Knowing this, I don t need the function any more. It s enough to modify the 2 lines from let bracepos = match(line, [(){} [ ]] , ...
        Message 3 of 3 , Jan 5, 2013
        • 0 Attachment
          Thanks to Andy.

          Knowing this, I don't need the function any more.

          It's enough to modify the 2 lines
          from
          <code>
          let bracepos = match(line, '[(){}\[\]]', ...
          </code>
          to
          <code>
          let bracepos = match(line, '[(){}[\]]', ...
          </code>
          (Remove the first backslash.)

          Now it works perfectly.

          Ronald



          --
          View this message in context: http://vim.1045645.n5.nabble.com/perl-indenting-references-arr-tp4950945p5712944.html
          Sent from the Vim - General mailing list archive at Nabble.com.

          --
          You received this message from the "vim_use" 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.