Author: dylan
Date: 2005-01-09 00:20:23 -0500 (Sun, 09 Jan 2005)
New Revision: 572
Added:
trunk/dev-tools/vim-automod/
trunk/dev-tools/vim-automod/Makefile
trunk/dev-tools/vim-automod/perl_automod.vim.m4
trunk/dev-tools/vim-automod/template.pm
Log:
automagic perl module templating.
Added: trunk/dev-tools/vim-automod/Makefile
===================================================================
--- trunk/dev-tools/vim-automod/Makefile 2005-01-09 05:04:23 UTC (rev
571)
+++ trunk/dev-tools/vim-automod/Makefile 2005-01-09 05:20:23 UTC (rev
572)
@@ -0,0 +1,32 @@
+
+SCRIPT = perl_automod.vim
+TEMPLATE = template.pm
+VIMDIR ?= $(HOME)/.vim
+
+SCRIPT_INSTALLED := $(VIMDIR)/ftplugin/$(SCRIPT)
+TEMPLATE_INSTALLED := $(VIMDIR)/templates/$(TEMPLATE)
+
+
+
+install: $(SCRIPT_INSTALLED) $(TEMPLATE_INSTALLED)
+ @echo "====== NOTICE ======"
+ @echo "Please add the following line to ~/.vimrc:"
+ @echo "autocmd BufNewFile *.pm nested call PerlModuleNewFile()"
+
+$(TEMPLATE_INSTALLED): $(TEMPLATE)
+ @echo install -D $< $@
+
+$(SCRIPT_INSTALLED): $(SCRIPT)
+ @echo install -D $< $@
+
+clean:
+ rm $(SCRIPT)
+
+uninstall: clean
+ rm $(SCRIPT_INSTALLED) $(TEMPLATE_INSTALLED)
+
+
+%.vim: %.vim.m4 Makefile
+ m4 -DMODULE_TEMPLATE=$(TEMPLATE_INSTALLED) $< > $@
+
+
Added: trunk/dev-tools/vim-automod/perl_automod.vim.m4
===================================================================
--- trunk/dev-tools/vim-automod/perl_automod.vim.m4 2005-01-09 05:04:23 UTC
(rev 571)
+++ trunk/dev-tools/vim-automod/perl_automod.vim.m4 2005-01-09 05:20:23 UTC
(rev 572)
@@ -0,0 +1,105 @@
+" vi:set ts=8 sts=4 sw=4:
+"
+" perl_automod.vim
+"
+" Maintainer: Dylan Hardison <[EMAIL PROTECTED]>
+" Last Change: 09-Jan-2005.
+" Description: This is a script to allow automagic perl module templates.
+"
+" To install:
+" * make install
+" * In your ~/.vimrc, use the following autocmd:
+" : autocmd BufNewFile *.pm nested call PerlModuleNewFile()
+"
+"
+"
+if exists('did_perl_automod')
+ finish
+endif
+
+let did_perl_automod=1
+
+if !exists("g:perl_automod_new")
+ let g:perl_automod_new="MODULE_TEMPLATE"
+endif
+
+function PerlModuleNewFile()
+ let skelfile=""
+
+ if exists("b:perl_mod_new")
+ let skelfile = b:perl_automod_new
+ else
+ let skelfile = g:perl_automod_new
+ endif
+
+ " Read in the skeleton code.
+ execute "0read" skelfile
+
+ " Turn a file name into a package name.
+ let package = s:PathToPerlPackage(@%)
+
+ " Replace <<PACKAGE>> with the guessed package name.
+ silent %substitute/<<PACKAGE>>/\=package/ge
+
+ if exists("$REALNAME")
+ silent %substitute/<<AUTHOR>>/\=$REALNAME/ge
+ endif
+
+ if exists("$EMAIL")
+ silent %substitute/<<EMAIL>>/\=$EMAIL/ge
+ endif
+
+ let year=strftime("%Y")
+ silent %substitute/<<YEAR>>/\=year/ge
+
+ silent %substitute/<<CURSOR>>//ge
+
+endfunction
+
+" Arguments: path -- the relative to . or absolute path to a perl module.
+" Returns: a perl package name.
+" Example: PathToPerlPackage( "lib/foo/bar/baz.pm" ) == "foo::bar::baz"
+" Description:
+" This function uses a simple heuristic to turn a
+" path name into a perl module package name.
+" The heuristic is to take the full path of the file,
+" search for the part after /lib/, change slashes to ::'s,
+" and remove the .pm
+" Notes:
+" This is a very simple heuristic, and could probably
+" be improved, but it works for me.
+function s:PathToPerlPackage(path)
+ " Is the file absolute or relative?
+ if match(a:path, '^/') == -1
+ " It is relative.
+ let path = getcwd() . '/' . a:path
+ else
+ let path = a:path
+ endif
+
+ " Skip the first char, "/"
+ let path = strpart(path, 1)
+
+ " Find the first occurance of "/lib/" in the path
+ let pos = match(path, "/lib/")
+
+ " If "/lib/" did not occure in the path
+ if pos == -1
+ let path = substitute(path, '^[^A-Z]\+/', '', 'g')
+ else
+ " Oh, it did. Start eating
+ while pos > -1
+ " skip past the rest of the path + 5 chars
+ " to skip the /lib/ part.
+ let path = strpart(path, pos + 5)
+ let pos = match(path, "/lib/")
+ endwhile
+ endif
+
+ " Change slashes to ::'s
+ let package = substitute(path, '/', '::', 'g')
+ " Remove the .pm extension.
+ let package = substitute(package, '\.pm$', '', '')
+
+ return package
+endfunction
Added: trunk/dev-tools/vim-automod/template.pm
===================================================================
--- trunk/dev-tools/vim-automod/template.pm 2005-01-09 05:04:23 UTC (rev
571)
+++ trunk/dev-tools/vim-automod/template.pm 2005-01-09 05:20:23 UTC (rev
572)
@@ -0,0 +1,61 @@
+# vim: set ts=4 sw=4 expandtab si ai sta tw=100:
+# This module is copyrighted, see end of file for details.
+package <<PACKAGE>>;
+use strict;
+use warnings;
+
+our $VERSION = 0.01;
+
+
+sub initialize {
+ my ($me) = @_;
+
+ # <<CURSOR>>
+}
+
+# use this instead of overriding DESTROY, if you extend Haver::Base.
+# sub finalize {
+# my ($me) = @_;
+#
+# }
+
+
+
+1;
+__END__
+
+=head1 NAME
+
+<<PACKAGE>> - description
+
+=head1 SYNOPSIS
+
+ use <<PACKAGE>>
+ # Small code example.
+
+=head1 DESCRIPTION
+
+FIXME
+
+=head1 METHODS
+
+<<PACKAGE>> implements the following methods:
+
+=head1 BUGS
+
+Describe how to report bugs, and list any known bugs.
+
+=head1 AUTHOR
+
+<<AUTHOR>>, E<lt><<EMAIL>>E<gt>
+
+=head1 SEE ALSO
+
+L<perl(1)>, and any other related modules / manpages / websites.
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (C) <<YEAR>> by <<AUTHOR>>. All Righest Reserved.
+
+This module is free software;
+you can redistribute it and/or modify it under the same terms as Perl itself.