Karsten Hopp f55637
To: vim_dev@googlegroups.com
Karsten Hopp f55637
Subject: Patch 7.3.1044
Karsten Hopp f55637
Fcc: outbox
Karsten Hopp f55637
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp f55637
Mime-Version: 1.0
Karsten Hopp f55637
Content-Type: text/plain; charset=UTF-8
Karsten Hopp f55637
Content-Transfer-Encoding: 8bit
Karsten Hopp f55637
------------
Karsten Hopp f55637
Karsten Hopp f55637
Patch 7.3.1044
Karsten Hopp f55637
Problem:    Python: No {Buffer,TabPage,Window}.valid attributes.
Karsten Hopp f55637
Solution:   Python patch 5: add .valid (ZyX)
Karsten Hopp f55637
Files:	    src/if_py_both.h, src/if_python3.c, src/if_python.c,
Karsten Hopp f55637
	    src/testdir/test86.in, src/testdir/test86.ok,
Karsten Hopp f55637
	    src/testdir/test87.in, src/testdir/test87.ok
Karsten Hopp f55637
Karsten Hopp f55637
Karsten Hopp f55637
*** ../vim-7.3.1043/src/if_py_both.h	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/if_py_both.h	2013-05-29 22:08:36.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1815,1820 ****
Karsten Hopp f55637
--- 1815,1833 ----
Karsten Hopp f55637
  }
Karsten Hopp f55637
  
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
+ TabPageAttrValid(TabPageObject *self, char *name)
Karsten Hopp f55637
+ {
Karsten Hopp f55637
+     PyObject *r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     if (strcmp(name, "valid") != 0)
Karsten Hopp f55637
+ 	return NULL;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     r = ((self->tab == INVALID_TABPAGE_VALUE) ? Py_False : Py_True);
Karsten Hopp f55637
+     Py_INCREF(r);
Karsten Hopp f55637
+     return r;
Karsten Hopp f55637
+ }
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     static PyObject *
Karsten Hopp f55637
  TabPageAttr(TabPageObject *self, char *name)
Karsten Hopp f55637
  {
Karsten Hopp f55637
      if (strcmp(name, "windows") == 0)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 2010,2015 ****
Karsten Hopp f55637
--- 2023,2041 ----
Karsten Hopp f55637
  }
Karsten Hopp f55637
  
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
+ WindowAttrValid(WindowObject *self, char *name)
Karsten Hopp f55637
+ {
Karsten Hopp f55637
+     PyObject *r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     if (strcmp(name, "valid") != 0)
Karsten Hopp f55637
+ 	return NULL;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     r = ((self->win == INVALID_WINDOW_VALUE) ? Py_False : Py_True);
Karsten Hopp f55637
+     Py_INCREF(r);
Karsten Hopp f55637
+     return r;
Karsten Hopp f55637
+ }
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     static PyObject *
Karsten Hopp f55637
  WindowAttr(WindowObject *self, char *name)
Karsten Hopp f55637
  {
Karsten Hopp f55637
      if (strcmp(name, "buffer") == 0)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 2050,2057 ****
Karsten Hopp f55637
  	return (PyObject *)(self->tabObject);
Karsten Hopp f55637
      }
Karsten Hopp f55637
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp f55637
! 	return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
Karsten Hopp f55637
! 		"vars", "options", "number", "row", "col", "tabpage");
Karsten Hopp f55637
      else
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  }
Karsten Hopp f55637
--- 2076,2083 ----
Karsten Hopp f55637
  	return (PyObject *)(self->tabObject);
Karsten Hopp f55637
      }
Karsten Hopp f55637
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp f55637
! 	return Py_BuildValue("[ssssssssss]", "buffer", "cursor", "height",
Karsten Hopp f55637
! 		"vars", "options", "number", "row", "col", "tabpage", "valid");
Karsten Hopp f55637
      else
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  }
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 3186,3191 ****
Karsten Hopp f55637
--- 3212,3230 ----
Karsten Hopp f55637
  }
