Hi all,
This is my first post here and I am not 100% sure if this topic
really belongs here.. Anyway, I'll give it a try.
I recently dealt with using vim's python omnicompletion for SAGE
development (see www.sagemath.org).
In order to get SAGE working in vim I tried
:py import sage.all
However, this fails due to the minimalistic implementation of
sys.stdout in vim's python interpreter (... and, to be honest,
due to a bug in SAGE which imports unnecessary stuff, which relies
on attributes that are not guaranteed to exist).
To be more precise, :py import sage.all crashes because vim's
sys.stdout has no 'flush' attribute.
I patched vim to include a dummy implementation of
sys.stdout.flush, which does nothing at all.
A corresponding patch file is attached.
I wondered, if this modification could be merged into upstream?
Admittedly, the changes are quite specific and the python
documentation of sys.stdout states that vim's implementation is
100% correct:
[...] stdout and stderr needn’t be built-in file objects: any
object is acceptable as long as it has a write() method that
takes a string argument.
(See http://docs.python.org/library/sys.html)
However, the documentation of file.flush() also says:
[...] This may be a no-op on some file-like objects.
(See http://docs.python.org/library/stdtypes.html#file-objects)
So it seems to me that my dummy flush implementation is alright
and should break no working code.
Tobias Columbus
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
*** src/src/if_py_both.h 2011-03-19 17:20:20.642621721 +0100
--- patches/src/if_py_both.h 2011-03-19 17:23:09.019620937 +0100
*************** Python_Release_Vim(void)
*** 33,38 ****
--- 33,39 ----
static PyObject *OutputWrite(PyObject *, PyObject *);
static PyObject *OutputWritelines(PyObject *, PyObject *);
+ static PyObject *OutputFlush( PyObject *, PyObject *);
/* Function to write a line, points to either msg() or emsg(). */
typedef void (*writefn)(char_u *);
*************** static struct PyMethodDef OutputMethods[
*** 49,54 ****
--- 50,56 ----
/* name, function, calling, documentation */
{"write", OutputWrite, 1, "" },
{"writelines", OutputWritelines, 1, "" },
+ {"flush", OutputFlush, 1, ""},
{ NULL, NULL, 0, NULL }
};
*************** OutputWritelines(PyObject *self, PyObjec
*** 123,128 ****
--- 125,145 ----
return Py_None;
}
+ static PyObject *
+ OutputFlush(PyObject *self, PyObject *args)
+ {
+ int len;
+ char *str;
+ int error = ((OutputObject *)(self))->error;
+
+ if (!PyArg_ParseTuple(args, "s#", &str, &len))
+ return NULL;
+
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+
/* Buffer IO, we write one whole line at a time. */
static garray_T io_ga = {0, 0, 1, 80, NULL};
static writefn old_fn = NULL;