Posts Tagged ‘snipMate’

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

My software stack revisited – Programming

Friday, December 24th, 2010

Programming is one of my primary interests, mainly because it allows me to stimulate my brain with solving problems, but also force it to think in new ways.

Languages

I started programming in PHP, picked up Java and Erlang during classes at ITU, picked up Python on my own during my studies at ITU, and my latest addition would be shell scripting.

Slightly tangent to the topic are the markup languages I have picked up as well, html and css in high-school and LaTeX at ITU. I dabbled around for a while with both creole and markdown, but that didn’t last long.

Editor / IDE

My first and foremost tool of choice given nearly any situation will be (g)vim. The only two exceptions I can think of off the bat is Java (for which I use Eclipse and if I need to write a whole lot of text, with minimal distraction (more on that later).

The pragmatic programmers recommend learning one text-editor, and learn it well. If the name of that editor is vim, emacs, kate, gedit, or whatever, I really don’t care. Just pick up one that fits you, and LEARN IT WELL!

I have extended vim with a couple of plugins, the most prominent being NERD Commenter, matchit, snipMate and sparkup. There are at least two more plugins, but I will write more about those later.

And for Python, I usually install the IPython interactive prompt as it is a fair bit more useful than the standard python-prompt.

Version Control

While studying at ITU I had my eyes opened about the wonderful concept of version control.

I was first exposed to SVN, and while quite capable, I figured it was too much of a hassle to set it up myself, since that would require the presence of a server somewhere to host the SVN repositories.

But then mercurial entered the stage. Git or bazaar would have done the job just as good, but the people orchestrating the fourth term settled on mercurial, and it is so dead simple and still powerful enough for what I need that I haven’t had a reason to look elsewhere.

Issue tracking

For a course at ITU I tried using Mantis, a web-based bug tracker written in PHP, and while it worked well, it was a hassle to manipulate bug reports since it meant I’d have to go online and log in to yet another system.

I have however found a different solution which I am currently trying out: a plugin to mercurial called b with the tagline “distributed bug tracking”. It is a bit too early to tell if it will do, but for the time being it solves the immediate problem of having to go online somewhere to handle bugs.

Next post in line: “Office Suite” software

:wq

Vim + snipMate

Sunday, March 14th, 2010

As I sat down in front of the computer today and started reading the identi.ca backlog I came across this gem, which lead here, about how to turn Vim into a Python IDE. The blogpost itself contained many useful tips/tricks (the code folding script being on the top of that list), but as is often the case, the really cool stuff gets unearthed in the comments, like this one about snipMate. Also, excellent video presentation is excellent!

That post also lead me to another post on that blog which inspired me to finally start looking into ctags, which is a two step installation, one being installing the package exuberant-ctags from the repository, and the other fetching this script.

All I need to do now is try to learn the key mappings M^e, f, M^f, and TT/F4 ;D oh, and to tab a lot ;D