DEF_CMD(python_doc_call);
static void python_free_command(struct command *c safe);
-static struct python_command *export_callable(PyObject *callable safe)
+static struct python_command *export_callable(PyObject *callable safe,
+ PyObject *nm)
{
struct python_command *c;
+ const char *name = NULL;
+ int len;
+
+ if (nm && PyUnicode_Check(nm))
+ name = PyUnicode_AsUTF8(nm);
+ if (!name)
+ name = "";
+ len = strlen(name);
list_for_each_entry(c, &exported_commands, lst)
if (c->callable == callable) {
c->c = python_call;
c->c.free = python_free_command;
c->c.refcnt = 0;
- c->c.closed_ok = 0;
+ if (strcmp(name, "handle_close") == 0 ||
+ (len > 10 &&
+ strcmp(name+len-10, "_closed_ok") == 0))
+ c->c.closed_ok = 1;
+ else
+ c->c.closed_ok = 0;
command_get(&c->c);
Py_INCREF(callable);
c->callable = callable;
if (doc && doc != Py_None) {
PyObject *tofree = NULL;
char *docs = python_as_string(doc, &tofree);
+
if (docs &&
strstarts(docs, "handle-range") &&
docs[12]) {
char *b = strndup(s1+1, s2-(s1+1));
struct python_command *comm =
- export_callable(m);
+ export_callable(m, e);
key_add_range(self->map, a, b,
&comm->c);
free(a); free(b);
char *b = strconcat(self->pane,
a, "\xFF\xFF\xFF\xFF");
struct python_command *comm =
- export_callable(m);
+ export_callable(m, e);
key_add_range(self->map, a, b,
&comm->c);
command_put(&comm->c);
if (m && PyMethod_Check(m)) {
PyObject *doc = PyObject_GetAttrString(m, "__doc__");
- if (doc && doc != Py_None) {
- PyObject *tofree = NULL;
- char *docs = python_as_string(doc, &tofree);
- if (docs &&
- strstarts(docs, "handle:")) {
+ char *docs;
+ PyObject *tofree = NULL;
+ if (doc && doc != Py_None &&
+ (docs = python_as_string(doc, &tofree)) != NULL) {
+
+ if (strstarts(docs, "handle:")) {
struct python_command *comm =
- export_callable(m);
+ export_callable(m, e);
key_add(self->map, docs+7, &comm->c);
command_put(&comm->c);
}
- if (docs &&
- strstarts(docs, "handle-list") &&
+ if (strstarts(docs, "handle-list") &&
docs[11]) {
char sep = docs[11];
char *s1 = docs + 12;
while (s1 && *s1 && *s1 != sep) {
struct python_command *comm =
- export_callable(m);
+ export_callable(m, e);
char *a;
char *s2 = strchr(s1, sep);
if (s2) {
command_put(&comm->c);
}
}
- Py_XDECREF(tofree);
}
+ Py_XDECREF(tofree);
Py_XDECREF(doc);
}
Py_XDECREF(m);
return False;
}
} else if (PyCallable_Check(a)) {
- struct python_command *pc = export_callable(a);
+ struct python_command *pc = export_callable(a, NULL);
if (ci->comm2 == NULL)
ci->comm2 = &pc->c;
return False;
}
} else if (PyCallable_Check(a)) {
- struct python_command *pc = export_callable(a);
+ struct python_command *pc = export_callable(a, NULL);
ci->comm2 = &pc->c;
} else {