Karsten Hopp f55637
  
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
+ BufferAttrValid(BufferObject *self, char *name)
Karsten Hopp f55637
+ {
Karsten Hopp f55637
+     PyObject *r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     if (strcmp(name, "valid") != 0)
Karsten Hopp f55637
+ 	return NULL;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     r = ((self->buf == INVALID_BUFFER_VALUE) ? Py_False : Py_True);
Karsten Hopp f55637
+     Py_INCREF(r);
Karsten Hopp f55637
+     return r;
Karsten Hopp f55637
+ }
Karsten Hopp f55637
+ 
Karsten Hopp f55637
+     static PyObject *
Karsten Hopp f55637
  BufferAttr(BufferObject *self, char *name)
Karsten Hopp f55637
  {
Karsten Hopp f55637
      if (strcmp(name, "name") == 0)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 3198,3204 ****
Karsten Hopp f55637
  	return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
Karsten Hopp f55637
  			(PyObject *) self);
Karsten Hopp f55637
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp f55637
! 	return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
Karsten Hopp f55637
      else
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  }
Karsten Hopp f55637
--- 3237,3244 ----
Karsten Hopp f55637
  	return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
Karsten Hopp f55637
  			(PyObject *) self);
Karsten Hopp f55637
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp f55637
! 	return Py_BuildValue("[sssss]", "name", "number", "vars", "options",
Karsten Hopp f55637
! 		"valid");
Karsten Hopp f55637
      else
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  }
Karsten Hopp f55637
*** ../vim-7.3.1043/src/if_python3.c	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/if_python3.c	2013-05-29 22:08:36.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1067,1078 ****
Karsten Hopp f55637
   */
