On Jul 5, 3:14 am, Jürgen Krämer <[email protected]> wrote:
> Hi,
>
> JD schrieb:
>
>
>
>
>
> > I was hoping someone could help me with this. I'd like to put the
> > current hg revision of the project i'm working on in the Vim
> > statusline to make it really easy to see without having to use hg log
> > or something. I have an idea of the commands necessary to do this, but
> > i'm not nearly good enough with Vim scripting so I was hoping someone
> > here would be able to help me out.
>
> > The shell commands that would give me the information I want/need from
> > mercurial are:
> > 'hg id -n' or 'hg tip --template "{rev}"' which print a 2, 3 or 4
> > digit number to stdout. Also, it'd need to run one of those hg
> > commands in the dir of the file i'm opening, not ~ or something.
>
> > Finally (and i could probably do this myself if necessary), it'd need
> > to check the dir of the file and keep going up a directory till it
> > finds a .hg directory to run one of those commands and if it doesn't
> > find one, don't do anything to the statusbar or run the hg commands.
>
> > I know i may be asking a lot, but i really know very little about Vim
> > scripting so i'm hoping some of the people more experienced on this
> > mailing list could help.
>
> put the following in your .vimrc or in a .vim file inside your local
> plugin directory:
>
>     function! HgRevision(filename)
>         " Get the path where the file resides.
>         let dir = fnamemodify(a:filename, ':p:h')
>
>         " Find out if it's in a directory controlled by Mercurial by
>         " searching upwards for a directory named '.hg'.
>         let hg = finddir('.hg', dir . ';')
>
>         " If it is not controlled by Mercurial, quit.
>         if hg == ''
>             return ''
>         endif
>
>         " We must call hg from the directory where the file resides.
>         " After the call we return to the current directory.
>         let olddir = getcwd()
>         exe 'cd ' . dir
>         let result = '[Rev: ' . system('hg tip --template "{rev}"') . ']'
>         exe 'cd ' . olddir
>
>         " We are done and return a string containing the information.
>         return result
>     endfunction
>
>     " Whenever we read a file or create new file we put the Mercurial
>     " revision in a buffer-local variable. The content of this variable
>     " is then inserted into the statuslines of the windows containing the
>     " file.
>     autocmd BufRead,BufNewFile *
>           \ let b:HgRev=HgRevision(expand('<afile>')) |
>           \ setl statusline=...%{b:HgRev}...
>
> In the last line you will have to replace the dots by the parts of your
> normal statusline that you want to see before and after the revision.
> Alternative you could try to reuse the current statusline by using
>
>           \ setl statusline+=%{b:HgRev}
>
> This would append the revision at the end of the statusline.
>
> Regards,
> J rgen
>
> --
> Sometimes I think the surest sign that intelligent life exists elsewhere
> in the universe is that none of it has tried to contact us.     (Calvin)

Wow! Thanks Jurgen! I'm definetly going to use this and i'm pretty
sure some other people probably will as well. Thankfully, a bit ago, I
found my own solution to this problem. I took the MinSCM plugin[1],
made some small modifications to it and IMO, it now fits my needs
perfectly. I published it because maybe someone else might find it
useful[2].

Sorry for possibly sounding a bit like an ass here if i come off that
way or ungrateful or something. I had a quite nice post pretty much
completely written up and then my power went out for the second time
this weekend so i'm quite a bit upset.

Thanks for the code though!
JD

[1]  http://www.vim.org/scripts/script.php?script_id=2637
[2]  http://github.com/jdhore/MinSCM

-- 
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

Reply via email to