You may remember one of my previous posts on a Vim script I wrote to quickly open an issue in the browser from the OOo sources. As the patches/dev300/apply file is containing issues numbers formatted differently (in the form i#XXXXX instead of #iXXXXX#), I decided to tweak my script to support this other issues format.

The previous OpenIssue function was using expand("\<cword>") in order to get the selected issue. This is not working for the new format I wanted to support as # is a words delimiter. Thanks to word_tools.vim from Luc Hermitte, I have written a new function getting all the issues formats. Here is the new code:

" Get the issue number under the cursor. An issue number is containing
" digits, lating letters and #. The # characters are removed from the result.
" Code heavily inspired from the words_tools.vim of Luc Hermitte
function! GetCurrentIssueText()
  let c = col ('.')-1
  let l = line('.')
  let ll = getline(l)
  let ll1 = strpart(ll,0,c)
  let ll1 = matchstr(ll1,'[0-9#a-zA-Z]*$')
  if strlen(ll1) == 0
    return ll1
    let ll2 = strpart(ll,c,strlen(ll)-c+1)
    let ll2 = strpart(ll2,0,match(ll2,'$\|[^0-9#a-zA-Z]'))
    let text = ll1.ll2

    let text = substitute( text, "#", "", "g" )
    return text

" Open IssueZilla / Bugzilla for the selected issue
function! OpenIssue( )

    let s:browser = "firefox"

    let s:issueText = GetCurrentIssueText( )
    let s:urlTemplate = ""
    let s:pattern = "\\(\\a\\+\\)\\(\\d\\+\\)"

    let s:prefix = substitute( s:issueText, s:pattern, "\\1", "" )
    let s:id = substitute( s:issueText, s:pattern, "\\2", "" )

    if s:prefix == "i"
        let s:urlTemplate = ""
    elseif s:prefix == "n"
        let s:urlTemplate = ""

    if s:urlTemplate != ""
        let s:url = substitute( s:urlTemplate, "%", s:id, "g" )
        let s:cmd = "silent !" . s:browser . " " . s:url . "&"
        execute s:cmd

map   :call OpenIssue()