Karsten Hopp f55637
  
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
! BufferGetattro(PyObject *self, PyObject*nameobj)
Karsten Hopp f55637
  {
Karsten Hopp f55637
      PyObject *r;
Karsten Hopp f55637
  
Karsten Hopp f55637
      GET_ATTR_STRING(name, nameobj);
Karsten Hopp f55637
  
Karsten Hopp f55637
      if (CheckBuffer((BufferObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
--- 1067,1081 ----
Karsten Hopp f55637
   */
Karsten Hopp f55637
  
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
! BufferGetattro(PyObject *self, PyObject *nameobj)
Karsten Hopp f55637
  {
Karsten Hopp f55637
      PyObject *r;
Karsten Hopp f55637
  
Karsten Hopp f55637
      GET_ATTR_STRING(name, nameobj);
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = BufferAttrValid((BufferObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckBuffer((BufferObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1094,1101 ****
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
  BufferDir(PyObject *self UNUSED)
Karsten Hopp f55637
  {
Karsten Hopp f55637
!     return Py_BuildValue("[sssss]", "name", "number",
Karsten Hopp f55637
! 						   "append", "mark", "range");
Karsten Hopp f55637
  }
Karsten Hopp f55637
  
Karsten Hopp f55637
  /******************/
Karsten Hopp f55637
--- 1097,1105 ----
Karsten Hopp f55637
      static PyObject *
Karsten Hopp f55637
  BufferDir(PyObject *self UNUSED)
Karsten Hopp f55637
  {
Karsten Hopp f55637
!     return Py_BuildValue("[ssssssss]",
Karsten Hopp f55637
! 	    "name", "number", "vars", "options", "valid",
Karsten Hopp f55637
! 	    "append", "mark", "range");
Karsten Hopp f55637
  }
Karsten Hopp f55637
  
Karsten Hopp f55637
  /******************/
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1283,1288 ****
Karsten Hopp f55637
--- 1287,1295 ----
Karsten Hopp f55637
  
Karsten Hopp f55637
      GET_ATTR_STRING(name, nameobj);
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckTabPage((TabPageObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1303,1308 ****
Karsten Hopp f55637
--- 1310,1318 ----
Karsten Hopp f55637
  
Karsten Hopp f55637
      GET_ATTR_STRING(name, nameobj);
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = WindowAttrValid((WindowObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckWindow((WindowObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
*** ../vim-7.3.1043/src/if_python.c	2013-05-29 22:05:51.000000000 +0200
Karsten Hopp f55637
--- src/if_python.c	2013-05-29 22:08:36.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1125,1130 ****
Karsten Hopp f55637
--- 1125,1133 ----
Karsten Hopp f55637
  {
Karsten Hopp f55637
      PyObject *r;
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = BufferAttrValid((BufferObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckBuffer((BufferObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1206,1211 ****
Karsten Hopp f55637
--- 1209,1217 ----
Karsten Hopp f55637
  {
Karsten Hopp f55637
      PyObject *r;
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckTabPage((TabPageObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 1224,1229 ****
Karsten Hopp f55637
--- 1230,1238 ----
Karsten Hopp f55637
  {
Karsten Hopp f55637
      PyObject *r;
Karsten Hopp f55637
  
Karsten Hopp f55637
+     if ((r = WindowAttrValid((WindowObject *)(self), name)))
Karsten Hopp f55637
+ 	return r;
Karsten Hopp f55637
+ 
Karsten Hopp f55637
      if (CheckWindow((WindowObject *)(self)))
Karsten Hopp f55637
  	return NULL;
Karsten Hopp f55637
  
Karsten Hopp f55637
*** ../vim-7.3.1043/src/testdir/test86.in	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/testdir/test86.in	2013-05-29 22:08:36.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 513,518 ****
Karsten Hopp f55637
--- 513,519 ----
Karsten Hopp f55637
      if _b is not cb:
Karsten Hopp f55637
          vim.command('bwipeout! ' + str(_b.number))
Karsten Hopp f55637
  del _b
Karsten Hopp f55637
+ cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
Karsten Hopp f55637
  for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")', 'b.name = "!"'):
Karsten Hopp f55637
      try:
Karsten Hopp f55637
          exec(expr)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 663,671 ****
Karsten Hopp f55637
--- 664,676 ----
Karsten Hopp f55637
  cb.append('Current window: ' + repr(vim.current.window))
Karsten Hopp f55637
  cb.append('Current buffer: ' + repr(vim.current.buffer))
Karsten Hopp f55637
  cb.append('Current line: ' + repr(vim.current.line))
Karsten Hopp f55637
+ ws = list(vim.windows)
Karsten Hopp f55637
+ ts = list(vim.tabpages)
Karsten Hopp f55637
  for b in vim.buffers:
Karsten Hopp f55637
      if b is not cb:
Karsten Hopp f55637
          vim.command('bwipeout! ' + str(b.number))
Karsten Hopp f55637
+ cb.append('w.valid: ' + repr([w.valid for w in ws]))
Karsten Hopp f55637
+ cb.append('t.valid: ' + repr([t.valid for t in ts]))
Karsten Hopp f55637
  EOF
Karsten Hopp f55637
  :tabonly!
Karsten Hopp f55637
  :only!
Karsten Hopp f55637
*** ../vim-7.3.1043/src/testdir/test86.ok	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/testdir/test86.ok	2013-05-29 22:09:47.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 328,333 ****
Karsten Hopp f55637
--- 328,334 ----
Karsten Hopp f55637
  1:BufFilePre:1
Karsten Hopp f55637
  7:BufFilePost:1
Karsten Hopp f55637
  testdir/test86.in
Karsten Hopp f55637
+ valid: b:False, cb:True
Karsten Hopp f55637
  i:<buffer test86.in>
Karsten Hopp f55637
  i2:<buffer test86.in>
Karsten Hopp f55637
  i:<buffer a>
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 344,350 ****
Karsten Hopp f55637
  Current tab pages:
Karsten Hopp f55637
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
!     <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (36, 0)
Karsten Hopp f55637
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
Karsten Hopp f55637
--- 345,351 ----
Karsten Hopp f55637
  Current tab pages:
Karsten Hopp f55637
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
!     <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (37, 0)
Karsten Hopp f55637
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 370,375 ****
Karsten Hopp f55637
--- 371,378 ----
Karsten Hopp f55637
  Current window: <window 0>
Karsten Hopp f55637
  Current buffer: <buffer test86.in>
Karsten Hopp f55637
  Current line: 'Type error at assigning None to vim.current.buffer'
Karsten Hopp f55637
+ w.valid: [True, False]
Karsten Hopp f55637
+ t.valid: [True, False, True, False]
Karsten Hopp f55637
  vim.vars:Dictionary:True
Karsten Hopp f55637
  vim.options:Options:True
Karsten Hopp f55637
  vim.bindeval("{}"):Dictionary:True
Karsten Hopp f55637
*** ../vim-7.3.1043/src/testdir/test87.in	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/testdir/test87.in	2013-05-29 22:08:36.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 500,505 ****
Karsten Hopp f55637
--- 500,506 ----
Karsten Hopp f55637
      if _b is not cb:
Karsten Hopp f55637
          vim.command('bwipeout! ' + str(_b.number))
Karsten Hopp f55637
  del _b
Karsten Hopp f55637
+ cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
Karsten Hopp f55637
  for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
Karsten Hopp f55637
      try:
Karsten Hopp f55637
          exec(expr)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 641,649 ****
Karsten Hopp f55637
--- 642,654 ----
Karsten Hopp f55637
  cb.append('Current window: ' + repr(vim.current.window))
Karsten Hopp f55637
  cb.append('Current buffer: ' + repr(vim.current.buffer))
Karsten Hopp f55637
  cb.append('Current line: ' + repr(vim.current.line))
Karsten Hopp f55637
+ ws = list(vim.windows)
Karsten Hopp f55637
+ ts = list(vim.tabpages)
Karsten Hopp f55637
  for b in vim.buffers:
Karsten Hopp f55637
      if b is not cb:
Karsten Hopp f55637
          vim.command('bwipeout! ' + str(b.number))
Karsten Hopp f55637
+ cb.append('w.valid: ' + repr([w.valid for w in ws]))
Karsten Hopp f55637
+ cb.append('t.valid: ' + repr([t.valid for t in ts]))
Karsten Hopp f55637
  EOF
Karsten Hopp f55637
  :tabonly!
Karsten Hopp f55637
  :only!
Karsten Hopp f55637
*** ../vim-7.3.1043/src/testdir/test87.ok	2013-05-29 22:02:18.000000000 +0200
Karsten Hopp f55637
--- src/testdir/test87.ok	2013-05-29 22:10:11.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 317,322 ****
Karsten Hopp f55637
--- 317,323 ----
Karsten Hopp f55637
  1:BufFilePre:1
Karsten Hopp f55637
  7:BufFilePost:1
Karsten Hopp f55637
  testdir/test87.in
Karsten Hopp f55637
+ valid: b:False, cb:True
Karsten Hopp f55637
  i:<buffer test87.in>
Karsten Hopp f55637
  i2:<buffer test87.in>
Karsten Hopp f55637
  i:<buffer a>
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 333,339 ****
Karsten Hopp f55637
  Current tab pages:
Karsten Hopp f55637
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
!     <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (36, 0)
Karsten Hopp f55637
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
Karsten Hopp f55637
--- 334,340 ----
Karsten Hopp f55637
  Current tab pages:
Karsten Hopp f55637
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
!     <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (37, 0)
Karsten Hopp f55637
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
Karsten Hopp f55637
    Windows:
Karsten Hopp f55637
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 359,364 ****
Karsten Hopp f55637
--- 360,367 ----
Karsten Hopp f55637
  Current window: <window 0>
Karsten Hopp f55637
  Current buffer: <buffer test87.in>
Karsten Hopp f55637
  Current line: 'Type error at assigning None to vim.current.buffer'
Karsten Hopp f55637
+ w.valid: [True, False]
Karsten Hopp f55637
+ t.valid: [True, False, True, False]
Karsten Hopp f55637
  vim.vars:Dictionary:True
Karsten Hopp f55637
  vim.options:Options:True
Karsten Hopp f55637
  vim.bindeval("{}"):Dictionary:True
Karsten Hopp f55637
*** ../vim-7.3.1043/src/version.c	2013-05-29 22:05:51.000000000 +0200
Karsten Hopp f55637
--- src/version.c	2013-05-29 22:10:45.000000000 +0200
Karsten Hopp f55637
***************
Karsten Hopp f55637
*** 730,731 ****
Karsten Hopp f55637
--- 730,733 ----
Karsten Hopp f55637
  {   /* Add new patch number below this line */
Karsten Hopp f55637
+ /**/
Karsten Hopp f55637
+     1044,
Karsten Hopp f55637
  /**/
Karsten Hopp f55637
Karsten Hopp f55637
-- 
Karsten Hopp f55637
hundred-and-one symptoms of being an internet addict:
Karsten Hopp f55637
20. When looking at a pageful of someone else's links, you notice all of them
Karsten Hopp f55637
    are already highlighted in purple.
Karsten Hopp f55637
Karsten Hopp f55637
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp f55637
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp f55637
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp f55637
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///