Commits

ZyX_I  committed 214630b

Added :AuHyperlink (constructs URL and puts it to clipboard).
URL is constructed out of paths.default-push or paths.default and points to a place
where file contents can be viewed on the web

  • Participants
  • Parent commits 70911d1

Comments (0)

Files changed (3)

File plugin/aurum.vim

     call FraworLoad('@/commands')
     call FraworLoad('@/functions')
     " TODO improve files completion
-    " TODO :AuSearch, :AuBrowse
+    " TODO :AuSearch
     " TODO :AuMerge ?
     " TODO :AuTree
     " TODO aurum#changeset(), aurum#repository() and aurum#status()
     let s:addargs={'Update': {'bang': 1}, 'Move': {'bang': 1}}
-    for s:cmd in ['Diff', 'File', 'Update', 'Move', 'Junk', 'Add']
+    for s:cmd in ['Diff', 'File', 'Update', 'Move', 'Junk', 'Add', 'Hyperlink']
         let s:part=tolower(s:cmd[:3])
         if len(s:cmd)>4 && stridx('aeiouy', s:part[-1:])!=-1
             let s:part=s:part[:-2]
         \}
 let s:_messages={
             \'nocread': 'Cannot read aurum://commit',
+            \ 'invurl': 'Failed to parse url %s of repository %s',
+            \ 'unkurl': 'Failed to process url %s of repository %s',
         \}
 "▶1 closebuf :: bvar → + buf
 function s:F.closebuf(bvar)
 call add(s:addcomp,
             \substitute(s:addfunc['@FWC'][0],
             \'\V+ type ""', '+ (path)', ''))
+"▶1 hypfunc
+" len("hgroot")=6
+let s:hypsites=[
+\['domain is? "bitbucket.org"', '"https://".domain.path."/src/".cs.hex."/".file', '"cl-".line'],
+\['domain is? "github.com"',    '"https://".domain."/".substitute(path, "\\v^\\:|\\.git$", "", "g").'.
+\                                                 '"/blob/".gitbranch."/".file',
+\                               '"L".line'],
+\['domain =~? "\\Vhg.sourceforge.net\\$"',
+\                               '"http://".domain."/hgweb".path[7:]."/file/".cs.hex."/".file',
+\                               '"l".line'],
+\['domain =~? "\\Vgooglecode.com\\$" && path[:2] is? "/hg"',
+\                               '"http://code.google.com/p/".matchstr(domain, "\\v^[^.]+").'.
+\                                                     '"/source/browse/".file."?r=".cs.hex',
+\                               'line'],
+\]
+" TODO urlescape file
+" TODO More domains support
+" TODO aurum#hyperlink ?
+function s:hypfunc.function(opts)
+    let [hasbuf, repo, rev, file]=s:_r.cmdutils.getrrf(a:opts, 'nocurf', 0)
+    call s:_r.cmdutils.checkrepo(repo)
+    let opts=copy(a:opts)
+    if rev is 0
+        if has_key(opts, 'line') &&
+                    \index(repo.functions.status(repo).clean, file)==-1
+            call remove(opts, 'line')
+        endif
+        let rev=repo.work_hex
+    endif
+    let cs=repo.functions.getcs(repo, rev)
+    let url=repo.functions.getrepoprop(repo, 'url')
+    let [dummystr, protocol, user, domain, port, path; dummylst]=
+                \matchlist(url, '\v^%(([^:]+)\:\/\/)?'.
+                \                  '%(([^@/:]+)\@)?'.
+                \                   '([^/:]*)'.
+                \                  '%(\:(\d+))?'.
+                \                   '(.*)$')
+    if empty(domain)
+        call s:_f.throw('invurl', url, repo.path)
+    endif
+    let gitbranch=substitute(get(cs.bookmarks, 0, 'master'), '\m^origin/', '', '')
+    for sitedef in s:hypsites
+        if eval(sitedef[0])
+            let r=eval(sitedef[1])
+            if has_key(opts, 'line')
+                if opts.line
+                    let line=opts.line
+                elseif hasbuf
+                    let line=line('.')
+                endif
+            endif
+            if exists('line')
+                let r.='#'.eval(sitedef[2])
+            endif
+            let cmd=get(opts, 'cmd', 'let @+=%s')
+            execute printf(cmd, string(r))
+            return
+        endif
+    endfor
+    call s:_f.throw('uknurl', url, repo.path)
+endfunction
+let s:hypfunc['@FWC']=['-onlystrings {?repo '.s:_r.cmdutils.nogetrepoarg.
+            \                       ' ?rev   type ""'.
+            \                       ' ?file  type ""'.
+            \                       ' ?line  range 0 inf'.
+            \                       ' ?cmd   type ""'.
+            \                       '}', 'filter']
+call add(s:hypcomp,
+            \substitute(substitute(substitute(s:hypfunc['@FWC'][0],
+            \'\Vfile\s\+type ""', 'file path',           ''),
+            \'\Vcmd\s\+type ""',  'cmd '.s:_r.comp.cmd,  ''),
+            \'\Vrev\s\+type ""',  'rev '.s:_r.comp.rev,  ''))
 "▶1
 call frawor#Lockvar(s:, '_pluginloaded,_r')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/drivers/mercurial.vim

             \ 'destex': 'Cannot copy %s to %s: destination already exists',
             \ 'nhgiwr': 'File %s is either a directory or not writeable',
             \'reponwr': 'Unable to write to repository root (%s)',
+            \  'nocfg': 'Failed to get property %s of repository %s ',
         \}
 "▶1 addchangesets :: repo, [cs] → _ + repo
 function s:F.addchangesets(repo, css)

File python/aurum.py

                 r=repo.listkeys('bookmarks').keys()
             else:
                 r=[]
-        if r is not None:
+        elif prop=='url':
+            r=repo.ui.config('paths', 'default-push')
+            if r is None:
+                r=repo.ui.config('paths', 'default')
+        if r is None:
+            vim_throw('nocfg', prop, repo.path)
+        else:
             vim.eval('extend(a:repo, {"'+prop+'": '+utf_dumps(r)+'})')
     except AurumError:
         pass