Monday, April 26, 2010

Re: How to embed VCSInfo into file comments?

Hi Ken-JP!

On Mo, 26 Apr 2010, Ken-JP wrote:

>
> Hi,
>
> I have recently discovered the wonderful
>
> :VCSInfo
>
> command from the vcscommand.vim script. Below is a sample output from one
> of my files.
>
> 1 Path: Identifier.cpp$
> 2 Name: Identifier.cpp$
> 3 URL: svn://localhost/dev/robolab/cpp/src/Identifier.cpp$
> 4 Repository Root: svn://localhost$
> 5 Repository UUID: be881e60-0d39-4e2c-82cd-b428fd5aaff4$
> 6 Revision: 702$
> 7 Node Kind: file$
> 8 Schedule: normal$
> 9 Last Changed Author: kfeng$
> 10 Last Changed Rev: 661$
> 11 Last Changed Date: 2010-03-23 10:11:51 +0800 (Tue, 23 Mar 2010)$
> 12 Text Last Updated: 2010-04-24 19:16:15 +0800 (Sat, 24 Apr 2010)$
> 13 Checksum: da0f4f13bdd9addb1354b76f56d70c08$
>
> -------------------------------
>
> My question is, is there a way to get vim to automatically pull this
> information (or part of the information, for example lines 9 through 12)
> into file comments? For example, if I have something like this:
>
> /* Some comments....
> * ...
> * _PUT_VCSInfo_HERE
> */
>
> so that _PUT_VCSInfo_HERE is inserted with lines 9 through 12 from above
> every time I commit back into VCS?
>
> I am guessing that there is either a macro/script way of doing this, but I
> am too much of a vim-noob to figure it out, or it is so common that someone
> has created a script to do it already.
> Any suggestions? TIA.

This is a quick and dirty approach. My excuse is, I do not know neither
vcscommand.vim nor :VCSInfo (though I probably have it installed
somewhere)

Anyway, my solution would be to split the string on the fly:
:redir =>a|exe ':silent :VCSInfo'|redir end|let b=split(a,'\n')|exe
':call append(' . search('^\s*\*\s*_PUT_VCSINFO_HERE', 'n') . ', b[8:])'
(one line)

This takes the output from the :VCSInfo command, splits it into a list
at linebreaks, searches for any of a start of line, any amount of space,
followed by any amount of space followed by _PUT_VCSINFO_HERE and
appends on that line the captured output of lines 9 till the end.

You might want to use setline() instead of append() so that on further
calls, you overwrite your previous lines. Make sure to leave enough
room, or else you'll overwrite your code.

You can probably all that put into a little command or even a map. That
is left as excercise to the reader (I always wanted to write that part
into my mails ;))

Oh and you probably want to read on at
:h Lists
:h append()
:h setline()
:h :redir
:h split()
:h search()

regards,
Christian

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Subscription settings: http://groups.google.com/group/vim_use/subscribe?hl=en

No comments:

Post a Comment