ZyX_I avatar ZyX_I committed c6f8fda

@aurum/drivers/mercurial: Changed python/aurum.py so that it works with vim.bindeval
(if it is available, of course)

Comments (0)

Files changed (2)

plugin/aurum/drivers/mercurial.vim

 if s:usepythondriver "▶2
 function s:hg.status(repo, ...)
     let revargs=join(map(copy(a:000), 'v:val is 0? "None": string(v:val)'), ',')
-    let r={}
+    let d={}
     try
         execute s:_r.py.cmd 'aurum.get_status(vim.eval("a:repo.path"), '.
                     \                         revargs.')'
     endtry
-    return r
+    return d
 endfunction
 else "▶2
 let s:statchars={
     r=[set_rev_dict(g_cs(repo, i), {'rev': i,}) for i in range(startrev, cscount+1)]
     return r
 
+if hasattr(vim, 'bindeval'):
+    def vim_extend(val, var='d', utf=True, list=False):
+        d_vim = vim.bindeval(var)
+        if list:
+            d_vim.extend(val)
+        else:
+            for key in val:
+                d_vim[key] = val[key]
+else:
+    def vim_extend(val, var='d', utf=True, list=False):
+        vim.eval('extend('+var+', '+((utf_dumps if utf else nonutf_dumps)(val))+')')
+
 @outermethod
 def get_updates(repo, oldtip=None):
     tipcs=repo['tip']
     bookmarks_vim={}
     if hasattr(repo, 'listkeys'):
         bookmarks_vim=repo.listkeys('bookmarks')
-    if hasattr(vim, 'bindeval'):
-        repo_vim=vim.bindeval('a:repo')
-        repo_vim['csnum']=len(repo)+1
-        d_vim=vim.bindeval('d')
-        d['css']=r
-        d['startrev']=startrev
-        d['tags']=tags_vim
-        d['bookmarks']=bookmarks_vim
-    else:
-        d_vim={      'css': r,
-                'startrev': startrev,
-                    'tags': tags_vim,
-               'bookmarks': bookmarks_vim,}
-        vim.eval('extend(a:repo, {"csnum": '+str(len(repo)+1)+'})')
-        vim.eval('extend(d, '+utf_dumps(d_vim)+')')
+    vim_extend(var='a:repo', val={'csnum': (len(repo)+1)})
+    vim_extend(val={'css': r,
+               'startrev': startrev,
+                   'tags': tags_vim,
+              'bookmarks': bookmarks_vim,})
 
 def get_cs_tag_dict(l):
     r={}
     if hasattr(repo, 'listkeys'):
         bookmarks=get_cs_tag_dict([(val, key) for key, val
                                    in repo.listkeys('bookmarks').items()])
-    return vim.eval('extend(d, '+utf_dumps({'tags': tags,
-                                       'bookmarks': bookmarks})+')')
+    vim_extend(val={'tags': tags, 'bookmarks': bookmarks})
 
 @outermethod
 def get_cs(repo, rev):
     cs=g_cs(repo, rev)
-    cs_vim=set_rev_dict(cs, {'rev': cs.rev()})
-    vim.eval('extend(cs, '+utf_dumps(cs_vim)+')')
+    vim_extend(var='cs', val=set_rev_dict(cs, {'rev': cs.rev()}))
 
 @outermethod
 def new_repo(repo):
              }
     if hasattr(repo, '__len__'):
         vim_repo['csnum']=len(repo)+1
-    vim.eval('extend(repo, '+utf_dumps(vim_repo)+')')
+    vim_extend(var='repo', val=vim_repo)
 
 @outermethod
 def get_file(repo, rev, filepath):
     fctx=g_fctx(g_cs(repo, rev), filepath)
     lines=[line.replace("\0", "\n") for line in fctx.data().split("\n")]
-    vim.eval('extend(r, '+nonutf_dumps(lines)+')')
+    vim_extend(var='r', val=lines, utf=False, list=True)
 
 @outermethod
 def annotate(repo, rev, filepath):
     ann=g_fctx(g_cs(repo, rev), filepath).annotate(follow=True, linenumber=True)
     ann_vim=[(line[0][0].path(), str(line[0][0].rev()), line[0][1])
                                                             for line in ann]
-    vim.eval('extend(r, '+nonutf_dumps(ann_vim)+')')
+    vim_extend(var='r', val=ann_vim, utf=False, list=True)
 
 def run_in_dir(dir, func, *args, **kwargs):
     workdir=os.path.abspath('.')
 def diff(*args, **kwargs):
     ui=CaptureUI()
     dodiff(ui, *args, **kwargs)
-    vim.eval('extend(r, '+nonutf_dumps(ui._getCaptured())+')')
+    vim_extend(var='r', val=ui._getCaptured(), utf=False, list=True)
 
 @outermethod
 def diffToBuffer(*args, **kwargs):
         else:
             copies_vim[f]=0
             renames_vim[f]=0
-    vim.eval('extend(a:cs, '+nonutf_dumps({'renames': renames_vim,
-                                            'copies': copies_vim})+')')
+    vim_extend(var='a:cs', val={'renames': renames_vim, 'copies': copies_vim},
+               utf=False)
 
 @outermethod
 def get_cs_prop(repo, rev, prop):
                 am.append(f)
             else:
                 r.append(f)
-        vim.eval('extend(a:cs, {  "files": '+nonutf_dumps(am)+', '+
-                               '"removes": '+nonutf_dumps(r) +', '+
-                               '"changes": '+nonutf_dumps(c) +'})')
+        vim_extend(var='a:cs', val={'files': am, 'removes': r, 'changes': c},
+                   utf=False)
         return
     elif prop=='renames' or prop=='copies':
         get_renames(cs)
         r=cs.__getattribute__(prop)()
     # XXX There is much code relying on the fact that after getcsprop
     #     property with given name is added to changeset dictionary
-    vim.eval('extend(a:cs, {"'+prop+'": '+nonutf_dumps(r)+'})')
+    vim_extend(var='a:cs', val={prop : r}, utf=False)
 
 @outermethod
 def get_status(repo, rev1=None, rev2=None, files=None, clean=None):
             m=match.match(None, None, files, exact=True)
         status=repo.status(rev1, rev2, ignored=True, clean=clean,
                            unknown=True, match=m)
-        vim.eval('extend(r, '+nonutf_dumps({'modified': status[0],
-                                               'added': status[1],
-                                             'removed': status[2],
-                                             'deleted': status[3],
-                                             'unknown': status[4],
-                                             'ignored': status[5],
-                                               'clean': status[6],
-                                           })+')')
+        vim_extend(val={'modified': status[0],
+                           'added': status[1],
+                         'removed': status[2],
+                         'deleted': status[3],
+                         'unknown': status[4],
+                         'ignored': status[5],
+                           'clean': status[6],},
+                   utf=False)
     else:
         vim_throw('statuns', repo.path)
 
         if r is None:
             vim_throw('failcfg', prop, repo.path)
         else:
-            vim.eval('extend(d, {"'+prop+'": '+utf_dumps(r)+'})')
+            vim_extend(val={prop : r})
     else:
         vim_throw('nocfg', repo.path, prop)
 
         else:
             file=(rev, file)
         r_vim.append({'filename': file, 'lnum': int(lnum), 'text': text})
-    vim.eval('extend(r, '+nonutf_dumps(r_vim)+')')
+    vim_extend(var='r', val=r_vim, utf=False, list=True)
 
 @outermethod
 def git_hash(repo, rev):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.