Commits

ZyX_I committed fd86a9e

Added :AuMove command (untested)

Comments (0)

Files changed (5)

ftplugin/aurumstatus.vim

     return ':<C-u>call call(<SID>Eval("s:F.runmap"), '.string(a:000).', {})<CR>'
 endfunction
 "▲2
-" TODO Add K/J mappings
 call s:_f.mapgroup.add('AuStatus', {
             \    'Exit': {'lhs':  'X',   'rhs': ':<C-u>bwipeout!<CR>'    },
             \    'Open': {'lhs': '<CR>', 'rhs': s:F.getrhs(       'open')},
     call FraworLoad('@/functions')
     " TODO improve files completion
     " TODO :AuSearch, :AuBrowse, :AuAdd, :AuPush, :AuPull
-    " TODO :AuMove with functionality similar to zmv
     " TODO :AuMerge ?
     " TODO :AuForget (forget), :AuForget! (forget and remove)
     "      :AuForget ignore (adds ignored *patterns* to ./.hgignore and adds
     "                        .hgignore to repository if it is not present)
     " TODO :AuDirectory/:AuTree
     " TODO aurum#changeset(), aurum#repository() and aurum#status()
-    let s:addargs={'Update': {'bang': 1}}
-    for s:cmd in ['Diff', 'File', 'Update']
+    let s:addargs={'Update': {'bang': 1}, 'Move': {'bang': 1}}
+    for s:cmd in ['Diff', 'File', 'Update', 'Move']
         let s:part=tolower(s:cmd[:3])
         if len(s:cmd)>4 && stridx('aeiouy', s:part[-1:])!=-1
             let s:part=s:part[:-2]
             \'\V _',                '',            ''),
             \'\V|*_r.repo.get',     '',            ''),
             \'\V:"tip"\s\+type ""', s:_r.comp.rev, ''))
+"▶1 movefunc
+function s:movefunc.function(bang, opts, ...)
+    if a:0
+        let repo=s:_r.repo.get(a:0)
+    else
+        let repo=s:_r.repo.get(':')
+    endif
+    let cs=repo.functions.getcs(repo, '.')
+    call repo.functions.getcsprop(repo, cs, 'allfiles')
+    if get(a:opts, 'copy', 0)
+        let key='copy'
+    else
+        let key='move'
+    endif
+    let rrfopts={'repo': repo.path}
+    if a:0==0
+        let target='.'
+        let files=[repo.functions.reltorepo(repo,
+                    \s:_r.cmdutils.getrrf(rrfopts, 'nocurf', -1)[3])]
+    elseif a:0==1 && isdirectory(a:1)
+        let target=a:1
+        let files=[repo.functions.reltorepo(repo,
+                    \s:_r.cmdutils.getrrf(rrfopts, 'nocurf', -1)[3])]
+    elseif a:0==2 && a:2=~#'[*?]' &&
+                \substitute(a:1, '\v(^|$|[^*?])[^*?]*', '-', 'g') is#
+                \substitute(a:2, '\v(^|$|[^*?])[^*?]*', '-', 'g')
+        let pattern=s:_r.cmdutils.globtopat(repo.functions.reltorepo(repo, a:1),
+                    \                       1)
+        let repl=split(a:2, '\V\(**\?\|?\)', 1)
+        let moves={}
+        for [file, match] in filter(map(copy(cs.allfiles),
+                    \                   '[v:val, matchlist(v:val, pattern)]'),
+                    \               '!empty(v:val[1])')
+            let target=''
+            let i=1
+            for s in repl
+                let target .= s . get(match, i, '')
+                let i+=1
+            endfor
+            let moves[file]=target
+        endfor
+        for [file, target] in items(moves)
+            let target=repo.functions.reltorepo(repo, target)
+            call call(repo.functions[key], [repo, a:bang, file, target], {})
+        endfor
+        return
+    elseif a:0==2 && !isdirectory(a:2)
+        let fst=a:1
+        if fst is# ':'
+            let fst=s:_r.cmdutils.getrrf(rrfopts, 'nocurf', -1)[3]
+        endif
+        call call(repo.functions[key], [repo, a:bang,
+                    \                   repo.functions.reltorepo(repo, fst),
+                    \                   repo.functions.reltorepo(repo, a:2)],
+                    \{})
+        return
+    else
+        let globs=filter(copy(a:000), 'v:val isnot# ":"')
+        let hascur=(len(globs)!=a:0)
+        if a:0==1 || !isdirectory(globs[-1])
+            let target='.'
+        else
+            let target=remove(globs, -1)
+        endif
+        let files=[]
+        for pattern in map(copy(globs), 's:_r.cmdutils.globtopat('.
+                    \                   'repo.functions.reltorepo(repo,v:val))')
+            let files+=filter(copy(cs.allfiles),
+                        \     'v:val=~#pattern && index(files, v:val)==-1')
+        endfor
+        if hascur
+            let files+=[s:_r.cmdutils.getrrf(rrfopts, 'nocurf', -1)[3]]
+        endif
+    endif
+    let target=repo.functions.reltorepo(repo, target)
+    for file in files
+        let dest=s:_r.os.path.basename(file)
+        if !empty(target)
+            let dest=s:_r.os.path.join(target, dest)
+        endif
+        echom file '->' dest
+        call call(repo.functions[key], [repo, a:bang, file, dest], {})
+    endfor
+endfunction
+let s:movefunc['@FWC']=['-onlystrings _ '.
+            \           '{ ?!copy } '.
+            \           '+ type ""', 'filter']
+call add(s:movecomp,
+            \substitute(substitute(s:movefunc['@FWC'][0],
+            \'\V _',        '',         ''),
+            \'\V+ type ""', '+ (path)', ''))
 "▶1
 call frawor#Lockvar(s:, '_pluginloaded,_r')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

