Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I know that this is an old node. And that I have already commented on it. However, I wanted to add some updates.

I had a regex mapped to comment out lines or blocks of code and another to uncomment them. I always hated that this killed my "previous search expression" so that I could not go through a file looking for a pattern, comment out the line, and go to the next occurrence without re-issuing the search command. I always thought "There must be a better way. After OSCON 2007, I found that better way:

function! Comment() let l:line = "#".getline(".") call setline(".",l:line) endfunction map ## :call Comment()<cr> function! UnComment() let l:line = getline(".") let l:pos = stridx(l:line,"#") if l:pos > -1 let l:line = strpart(l:line,0,l:pos).strpart(l:line,l:pos+1) endif call setline(".",l:line) endfunction map !# :call UnComment()<cr>

I also got tired of the fancy status line function not working inside closures because sub was indented. So, I did some poking at the code (that a coworker had put together) and made some minor fixes:

if has( "folding" ) set statusline=%f%{CurrSubName()}\ %m%h%r\ %=%25(%-17(%l\,%c%V%)\ %p +%%%) set laststatus=2 set maxfuncdepth=1000 endif function! CurrSubName() let g:subname = "" let g:subrecurssion = 0 " See if this is a Perl file let l:firstline = getline(1) if ( l:firstline =~ '#!.*perl' || l:firstline =~ '^package ' ) call GetSubName(line(".")) endif return g:subname endfunction function! GetSubName(line) let l:str = getline(a:line) if l:str =~ '^\s*sub\>' let l:str = substitute( l:str, ' *{.*', '', '' ) let l:str = substitute( l:str, '^\s*sub *', ': ', '' ) let g:subname = l:str return 1 elseif ( l:str =~ '^}' || l:str =~ '^} *#' ) && g:subrecurssion >= 1 return -1 elseif a:line > 2 let g:subrecurssion = g:subrecurssion + 1 if g:subrecurssion < 190 call GetSubName(a:line - 1) else let g:subname = ': <too deep>' return -1 endif else return -1 endif endfunction

Share and enjoy.

Ivan Heffner
Sr. Software Engineer, Inc.

In reply to Re: .vimrc for perl programmers by Codon
in thread .vimrc for perl programmers by nferraz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (6)
    As of 2020-02-24 09:32 GMT
    Find Nodes?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?

      Results (104 votes). Check out past polls.