Tools

Put your work under version control today

January 31, 2008 Tools 5 comments

There is no project so small, so trivial, that it is not worth you putting it into a Subversion repository. If it’s worth your time to work on it, it’s worth saving. Putting it in Subversion is a matter of a few statements, and you don’t have to do any big fancy-shmancy server setup.

Let’s assume you’re working on Linux/Unix, and you have svn installed, which is pretty standard these days. Say you’re working on a game called bongo, and you’ve just been keeping it in ~/bongo. Do this:

# Create the Subversion repo
$ mkdir /svn
# Create the bongo repo
$ svnadmin create /svn/bongo
# Import bongo into its project
$ cd ~/bongo
$ svn import file:///svn/bongo -m'First import of bongo into Subversion'
# Move the original bongo directory out of the way,
# in case something goes wrong
$ mv ~/bongo ~/bongo-original
# Check out bongo from Subversion
svn co file:///svn/bongo

At this point, you’ll have a checked-out version of bongo in ~/bongo, and you can make commits against it.

Ricardo Signes points out that Git makes it even easier.

# Go to the bongo directory
$ cd ~/bongo
# Import bongo
$ git init

With Git, everything is put in your ~/.git directory, and you don’t have to check out anything from the project.

Whatever route you choose, version control is so simple these days there’s just no excuse not to do it. Your programming life will never be the same.

Vim tricks for Perl

January 23, 2008 Tools 1 comment

This thread on use.perl.org points to some cool vim support for Perl. I’m not sure I like all the doodads in perl-support.vim, but I did add this to my .vimrc:

autocmd FileType perl :noremap K :!perldoc <cword>
<bar><bar> perldoc -f <cword><cr>

Now hitting K in vim runs perldoc or perldoc -f on the word under the cursor.

Make your own mini CPAN

January 21, 2008 CPAN, Tools No comments

Ricardo Signes’ marvelous module CPAN::Mini just got an update today, and it reminds me to tell you all how great it is to be able to have a small version of the CPAN on your local hard drive, especially on a laptop. The included minicpan program makes it trivial to update your local archive.

First, I make a little ~/.minicpanrc that looks like this:

local: ~/minicpan/
remote: http://cpan.pair.com/pub/CPAN/
also_mirror: indices/ls-lR.gz

And then I run minicpan every so often. This pulls in the latest version of each distribution, and deletes ones that are obsoleted by newer versions. When I run minicpan, it looks like this:

$ minicpan
authors/01mailrc.txt.gz ... updated
modules/02packages.details.txt.gz ... updated
modules/03modlist.data.gz ... updated
mkdir /tmp/Woq_DHsWsN/indices
indices/ls-lR.gz ... updated
indices/ls-lR.gz ... updated
mkdir /home/andy/minicpan/authors/id/G/GR/GROMMIER
authors/id/G/GR/GROMMIER/Text-Editor-Easy-0.01.tar.gz ... updated
authors/id/G/GR/GROMMIER/CHECKSUMS ... updated
mkdir /home/andy/minicpan/authors/id/Z/ZO/ZOFFIX
authors/id/Z/ZO/ZOFFIX/Acme-BabyEater-0.01.tar.gz ... updated
authors/id/Z/ZO/ZOFFIX/CHECKSUMS ... updated
...
cleaning /home/andy/minicpan/authors/id/L/LU/LUKEROSS/DBIx-StORM-0.04.tar.gz ...done
cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/Test-WWW-Selenium-1.13.tar.gz ...done
cleaning /home/andy/minicpan/authors/id/L/LU/LUKEC/mocked-0.07.tar.gz ...done
cleaning /home/andy/minicpan/authors/id/L/LO/LOCATION/Geo-IP2Location-2.00.tar.gz ...done
cleaning /home/andy/minicpan/authors/id/L/LO/LODIN/Regexp-Exhaustive-0.03.tar.gz ...done

Currently the repository is only 846M of disk space. Who doesn’t have an extra gig lying around these days?

uniqua:~/minicpan $ du -sh
846M	.

I also point my CPAN shell configuration to use the mini CPAN as its source of modules by prepending file:///home/andy/minicpan to the list of URLs it checks.

Thanks to Ricardo for putting out this great tool, and Randal Schwartz for the original column on which it was based.

More vim goodies for Perl 5.10

January 21, 2008 Tools No comments

Rafael Garcia-Suarez has posted his modifications for vim to support Perl 5.10. His are a good deal more complete than the simple
modification I posted last month that just covers the say keyword.

Make vim support Perl 5.10

December 27, 2007 Tools 1 comment

The new say function isn’t supported by the perl.vim file that ships with vim. Nick Hibma, the maintainer, tells me it will be updated in the next version of vim. In the meantime, you can hack your local vim files by adding the following line to your ~/.vim/syntax/perl.vim file:

syn keyword perlStatementFiledesc
 binmode close closedir eof fileno getc
 lstat print printf readdir readline readpipe rewinddir
 say select stat tell telldir write
 nextgroup=perlFiledescStatementNocomma skipwhite

Even if you haven’t upgraded to Perl 5.10, you can use Jim Keenan’s Perl6::Say module to add the say function.

Share your dotfiles and check out others

December 11, 2007 Tools No comments

dotfiles.org is a site that collects dotfiles for various shells and editors. If you’ve ever read someone else’s .bashrc and said “Oh, THAT’S a cool trick”, this is the site for you. If you haven’t, now’s the time to start. If you don’t know what a dotfile is, or haven’t modified the dotfile for your editor and shell, now is definitely the time to start.

Popular dotfiles include:

  • .vimrc
  • .screenrc
  • .zshrc
  • .bashrc
  • .irbrc
  • .Xdefaults
  • .conkyrc
  • .bash_profile
  • .xinitrc
  • .emacs

I’ve only put my .vimrc up on my personal wiki, but I can see I’ll need to put it up here as well.

ctags 5.7 improves Perl support

September 8, 2007 Tools No comments

Exuberant ctags, the standard tags utility on most systems today, has released version 5.7 for download with the following improvements to its Perl support (among many other improvements):

  • Added support for ‘package’ keyword
  • Added support for multi-line subroutine, package, and constant definitions
  • Added support for optional subroutine declarations
  • Added support for formats
  • Ignore comments mixed into definitions and declarations
  • Fixed detecting labels with whitespace after label name
  • Fixed misidentification of fully qualified function calls as labels

If you’ve never used tags or ctags, start today. Your life will never be the same after.

For example, if you run ctags on a tree of source code, and then run vim -t some_function from the shell, vim will open the file where some_function lives and leave your cursor there. Alternatively, if you’re editing a file with vim and you position your cursor over the word some_function and press Ctrl-], vim will jump to the function. Other editors have similar bindings.

Your editor doesn’t know Perl, but it relies on ctags generating a tags file, which is in a standard file. Of course, ctags isn’t perl itself, so isn’t as exact. These improvements in v5.7 will make your tag files more accurate.

If you’ve got a Perl module, it’s easy to add a makefile target for tags. See any of my major modules (WWW::Mechanize, ack, etc) and steal from the Makefile.PL, or just add the following to your Makefile.PL:

sub MY::postamble {
my $postamble = <<'MAKE_FRAG';
.PHONY: tags
tags:
ctags -f tags --recurse --totals 
--exclude=blib 
--exclude=.svn 
--exclude='*~' 
--languages=Perl --langmap=Perl:+.t 
MAKE_FRAG
}

(With ctags 5.7 it turns out, that --exclude=.svn is no longer necessary, as ctags automatically knows to ignore it now.)