plugin/aurum/cmdutils.vim

             \ 'nocurf': 'Failed to deduce which file was meant',
             \'nocfile': 'Unsure what should be commited',
         \}
-"▶1 globtopattern :: glob → pattern
-function s:F.globtopattern(glob)
+"▶1 globtopattern :: glob[, catchstars] → pattern
+function s:F.globtopattern(glob, ...)
     " XXX If more metacharacters will be supported, they must be added to 
     " escape() calls in s:F.filehistory in ftplugin/aurumlog and in logfunc 
     " call
     if g[-1:] is# '/'
         let g=g[:-2]
     endif
+    let catchstars=(a:0&&a:1)
     let incurl=0
     let curlit=[]
     let outr=[]
         let c=g[0]
         let g=g[1:]
         if c is# '*'
+            if catchstars
+                let r.='\('
+            endif
             if g[0] is# '*'
                 let g=g[1:]
                 if g[0] is# '/'
             else
                 let r.='\[^/]\*'
             endif
+            if catchstars
+                let r.='\)'
+            endif
         elseif c is# '?'
-            let r.='\[^/]'
+            let r.=((catchstars)?('\(\[^/]\)'):('\[^/]'))
         elseif c is# '[' && stridx(g, ']')!=-1
             let r.='\['
             if g[0] is# '!'
     endif
     return file
 endfunction
-"▶1 getrrf :: opts, failmsg + buf → (hasbuf, repo, rev, file)
+"▶1 getrrf :: opts, failmsg, ann + buf → (hasbuf, repo, rev, file)
 let s:rrffailresult=[0, 0, 0, 0]
 function s:F.getrrf(opts, failmsg, ann)
     let hasbuf=0

plugin/aurum/drivers/mercurial.vim

             \           'operation not supported',
             \ 'upduns': 'Unable to update working directory state for '.
             \           'repository %s: operation not supported',
+            \ 'destex': 'Cannot copy %s to %s: destination already exists',
         \}
 "▶1 hg.addchangesets :: repo, [cs] → _ + repo
 function s:hg.addchangesets(repo, css)
     endtry
     return a:repo[a:prop]
 endfunction
+"▶1 hg.runcmd :: repo, attr, args, kwargs → + ?
+function s:hg.runcmd(repo, attr, args, kwargs)
+    execute s:_r.py.cmd 'aurum.call_cmd(vim.eval("a:repo.path"), '.
+                \                      'vim.eval("a:attr"), '.
+                \                      '*vim.eval("a:args"), '.
+                \                      '**vim.eval("a:kwargs"))'
+endfunction
+"▶1 hg.move :: repo, force, source, target → + FS
+function s:hg.move(repo, force, ...)
+    return a:repo.functions.runcmd(a:repo, 'rename', a:000,
+                \                  a:force ? {'force': 1} : {})
+endfunction
+"▶1 hg.copy :: repo, force, source, target → + FS
+function s:hg.copy(repo, force, ...)
+    return a:repo.functions.runcmd(a:repo, 'copy', a:000,
+                \                  a:force ? {'force': 1} : {})
+endfunction
 "▶1 Post resource
 call s:_f.postresource('mercurial', s:hg)
 "▶1
 
 class PrintUI(ui.ui):
     @staticmethod
-    def _write(f, o):
+    def _write(f, o, warning=False):
         try:
             return f.write(str(o))
         except UnicodeDecodeError:
-            vim.command('echomsg '+utf_dumps(str(o)))
-            # return None
-            # return f.write(bytearray(o, 'utf8'))
+            for line in str(o).split("\n"):
+                if line == '':
+                    line=' '
+                if warning:
+                    vim.command('echohl ErrorMsg')
+                vim.command('echomsg '+utf_dumps(line))
+                if warning:
+                    vim.command('echohl None')
 
     # ui.ui for some reason does not support outputting unicode
     def write(self, *args, **kwargs):
 
     def write_err(self, *args, **kwargs):
         for a in args:
-            self._write(self.ferr, a)
+            self._write(self.ferr, a, True)
 
 class CaptureUI(PrintUI):
     def __init__(self):
     except AurumError:
         pass
 
+def call_cmd(path, attr, *args, **kwargs):
+    try:
+        repo=g_repo(path)
+        if 'force' in kwargs:
+            kwargs['force']=not not kwargs['force']
+        else:
+            kwargs['force']=False
+        cargs=[PrintUI(), repo]
+        cargs.extend(args)
+        run_in_dir(repo.root, commands.__getattribute__(attr),
+                   *cargs, **kwargs)
+    except AurumError:
+        pass
+