user-pic

Fernando

  • About: I don't blog about Perl.
  • Commented on Show Perl subname in vim statusline
    Uh, double comment above, you may remove one. Corrections after having used this a bit: b:did_perl_statusline makes the variable local to the buffer instead of g: which is global my $line_number = ($curwin->Cursor)[0]; my $line = ''; $line = $curbuf->Get(...
  • Commented on Show Perl subname in vim statusline
    From the bike-shedding department, the lines:   my @document = map { $curbuf->Get($_) } 0 .. $curbuf->Count; my ( $line_number, $column ) = $curwin->Cursor;   could become:   my ( $line_number, $column ) = $curwin->Cursor; $line = $curbuf->Get($line_number--) while $line_number...
  • Commented on Show Perl subname in vim statusline
    From the bike-shedding department, the lines:   my @document = map { $curbuf->Get($_) } 0 .. $curbuf->Count; my ( $line_number, $column ) = $curwin->Cursor;   can become:   my ( $line_number, $column ) = $curwin->Cursor; $line = $curbuf->Get($line_number--) while $line_number...
Subscribe to feed Recent Actions from Fernando

  • hanekomu commented on Show Perl subname in vim statusline

    Here's a function that determines the name of the current sub in much the same way, but it's in Vim script, so it works even if you don't have Perl embedded in Vim:

    
    function! PerlCurrentSubName()
        let s:currline = line('.')
        let s:currcol = col('.')
        normal $
        let [s:line, s:column] = searchpos('^\s*sub\s\+\zs\(\w\+\)','bcW')
        if (s:line != 0)
            let s:subname = expand('')
            call cursor(s:currline, s:currcol)
            return s:subname
        else
            return '(not in sub)'
        endif
    endfunction
    
  • hanekomu commented on Show Perl subname in vim statusline

    Actually, in this function we need to call cursor() even if there was no match, because "normal $" would insist on always keeping the cursor on the end of the line...

    
    function! PerlCurrentSubName()
        let s:currline = line('.')
        let s:currcol = col('.')
        normal $ 
        let [s:line, s:column] = searchpos('^\s*sub\s\+\zs\(\w\+\)','bcW')
        if (s:line != 0)
            let s:subname = expand('')
        else
            let s:subname = '(not in sub)'
        endif
        call cursor(s:currline, s:currcol)
        return s:subname
    endfunction
    
    

    There may be a better way of doing this witho…

  • Andrew commented on Show Perl subname in vim statusline

    I played with your script for about an hour and made an improvement. This will display 'N/A' if you're outside the subroutine. If you have a history of your closing brace indent not matching your sub declaration indent you may want to alter the $indent portion. Have fun!

    .vimrc
    
    syntax on
    setlocal laststatus=2
    setlocal statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Position:\ %p%%\ %l/%L,%c
    if has("autocmd")
        autocmd BufReadPost * if &syntax == 'perl' | source ~/.vim/perl_current_subroutine | endif
    endif
    



    .vim…

Subscribe to feed Responses to Comments from Fernando

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.