emacs template for perl modules

jrockway on 2007-05-10T20:17:14

Here's the template.el template I use for .pm files:


# Copyright (c) (>>>YEAR<<<) Jonathan Rockway <jrockway@cpan.org>

package (>>>PACKAGE_NAME<<<); use strict; use warnings; (>>>POINT<<<) 1; >>>TEMPLATE-DEFINITION-SECTION<<< ("PACKAGE_NAME" (insert-string (let ((filename (buffer-file-name))) (if (string-match "lib/\\(.+\\)[.]pm$" filename) (let ((mod (match-string 1 filename))) (while (string-match "/" mod) (setq mod (replace-match "::" nil nil mod))) mod) (if (string-match "\\([^/]+\\)[.]pm$" filename) (match-string 1 filename) "UNKNOWN"))) ))
The nice part is that it knows what the name of your module is. If you C-x C-f lib/Foo/Bar/Baz.pm, then the package declaration at the top will say Foo::Bar::Baz (and will auto-create lib/Foo/Bar for you). I've been using this for a few months and realized that it's too convenient to keep to myself :)


more info

thinc on 2007-05-11T02:20:26

I use emacs, but had never heard of 'template'.

In case anyone else is in that situation, here is a link:

http://emacs-template.sourceforge.net/