It seems to me that an Emacs shortcut to avoid the mistake you describe would be significantly complicated by the fact that the LHS of the assignment is quite variable, but maybe this will be enough:

(add-hook 'cperl-mode-hook (lambda() (local-set-key "\C-cm" 'perl-insert-oo-me +thod))) (defun perl-insert-oo-method (methodname) "Insert Perl OO method" (interactive "MEnter method's name: ") (insert (format "sub %s {\nmy ( $self ) = @_;" methodname)) (backward-char 8) (cperl-indent-command) )
Tweak to taste. It assumes that you are using cperl-mode (and if you aren't I highly recommend it). Also, you can probably modify this example to handle other common coding shortcuts.

Update:For those less familiar with extending Emacs:

  1. Cut and paste the code above to your .emacs file or equivalent (I believe that for xemacs that would be the file .xemacs/custom.el, but I'm not sufficiently familiar with xemacs to know for sure).
  2. Make this inserted text the region, and execute the command eval-region (i.e. M-x eval-region).
  3. Switch to a new buffer and execute he command cperl-mode (i.e. M-x cperl-mode).
  4. Now, in cperl mode, the key sequence C-c m will bring up a prompt for the method name:
    Enter method name: foo
    Once the method name is entered (say foo), the following will be inserted at point:
    sub foo { my ( $self ) = @_;
    and point will be placed right after $self.

the lowliest monk


In reply to Re: Perl templates for Emacs? by tlm
in thread Perl templates for Emacs? by loris

Title:
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, details, 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, summary, 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.