Auto insert module header

by Ruslan Spivak on November 1, 2010

It’s a good development practice to insert at the beginning of a file copyright, license, and author information. Being lazy I automated the process of insertion using Emacs’ skeleton mode and auto insert mode.

This is an example skeleton configuration:

When I open a new Python file with C-x C-f the header is inserted automatically:

Skeletons support Lisp expressions, so I embedded automatic year generation as well as retrieval of organization’s name, user’s full name, and user’s email address. (You may need to add ORGANIZATION and EMAIL environment variables to your .bash_profile)
M-x skeleton-name will call the skeleton interactively and insert it at the cursor’s position

Alternatively the header insertion automation can be accomplished with yasnippet package, which I use with different programming modes.

If you enjoyed this post why not subscribe via email or my RSS feed and get the latest updates immediately. You can also follow me on GitHub or Twitter.

{ 7 comments… read them below or add one }

matt harrison November 1, 2010 at 10:40 AM

Seems like a bunch of license texts would be a good contribution for yasnippet…. (gpl, gpl3, mit, bsd, apache, psf….)

Reply

Ruslan Spivak November 1, 2010 at 9:07 PM

Hi Matt,

I agree, it’s a good idea and it would be convenient – no need to reinvent the wheel over and over again.

Reply

Borbus November 16, 2010 at 6:22 AM

Actually I have already done a load for my own benefit, maybe I will send them all to the yasnippet author.

Reply

MrM November 1, 2010 at 1:57 PM

Don’t forget to add copyright-update to keep the copyright notice up-to-date when editing older files as well. ;-)

Reply

Ruslan Spivak November 1, 2010 at 9:09 PM

Thanks for copyright-update – didn’t know about it.

Reply

Gunnar Tveiten November 4, 2010 at 8:33 AM

The code is fine – but adding kilobytes of junk to the top of every file is silly. Intellectual works are copyrigthed whether or not you say so, so you don’t actually need to say anything. But if you must, “copyright [name] [company] [year] for details see LICENCE.txt” is plenty.

Reply

Borbus November 16, 2010 at 9:47 AM

It’s only really important when the software is licensed under a free software licence, and even more importantly when it’s a copyleft licence. The reader needs to be aware that the code is *not* public domain but *is* free software.

If you don’t have a licence + copyright notice then anyone reading must assume that the work is copyrighted and all rights are reserved which is totally wrong if it’s supposed to be free software. The whole point is that you *can* use this code, without the header the code is basically useless to anyone and everyone except the actual (unknown) copyright holder.

Having the notice in every file means that even if somehow the files become separated or conflated with other projects the individual rights are still known. This is *very* important! Think about large projects such as Linux (the kernel) where it’s not hard to find 20 different files by 20 different authors.

Reply

Speak your mind

Previous post:

Next post: