# HG changeset patch
# User ZyX <[email protected]>
# Date 1369473652 -14400
# Node ID a71b70fc1b4ea887cc5361a13e43c0b594309593
# Parent  e6465392bfef41fcb4c92e7ddc7bf842b096c4ab
Add {Buffer,TabPage,Window}.valid attributes

diff -r e6465392bfef -r a71b70fc1b4e src/if_py_both.h
--- a/src/if_py_both.h  Sat May 25 12:41:27 2013 +0400
+++ b/src/if_py_both.h  Sat May 25 13:20:52 2013 +0400
@@ -1815,6 +1815,19 @@
 }
 
     static PyObject *
+TabPageAttrValid(TabPageObject *self, char *name)
+{
+    PyObject *r;
+
+    if (strcmp(name, "valid") != 0)
+       return NULL;
+
+    r = ((self->tab == INVALID_TABPAGE_VALUE) ? Py_False : Py_True);
+    Py_INCREF(r);
+    return r;
+}
+
+    static PyObject *
 TabPageAttr(TabPageObject *self, char *name)
 {
     if (strcmp(name, "windows") == 0)
@@ -2010,6 +2023,19 @@
 }
 
     static PyObject *
+WindowAttrValid(WindowObject *self, char *name)
+{
+    PyObject *r;
+
+    if (strcmp(name, "valid") != 0)
+       return NULL;
+
+    r = ((self->win == INVALID_WINDOW_VALUE) ? Py_False : Py_True);
+    Py_INCREF(r);
+    return r;
+}
+
+    static PyObject *
 WindowAttr(WindowObject *self, char *name)
 {
     if (strcmp(name, "buffer") == 0)
@@ -2050,8 +2076,8 @@
        return (PyObject *)(self->tabObject);
     }
     else if (strcmp(name,"__members__") == 0)
-       return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
-               "vars", "options", "number", "row", "col", "tabpage");
+       return Py_BuildValue("[ssssssssss]", "buffer", "cursor", "height",
+               "vars", "options", "number", "row", "col", "tabpage", "valid");
     else
        return NULL;
 }
@@ -3186,6 +3212,19 @@
 }
 
     static PyObject *
+BufferAttrValid(BufferObject *self, char *name)
+{
+    PyObject *r;
+
+    if (strcmp(name, "valid") != 0)
+       return NULL;
+
+    r = ((self->buf == INVALID_BUFFER_VALUE) ? Py_False : Py_True);
+    Py_INCREF(r);
+    return r;
+}
+
+    static PyObject *
 BufferAttr(BufferObject *self, char *name)
 {
     if (strcmp(name, "name") == 0)
@@ -3198,7 +3237,8 @@
        return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
                        (PyObject *) self);
     else if (strcmp(name,"__members__") == 0)
-       return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
+       return Py_BuildValue("[sssss]", "name", "number", "vars", "options",
+               "valid");
     else
        return NULL;
 }
