On 05/07/10 03:26, JD wrote:
Hey fellow listmates,

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.

Thanks
JD


1. Don't forget that a changeset number is not shared between clones; the 12- or 40-nybble changeset ID is more portable. 2. The problem withthis whole approach is that it could run a shell command every time the status line needs to be refreshed, which might mean at every move of the cursor. 3. The output of "hg id" when run outside of a repository, is predictable (and IIUC identical to what you would get in a new repository where nothing has been committed yet). I think that the following function would compute what you need:

function HgId()
        if &buftype != "" || !filereadable(expand('%')
                return ""
        endif
        let id = system('cd ' . expand('%:p:h') . ' && hg id -nibt')
        if v:shell_error || id == "000000000000 -1 default tip\n"
                return ""
        else
                return id[:-2]
        endif
endfunc

but I also think that invoking Mercurial at every statusline refresh is too heavy. Maybe the following would be better

 :map <F5>
 \ :echo system('cd ' . expand('%:p:h') . ' ; hg id -nibt')[:-2]<CR>
 :imap <F5> <C-O><F5>

so you could display it on-demand by hitting a key (e.g. the F5 key). In this case you would just get "000000000000 -1 default tip" if outside of any repository or in a freshly initiated repository without even a "changeset zero".


Best regards,
Tony.

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