Random thoughts shooting out of volatile mind
Inserting GPL license notice in Emacs
If you have used Geany a simple IDE it allows you to insert the GPL or similar license into the code file. I use Emacs and when I want to insert some sort of open source license I had to switch back to Geany and insert the license and return back to Emacs. Finally I thought of writing my own yasnippet to do this job. I've written 2 separate snippet files one for Python and other can be used by all languages which use C style comments.

The snippet does the following
1. It gets the name of the file from the current buffer's name
2. Copyright statement similar to one found in GPL license notice. Here I extract the year from current date. Also I insert the user name and email address from elisp variables user-full-name and user-mail-address. For customizing user name and email address please add the following lines in your .emacs file
(setq user-full-name
"Your name")
(setq user-mail-address
"Your email address")
3. Next comes the type of license. You can select license from drop down (Lesser,Affero) if you want to use GPL then just leave this field to default.
4. Version is also selected from drop down. Version 2 and 3 are for GPL,Affero and 2 2.1 for Lesser GPL. Its up-to user to select proper version for a license selected in previous option.

The first 2 options that is file name and copyright lines can be edited to override default values. Please use Tab key to navigate from one field to other.

Here are the installation instruction
1. Copy the pygpl to snippets/text-mode/python-mode/ folder.
2. Copy the cgpl file to snippets/text-mode/cc-mode directory and then create hard links using ln in c-mode and c++-mode.
1. In the Python mode just type pygpl and then hit Tab key and license notice will be inserted starting from the line where you wrote pygpl.
2. For C/C++ or any other mode follow the same step just type in cgpl instead of pygpl rest all remains same.
Here is a screen shot of the license notice inserted in a Python file

You can get the snippets from github. This is the first version of these snippets. Any suggestions on improvements are welcome :)
Posted by: copyninja on Sunday, 8 August 2010

blog comments powered by Disqus
Fork me on GitHub