in reply to Perl templates for Emacs?

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

Replies are listed 'Best First'.
Re^2: Perl templates for Emacs?
by loris (Hermit) on Jun 30, 2005 at 13:10 UTC

    That is also nice, although I like the multiple arguments bit of the version given in PerlTemplates.

    However, I'd quite like to have pod inserted there too, so time to learn some Lisp, I suppose ...

      It's out of print, but if you can find a copy Writing GNU Emacs Extensions (ISBN 1565922611) is a pretty gentle (if somewhat dated) introduction to elisp. You can at least get the example code from ORA at the link above.

      --
      We're looking for people in ATL

      loris writes:

      time to learn some Lisp, I suppose ...

      Bob Chassell's An Introduction to Programming in Emacs Lisp is a good way to get started, if your primary objective is to extend Emacs, because Elisp has a lot of functions and concepts that are specific to text editing and would not be covered at all in a general Lisp book or tutorial. You can find the book online (though personally I like to support the FSF by buying hardcopies of their books).

      One alternative is Writing GNU Emacs Extensions by Bob Glickstein, but this book is out of print, so you'll need to find a used copy.

      the lowliest monk