Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Perl-Sensitive Sunglasses
 
PerlMonks  

vimrc for documenting subs

by scain (Curate)
on May 19, 2004 at 13:50 UTC ( #354609=sourcecode: print w/ replies, xml ) Need Help??

Category: Utility Scripts
Author/Contact Info Scott Cain
Description: This is a vimrc that will automatically create documentation and skeleton code for a subroutine. To use it, type the name of the new subroutine in a line by itself in vim, the press either F2 for a generic sub or F3 for a Get/Set sub. The result for a generic sub looks like this:
=head2 generic_sub_name + =over + =item Usage + $obj->generic_sub_name() + =item Function + =item Returns + =item Arguments + =back + =cut + sub generic_sub_name { my ($self, %argv) = @_; + + }
and for a get/set sub, like this:
=head2 get_set_name + =over + =item Usage + $obj->get_set_name() #get existing value $obj->get_set_name($newval) #set new value + =item Function + =item Returns + value of get_set_name (a scalar) + =item Arguments + new value of get_set_name (to set) + =back + =cut + sub get_set_name { my $self = shift; return $self->{'get_set_name'} = shift if defined(@_); return $self->{'get_set_name'}; }
map <F2> :call Method()<cr>
map <F3> :call Getset()<cr>
                                                                      
+             
function! Method()
perl <<EOF
  ($row) = $curwin->Cursor();
  my $method_name = $curbuf->Get( $row );
  my @method_string = (
   "=head2 $method_name",
   "",
   "=over",
   "",
   "=item Usage",
   "",
   "  \$obj->$method_name()",
   "",
   "=item Function",
   "",
   "=item Returns",
   "",
   "=item Arguments",
   "",
   "=back",
   "",
   "=cut",
   "",
   "sub $method_name {",
   "    my (\$self, \%argv) = \@_;",
   "",
   "",
   "}",
   ""
  );
                                                                      
+             
  $curbuf->Delete($row);
  $row--;
  $curbuf->Append($row, @method_string);
EOF
endfunction

function! Getset()
perl <<EOF
  ($row) = $curwin->Cursor();
  my $method_name = $curbuf->Get( $row );
  my @method_string = (
   "=head2 $method_name",
   "",
   "=over",
   "",
   "=item Usage",
   "",
   "  \$obj->$method_name()        #get existing value",
   "  \$obj->$method_name(\$newval) #set new value",
   "",
   "=item Function",
   "",
   "=item Returns",
   "",
   "value of $method_name (a scalar)",
   "",
   "=item Arguments",
   "",
   "new value of $method_name (to set)",
   "",
   "=back",
   "",
   "=cut",
   "",
   "sub $method_name {",
   "    my \$self = shift;",
   "    return \$self->{'$method_name'} = shift if defined(\@_);",
   "    return \$self->{'$method_name'};",
   "}",
   ""
  );
                                                                      
+             
  $curbuf->Delete($row);
  $row--;
  $curbuf->Append($row, @method_string);
EOF
endfunction

Comment on vimrc for documenting subs
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://354609]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-04-17 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls