Commits

ZyX_I  committed fc9ba7a

@%aurum/drivers/common/utils: Made it use python’s subprocess.Popen to read
shell output as it is much faster

  • Participants
  • Parent commits 6bf72b1

Comments (0)

Files changed (2)

File autoload/aurum/drivers/common/utils.vim

 endfunction
 "▶1 readsystem :: cmd[, cdpath] → [String]
 if has('python') && exists('*pyeval')
-    python import aurum.utils
-    function s:F.readsystem(...)
-        return pyeval('aurum.utils.readsystem(*vim.eval("a:000"))')
-    endfunction
+    try
+        " This way is much faster
+        python import aurum.utils
+        function s:F.readsystem(...)
+            unsilent echom string(a:000)
+            return pyeval('aurum.utils.readsystem(*vim.eval("a:000"))')
+        endfunction
+    catch
+    endtry
 endif
 "▶1 utils.run :: cmd, hasnulls::0|1|2, path → [String] + shell
 function s:utils.run(cmd, hasnulls, cdpath)
         endif
     endif
     if a:hasnulls
+        " XXX Remove this code? Or keep as-is as it avoids temporary files in 
+        "     some cases?
         let savedlazyredraw=&lazyredraw
         let savedeventignore=&eventignore
         set eventignore=all

File python/aurum/utils.py

+# XXX This should throw an exception if it is unusable
+from subprocess import Popen, PIPE
+def readsystem(cmd, cwd=None):
+    if not cwd:
+        cwd=None
+    p=Popen(cmd, shell=False, stdout=PIPE, cwd=cwd)
+    lines=[]
+    lastnl=False
+    for line in p.stdout:
+        lastnl=(line[-1]=='\n')
+        lines.append((line[:-1] if lastnl else line).replace('\0', '\n'))
+    if lastnl:
+        lines.append('')
+    exit_code=p.poll()
+    return lines, exit_code
+# vim: ft=python ts=4 sw=4 sts=4 et tw=100