diff -r e6465392bfef -r a71b70fc1b4e src/if_python.c
--- a/src/if_python.c   Sat May 25 12:41:27 2013 +0400
+++ b/src/if_python.c   Sat May 25 13:20:52 2013 +0400
@@ -1125,6 +1125,9 @@
 {
     PyObject *r;
 
+    if ((r = BufferAttrValid((BufferObject *)(self), name)))
+       return r;
+
     if (CheckBuffer((BufferObject *)(self)))
        return NULL;
 
@@ -1206,6 +1209,9 @@
 {
     PyObject *r;
 
+    if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
+       return r;
+
     if (CheckTabPage((TabPageObject *)(self)))
        return NULL;
 
@@ -1224,6 +1230,9 @@
 {
     PyObject *r;
 
+    if ((r = WindowAttrValid((WindowObject *)(self), name)))
+       return r;
+
     if (CheckWindow((WindowObject *)(self)))
        return NULL;
 
diff -r e6465392bfef -r a71b70fc1b4e src/if_python3.c
--- a/src/if_python3.c  Sat May 25 12:41:27 2013 +0400
+++ b/src/if_python3.c  Sat May 25 13:20:52 2013 +0400
@@ -1067,12 +1067,15 @@
  */
 
     static PyObject *
-BufferGetattro(PyObject *self, PyObject*nameobj)
+BufferGetattro(PyObject *self, PyObject *nameobj)
 {
     PyObject *r;
 
     GET_ATTR_STRING(name, nameobj);
 
+    if ((r = BufferAttrValid((BufferObject *)(self), name)))
+       return r;
+
     if (CheckBuffer((BufferObject *)(self)))
        return NULL;
 
@@ -1094,8 +1097,9 @@
     static PyObject *
 BufferDir(PyObject *self UNUSED)
 {
-    return Py_BuildValue("[sssss]", "name", "number",
-                                                  "append", "mark", "range");
+    return Py_BuildValue("[ssssssss]",
+           "name", "number", "vars", "options", "valid",
+           "append", "mark", "range");
 }
 
 /******************/
@@ -1283,6 +1287,9 @@
 
     GET_ATTR_STRING(name, nameobj);
 
+    if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
+       return r;
+
     if (CheckTabPage((TabPageObject *)(self)))
        return NULL;
 
@@ -1303,6 +1310,9 @@
 
     GET_ATTR_STRING(name, nameobj);
 
+    if ((r = WindowAttrValid((WindowObject *)(self), name)))
+       return r;
+
     if (CheckWindow((WindowObject *)(self)))
        return NULL;
 
diff -r e6465392bfef -r a71b70fc1b4e src/testdir/test86.in
--- a/src/testdir/test86.in     Sat May 25 12:41:27 2013 +0400
+++ b/src/testdir/test86.in     Sat May 25 13:20:52 2013 +0400
@@ -513,6 +513,7 @@
     if _b is not cb:
         vim.command('bwipeout! ' + str(_b.number))
 del _b
+cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
 for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")', 'b.name = 
"!"'):
     try:
         exec(expr)
@@ -663,9 +664,13 @@
 cb.append('Current window: ' + repr(vim.current.window))
 cb.append('Current buffer: ' + repr(vim.current.buffer))
 cb.append('Current line: ' + repr(vim.current.line))
+ws = list(vim.windows)
+ts = list(vim.tabpages)
 for b in vim.buffers:
     if b is not cb:
         vim.command('bwipeout! ' + str(b.number))
+cb.append('w.valid: ' + repr([w.valid for w in ws]))
+cb.append('t.valid: ' + repr([t.valid for t in ts]))
 EOF
 :tabonly!
 :only!
diff -r e6465392bfef -r a71b70fc1b4e src/testdir/test86.ok
--- a/src/testdir/test86.ok     Sat May 25 12:41:27 2013 +0400
+++ b/src/testdir/test86.ok     Sat May 25 13:20:52 2013 +0400
@@ -328,6 +328,7 @@
 1:BufFilePre:1
 7:BufFilePost:1
 /home/zyx/a.a/Proj/c/vim/src/testdir/test86.in
+valid: b:False, cb:True
 i:<buffer test86.in>
 i2:<buffer test86.in>
 i:<buffer a>
@@ -344,7 +345,7 @@
 Current tab pages:
   <tabpage 0>(1): 1 windows, current is <window object (unknown)>
   Windows:
-    <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor 
is at (36, 0)
+    <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor 
is at (37, 0)
   <tabpage 1>(2): 1 windows, current is <window object (unknown)>
   Windows:
     <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 
0)
@@ -370,6 +371,8 @@
 Current window: <window 0>
 Current buffer: <buffer test86.in>
 Current line: 'Type error at assigning None to vim.current.buffer'
+w.valid: [True, False]
+t.valid: [True, False, True, False]
 vim.vars:Dictionary:True
 vim.options:Options:True
 vim.bindeval("{}"):Dictionary:True
diff -r e6465392bfef -r a71b70fc1b4e src/testdir/test87.in
--- a/src/testdir/test87.in     Sat May 25 12:41:27 2013 +0400
+++ b/src/testdir/test87.in     Sat May 25 13:20:52 2013 +0400
@@ -500,6 +500,7 @@
     if _b is not cb:
         vim.command('bwipeout! ' + str(_b.number))
 del _b
+cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
 for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
     try:
         exec(expr)
@@ -641,9 +642,13 @@
 cb.append('Current window: ' + repr(vim.current.window))
 cb.append('Current buffer: ' + repr(vim.current.buffer))
 cb.append('Current line: ' + repr(vim.current.line))
+ws = list(vim.windows)
+ts = list(vim.tabpages)
 for b in vim.buffers:
     if b is not cb:
         vim.command('bwipeout! ' + str(b.number))
+cb.append('w.valid: ' + repr([w.valid for w in ws]))
+cb.append('t.valid: ' + repr([t.valid for t in ts]))
 EOF
 :tabonly!
 :only!
diff -r e6465392bfef -r a71b70fc1b4e src/testdir/test87.ok
--- a/src/testdir/test87.ok     Sat May 25 12:41:27 2013 +0400
+++ b/src/testdir/test87.ok     Sat May 25 13:20:52 2013 +0400
@@ -317,6 +317,7 @@
 1:BufFilePre:1
 7:BufFilePost:1
 /home/zyx/a.a/Proj/c/vim/src/testdir/test87.in
+valid: b:False, cb:True
 i:<buffer test87.in>
 i2:<buffer test87.in>
 i:<buffer a>
@@ -333,7 +334,7 @@
 Current tab pages:
   <tabpage 0>(1): 1 windows, current is <window object (unknown)>
   Windows:
-    <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor 
is at (36, 0)
+    <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor 
is at (37, 0)
   <tabpage 1>(2): 1 windows, current is <window object (unknown)>
   Windows:
     <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 
0)
@@ -359,6 +360,8 @@
 Current window: <window 0>
 Current buffer: <buffer test87.in>
 Current line: 'Type error at assigning None to vim.current.buffer'
+w.valid: [True, False]
+t.valid: [True, False, True, False]
 vim.vars:Dictionary:True
 vim.options:Options:True
 vim.bindeval("{}"):Dictionary:True

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff -cr vim.e6465392bfef/src/if_py_both.h vim.a71b70fc1b4e/src/if_py_both.h
*** vim.e6465392bfef/src/if_py_both.h	2013-05-25 14:58:14.910765314 +0400
--- vim.a71b70fc1b4e/src/if_py_both.h	2013-05-25 14:58:14.927756655 +0400
***************
*** 1815,1820 ****
--- 1815,1833 ----
  }
  
      static PyObject *
+ TabPageAttrValid(TabPageObject *self, char *name)
+ {
+     PyObject *r;
+ 
+     if (strcmp(name, "valid") != 0)
+ 	return NULL;
+ 
+     r = ((self->tab == INVALID_TABPAGE_VALUE) ? Py_False : Py_True);
+     Py_INCREF(r);
+     return r;
+ }
+ 
+     static PyObject *
  TabPageAttr(TabPageObject *self, char *name)
  {
      if (strcmp(name, "windows") == 0)
***************
*** 2010,2015 ****
--- 2023,2041 ----
  }
  
      static PyObject *
+ WindowAttrValid(WindowObject *self, char *name)
+ {
+     PyObject *r;
+ 
+     if (strcmp(name, "valid") != 0)
+ 	return NULL;
+ 
+     r = ((self->win == INVALID_WINDOW_VALUE) ? Py_False : Py_True);
+     Py_INCREF(r);
+     return r;
+ }
+ 
+     static PyObject *
  WindowAttr(WindowObject *self, char *name)
  {
      if (strcmp(name, "buffer") == 0)
***************
*** 2050,2057 ****
  	return (PyObject *)(self->tabObject);
      }
      else if (strcmp(name,"__members__") == 0)
! 	return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
! 		"vars", "options", "number", "row", "col", "tabpage");
      else
  	return NULL;
  }
