Posts Tagged ‘GPLv3’

Vim and adding licenses to code

Thursday, March 31st, 2011

A while back @psquid gave me a new perspective on things.

I can’t remember what the discussion was about, but it left me with the realization that my current system (of having file type templates in vim coming with predefined licenses (GPL v3)) was flawed.

The thing I believe he got out of the discussion was that one could use snipMate to define ones own shortcuts for inserting licences into source code.

I couldn’t tell you why I hesitated so long before trying it, since the idea seemed sound. But when I did try it I came to two conclusions:

(1) It wouldn’t work the way I wanted it to , or (2) at least not without duplication.

Since I on occasion program both Python, Java, PHP, Bash and, infrequently, Erlang, in order to have licensing snippets (think GPL3, BSD, and the odd CC By-SA) I’d need to put these license-blurbs into each snippet file that should support it (since Python don’t do C-style comments, and Erlang-style comments are completely different as well)

So what I wanted was some way to call a Vim command (say NERD Commenter ( ,,cs )) once a certain snippet (the license blurb) had been expanded.

I am pretty sure this can’t be done in an easy way, so I gave that idea up. Mapping a key, say F3, to a user defined command in my .vimrc, however,  would be much easier.

Something along the lines of:

function! GPL3()
    r~/static/templates/gpl3
    :.,$call NERDComment(0, 'sexy')
endfunction
nmap  :call GPL3()

I am not well-versed at all with scripting vim, so I have probably made some embarrassing mistakes (for one, I should probably read up on what the heck that exclamation mark at the beginning of the function does. Please do point out any mistakes.)

All in all I am pretty content with this solution, but if someone know of a way to trigger a command after a snipMate expansion (and only on specific expansions, and only on the specific expanded lines) I am all ears.

(This since there is a _.snippet which seem to be included in all instances regardless of file type, which means I could still have the licenses in one place, defined once, but used with different comments anyway, which would be awesome) :)

:wq

Introducing jQuery.xmastree

Saturday, January 15th, 2011

With this post I hereby announce the first release of a little jQuery-script I call xmastree. This script has NOTHING to do with Christmas decorations.

I could have given the project the more specific name jQuery.HullOpeningIndicator, but that is both long and ugly, and I fear that it would also have trapped people in thinking that it could only be useful for indicating whether openings in a submarines hull were either open or closed.

In simplified terms, an xmastree on board a submarine is a panel which displays the state of every opening into said submarine. In a submarine, the only two reasonable states are “open” and “closed”.

As such, a submarine xmastree (hull opening indicator) visualizes a series of binary states.

And that is what jQuery.xmastree attempts to mimic. Of course, this xmastree will make no assumptions about what these states represent, or how they should be visualized (that is configurable and left to the user to decide). In fact, jQuery.xmastree make no assumption about the data being visualized is binary either. It most certainly doesn’t need to be, there are no such limitations in the code.

The demo use ASCII for visualization, but one could just as simply modify data.json to have xmastree output <img> tags and thus images.

This project is released under the GNU GPL version 3 or later, and the source may be found here.

:wq