--- 2076,2083 ----
  	return (PyObject *)(self->tabObject);
      }
      else if (strcmp(name,"__members__") == 0)
! 	return Py_BuildValue("[ssssssssss]", "buffer", "cursor", "height",
! 		"vars", "options", "number", "row", "col", "tabpage", "valid");
      else
  	return NULL;
  }
***************
*** 3186,3191 ****
--- 3212,3230 ----
  }
  
      static PyObject *
+ BufferAttrValid(BufferObject *self, char *name)
+ {
+     PyObject *r;
+ 
+     if (strcmp(name, "valid") != 0)
+ 	return NULL;
+ 
+     r = ((self->buf == INVALID_BUFFER_VALUE) ? Py_False : Py_True);
+     Py_INCREF(r);
+     return r;
+ }
+ 
+     static PyObject *
  BufferAttr(BufferObject *self, char *name)
  {
      if (strcmp(name, "name") == 0)
***************
*** 3198,3204 ****
  	return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
  			(PyObject *) self);
      else if (strcmp(name,"__members__") == 0)
! 	return Py_BuildValue("[ssss]", "name", "number", "vars", "options");
      else
  	return NULL;
  }
--- 3237,3244 ----
  	return OptionsNew(SREQ_BUF, self->buf, (checkfun) CheckBuffer,
  			(PyObject *) self);
      else if (strcmp(name,"__members__") == 0)
! 	return Py_BuildValue("[sssss]", "name", "number", "vars", "options",
! 		"valid");
      else
  	return NULL;
  }
diff -cr vim.e6465392bfef/src/if_python3.c vim.a71b70fc1b4e/src/if_python3.c
*** vim.e6465392bfef/src/if_python3.c	2013-05-25 14:58:14.915762767 +0400
--- vim.a71b70fc1b4e/src/if_python3.c	2013-05-25 14:58:14.931754618 +0400
***************
*** 1067,1078 ****
   */
  
      static PyObject *
! BufferGetattro(PyObject *self, PyObject*nameobj)
  {
      PyObject *r;
  
      GET_ATTR_STRING(name, nameobj);
  
      if (CheckBuffer((BufferObject *)(self)))
  	return NULL;
  
--- 1067,1081 ----
   */
  
      static PyObject *
! BufferGetattro(PyObject *self, PyObject *nameobj)
  {
      PyObject *r;
  
      GET_ATTR_STRING(name, nameobj);
  
+     if ((r = BufferAttrValid((BufferObject *)(self), name)))
+ 	return r;
+ 
      if (CheckBuffer((BufferObject *)(self)))
  	return NULL;
  
***************
*** 1094,1101 ****
      static PyObject *
  BufferDir(PyObject *self UNUSED)
  {
!     return Py_BuildValue("[sssss]", "name", "number",
! 						   "append", "mark", "range");
  }
  
  /******************/
--- 1097,1105 ----
      static PyObject *
  BufferDir(PyObject *self UNUSED)
  {
!     return Py_BuildValue("[ssssssss]",
! 	    "name", "number", "vars", "options", "valid",
! 	    "append", "mark", "range");
  }
  
  /******************/
***************
*** 1283,1288 ****
--- 1287,1295 ----
  
      GET_ATTR_STRING(name, nameobj);
  
+     if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
+ 	return r;
+ 
      if (CheckTabPage((TabPageObject *)(self)))
  	return NULL;
  
***************
*** 1303,1308 ****
--- 1310,1318 ----
  
      GET_ATTR_STRING(name, nameobj);
  
+     if ((r = WindowAttrValid((WindowObject *)(self), name)))
+ 	return r;
+ 
      if (CheckWindow((WindowObject *)(self)))
  	return NULL;
  
diff -cr vim.e6465392bfef/src/if_python.c vim.a71b70fc1b4e/src/if_python.c
*** vim.e6465392bfef/src/if_python.c	2013-05-25 14:58:14.918761239 +0400
--- vim.a71b70fc1b4e/src/if_python.c	2013-05-25 14:58:14.935752580 +0400
***************
*** 1125,1130 ****
--- 1125,1133 ----
  {
      PyObject *r;
  
+     if ((r = BufferAttrValid((BufferObject *)(self), name)))
+ 	return r;
+ 
      if (CheckBuffer((BufferObject *)(self)))
  	return NULL;
  
***************
*** 1206,1211 ****
--- 1209,1217 ----
  {
      PyObject *r;
  
+     if ((r = TabPageAttrValid((TabPageObject *)(self), name)))
+ 	return r;
+ 
      if (CheckTabPage((TabPageObject *)(self)))
  	return NULL;
  
***************
*** 1224,1229 ****
--- 1230,1238 ----
  {
      PyObject *r;
  
+     if ((r = WindowAttrValid((WindowObject *)(self), name)))
+ 	return r;
+ 
      if (CheckWindow((WindowObject *)(self)))
  	return NULL;
  
diff -cr vim.e6465392bfef/src/testdir/test86.in vim.a71b70fc1b4e/src/testdir/test86.in
*** vim.e6465392bfef/src/testdir/test86.in	2013-05-25 14:58:14.911764805 +0400
--- vim.a71b70fc1b4e/src/testdir/test86.in	2013-05-25 14:58:14.928756145 +0400
***************
*** 513,518 ****
--- 513,519 ----
      if _b is not cb:
          vim.command('bwipeout! ' + str(_b.number))
  del _b
+ cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
  for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")', 'b.name = "!"'):
      try:
          exec(expr)
***************
*** 663,671 ****
--- 664,676 ----
  cb.append('Current window: ' + repr(vim.current.window))
  cb.append('Current buffer: ' + repr(vim.current.buffer))
  cb.append('Current line: ' + repr(vim.current.line))
+ ws = list(vim.windows)
+ ts = list(vim.tabpages)
  for b in vim.buffers:
      if b is not cb:
          vim.command('bwipeout! ' + str(b.number))
+ cb.append('w.valid: ' + repr([w.valid for w in ws]))
+ cb.append('t.valid: ' + repr([t.valid for t in ts]))
  EOF
  :tabonly!
  :only!
diff -cr vim.e6465392bfef/src/testdir/test86.ok vim.a71b70fc1b4e/src/testdir/test86.ok
*** vim.e6465392bfef/src/testdir/test86.ok	2013-05-25 14:58:14.912764296 +0400
--- vim.a71b70fc1b4e/src/testdir/test86.ok	2013-05-25 14:58:14.929755636 +0400
***************
*** 328,333 ****
--- 328,334 ----
  1:BufFilePre:1
  7:BufFilePost:1
  /home/zyx/a.a/Proj/c/vim/src/testdir/test86.in
+ valid: b:False, cb:True
  i:<buffer test86.in>
  i2:<buffer test86.in>
  i:<buffer a>
***************
*** 344,350 ****
  Current tab pages:
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
    Windows:
!     <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (36, 0)
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
    Windows:
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
--- 345,351 ----
  Current tab pages:
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
    Windows:
!     <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (37, 0)
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
    Windows:
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
***************
*** 370,375 ****
--- 371,378 ----
  Current window: <window 0>
  Current buffer: <buffer test86.in>
  Current line: 'Type error at assigning None to vim.current.buffer'
+ w.valid: [True, False]
+ t.valid: [True, False, True, False]
  vim.vars:Dictionary:True
  vim.options:Options:True
  vim.bindeval("{}"):Dictionary:True
diff -cr vim.e6465392bfef/src/testdir/test87.in vim.a71b70fc1b4e/src/testdir/test87.in
*** vim.e6465392bfef/src/testdir/test87.in	2013-05-25 14:58:14.905767861 +0400
--- vim.a71b70fc1b4e/src/testdir/test87.in	2013-05-25 14:58:14.921759711 +0400
***************
*** 500,505 ****
--- 500,506 ----
      if _b is not cb:
          vim.command('bwipeout! ' + str(_b.number))
  del _b
+ cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
  for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc")'):
      try:
          exec(expr)
***************
*** 641,649 ****
--- 642,654 ----
  cb.append('Current window: ' + repr(vim.current.window))
  cb.append('Current buffer: ' + repr(vim.current.buffer))
  cb.append('Current line: ' + repr(vim.current.line))
+ ws = list(vim.windows)
+ ts = list(vim.tabpages)
  for b in vim.buffers:
      if b is not cb:
          vim.command('bwipeout! ' + str(b.number))
+ cb.append('w.valid: ' + repr([w.valid for w in ws]))
+ cb.append('t.valid: ' + repr([t.valid for t in ts]))
  EOF
  :tabonly!
  :only!
diff -cr vim.e6465392bfef/src/testdir/test87.ok vim.a71b70fc1b4e/src/testdir/test87.ok
*** vim.e6465392bfef/src/testdir/test87.ok	2013-05-25 14:58:14.906767352 +0400
--- vim.a71b70fc1b4e/src/testdir/test87.ok	2013-05-25 14:58:14.922759202 +0400
***************
*** 317,322 ****
--- 317,323 ----
  1:BufFilePre:1
  7:BufFilePost:1
  /home/zyx/a.a/Proj/c/vim/src/testdir/test87.in
+ valid: b:False, cb:True
  i:<buffer test87.in>
  i2:<buffer test87.in>
  i:<buffer a>
***************
*** 333,339 ****
  Current tab pages:
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
    Windows:
!     <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (36, 0)
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
    Windows:
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
--- 334,340 ----
  Current tab pages:
    <tabpage 0>(1): 1 windows, current is <window object (unknown)>
    Windows:
!     <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (37, 0)
    <tabpage 1>(2): 1 windows, current is <window object (unknown)>
    Windows:
      <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
***************
*** 359,364 ****
--- 360,367 ----
  Current window: <window 0>
  Current buffer: <buffer test87.in>
  Current line: 'Type error at assigning None to vim.current.buffer'
+ w.valid: [True, False]
+ t.valid: [True, False, True, False]
  vim.vars:Dictionary:True
  vim.options:Options:True
  vim.bindeval("{}"):Dictionary:True

Raspunde prin e-mail lui