Loading ...
Sorry, an error occurred while loading the content.
 

Patch 7.3.945

Expand Messages
  • Bram Moolenaar
    Patch 7.3.945 Problem: Python: List of buffers is not very useful. Solution: Make vim.buffers a map. No iterator yet. (ZyX) Files:
    Message 1 of 1 , May 15 4:39 AM
      Patch 7.3.945
      Problem: Python: List of buffers is not very useful.
      Solution: Make vim.buffers a map. No iterator yet. (ZyX)
      Files: runtime/doc/if_pyth.txt, src/if_py_both.h, src/if_python3.c,
      src/if_python.c, src/testdir/test86.ok, src/testdir/test87.ok


      *** ../vim-7.3.944/runtime/doc/if_pyth.txt 2013-05-12 19:30:27.000000000 +0200
      --- runtime/doc/if_pyth.txt 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 209,220 ****
      to which the variables referred.

      vim.buffers *python-buffers*
      ! A sequence object providing access to the list of vim buffers. The
      object supports the following operations: >
      :py b = vim.buffers[i] # Indexing (read-only)
      :py b in vim.buffers # Membership test
      :py n = len(vim.buffers) # Number of elements
      - :py for b in vim.buffers: # Sequential access
      <
      vim.windows *python-windows*
      A sequence object providing access to the list of vim windows. The
      --- 209,219 ----
      to which the variables referred.

      vim.buffers *python-buffers*
      ! A mapping object providing access to the list of vim buffers. The
      object supports the following operations: >
      :py b = vim.buffers[i] # Indexing (read-only)
      :py b in vim.buffers # Membership test
      :py n = len(vim.buffers) # Number of elements
      <
      vim.windows *python-windows*
      A sequence object providing access to the list of vim windows. The
      *** ../vim-7.3.944/src/if_py_both.h 2013-05-12 21:16:17.000000000 +0200
      --- src/if_py_both.h 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 534,549 ****
      * Buffer list object - Implementation
      */

      ! static PyTypeObject BufListType;
      ! static PySequenceMethods BufListAsSeq;

      typedef struct
      {
      PyObject_HEAD
      ! } BufListObject;

      static PyInt
      ! BufListLength(PyObject *self UNUSED)
      {
      buf_T *b = firstbuf;
      PyInt n = 0;
      --- 534,548 ----
      * Buffer list object - Implementation
      */

      ! static PyTypeObject BufMapType;

      typedef struct
      {
      PyObject_HEAD
      ! } BufMapObject;

      static PyInt
      ! BufMapLength(PyObject *self UNUSED)
      {
      buf_T *b = firstbuf;
      PyInt n = 0;
      ***************
      *** 558,577 ****
      }

      static PyObject *
      ! BufListItem(PyObject *self UNUSED, PyInt n)
      {
      ! buf_T *b;

      ! for (b = firstbuf; b; b = b->b_next, --n)
      {
      ! if (n == 0)
      ! return BufferNew(b);
      }

      ! PyErr_SetString(PyExc_IndexError, _("no such buffer"));
      ! return NULL;
      }

      typedef struct pylinkedlist_S {
      struct pylinkedlist_S *pll_next;
      struct pylinkedlist_S *pll_prev;
      --- 557,597 ----
      }

      static PyObject *
      ! BufMapItem(PyObject *self UNUSED, PyObject *keyObject)
      {
      ! buf_T *b;
      ! int bnr;

      ! #if PY_MAJOR_VERSION < 3
      ! if (PyInt_Check(keyObject))
      ! bnr = PyInt_AsLong(keyObject);
      ! else
      ! #endif
      ! if (PyLong_Check(keyObject))
      ! bnr = PyLong_AsLong(keyObject);
      ! else
      {
      ! PyErr_SetString(PyExc_ValueError, _("key must be integer"));
      ! return NULL;
      }

      ! b = buflist_findnr(bnr);
      !
      ! if (b)
      ! return BufferNew(b);
      ! else
      ! {
      ! PyErr_SetString(PyExc_KeyError, _("no such buffer"));
      ! return NULL;
      ! }
      }

      + static PyMappingMethods BufMapAsMapping = {
      + (lenfunc) BufMapLength,
      + (binaryfunc) BufMapItem,
      + (objobjargproc) 0,
      + };
      +
      typedef struct pylinkedlist_S {
      struct pylinkedlist_S *pll_next;
      struct pylinkedlist_S *pll_prev;
      ***************
      *** 3401,3411 ****
      WindowType.tp_setattr = WindowSetattr;
      #endif

      ! vim_memset(&BufListType, 0, sizeof(BufListType));
      ! BufListType.tp_name = "vim.bufferlist";
      ! BufListType.tp_basicsize = sizeof(BufListObject);
      ! BufListType.tp_as_sequence = &BufListAsSeq;
      ! BufListType.tp_flags = Py_TPFLAGS_DEFAULT;
      BufferType.tp_doc = "vim buffer list";

      vim_memset(&WinListType, 0, sizeof(WinListType));
      --- 3421,3431 ----
      WindowType.tp_setattr = WindowSetattr;
      #endif

      ! vim_memset(&BufMapType, 0, sizeof(BufMapType));
      ! BufMapType.tp_name = "vim.bufferlist";
      ! BufMapType.tp_basicsize = sizeof(BufMapObject);
      ! BufMapType.tp_as_mapping = &BufMapAsMapping;
      ! BufMapType.tp_flags = Py_TPFLAGS_DEFAULT;
      BufferType.tp_doc = "vim buffer list";

      vim_memset(&WinListType, 0, sizeof(WinListType));
      *** ../vim-7.3.944/src/if_python3.c 2013-05-12 21:16:17.000000000 +0200
      --- src/if_python3.c 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 1272,1293 ****
      }
      }

      - /* Buffer list object - Definitions
      - */
      -
      - static PySequenceMethods BufListAsSeq = {
      - (lenfunc) BufListLength, /* sq_length, len(x) */
      - (binaryfunc) 0, /* sq_concat, x+y */
      - (ssizeargfunc) 0, /* sq_repeat, x*n */
      - (ssizeargfunc) BufListItem, /* sq_item, x[i] */
      - 0, /* was_sq_slice, x[i:j] */
      - (ssizeobjargproc) 0, /* sq_as_item, x[i]=v */
      - 0, /* sq_ass_slice, x[i:j]=v */
      - 0, /* sq_contains */
      - 0, /* sq_inplace_concat */
      - 0, /* sq_inplace_repeat */
      - };
      -
      /* Window object - Implementation
      */

      --- 1272,1277 ----
      ***************
      *** 1512,1520 ****
      }
      #endif

      ! static BufListObject TheBufferList =
      {
      ! PyObject_HEAD_INIT(&BufListType)
      };

      static WinListObject TheWindowList =
      --- 1496,1504 ----
      }
      #endif

      ! static BufMapObject TheBufferMap =
      {
      ! PyObject_HEAD_INIT(&BufMapType)
      };

      static WinListObject TheWindowList =
      ***************
      *** 1538,1544 ****
      PyType_Ready(&BufferType);
      PyType_Ready(&RangeType);
      PyType_Ready(&WindowType);
      ! PyType_Ready(&BufListType);
      PyType_Ready(&WinListType);
      PyType_Ready(&CurrentType);
      PyType_Ready(&DictionaryType);
      --- 1522,1528 ----
      PyType_Ready(&BufferType);
      PyType_Ready(&RangeType);
      PyType_Ready(&WindowType);
      ! PyType_Ready(&BufMapType);
      PyType_Ready(&WinListType);
      PyType_Ready(&CurrentType);
      PyType_Ready(&DictionaryType);
      ***************
      *** 1557,1564 ****
      Py_INCREF(VimError);

      PyModule_AddObject(mod, "error", VimError);
      ! Py_INCREF((PyObject *)(void *)&TheBufferList);
      ! PyModule_AddObject(mod, "buffers", (PyObject *)(void *)&TheBufferList);
      Py_INCREF((PyObject *)(void *)&TheCurrent);
      PyModule_AddObject(mod, "current", (PyObject *)(void *)&TheCurrent);
      Py_INCREF((PyObject *)(void *)&TheWindowList);
      --- 1541,1548 ----
      Py_INCREF(VimError);

      PyModule_AddObject(mod, "error", VimError);
      ! Py_INCREF((PyObject *)(void *)&TheBufferMap);
      ! PyModule_AddObject(mod, "buffers", (PyObject *)(void *)&TheBufferMap);
      Py_INCREF((PyObject *)(void *)&TheCurrent);
      PyModule_AddObject(mod, "current", (PyObject *)(void *)&TheCurrent);
      Py_INCREF((PyObject *)(void *)&TheWindowList);
      *** ../vim-7.3.944/src/if_python.c 2013-05-12 20:36:09.000000000 +0200
      --- src/if_python.c 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 1131,1154 ****
      &((RangeObject *)(self))->end);
      }

      - /* Buffer list object - Definitions
      - */
      -
      - static PySequenceMethods BufListAsSeq = {
      - (PyInquiry) BufListLength, /* sq_length, len(x) */
      - (binaryfunc) 0, /* sq_concat, x+y */
      - (PyIntArgFunc) 0, /* sq_repeat, x*n */
      - (PyIntArgFunc) BufListItem, /* sq_item, x[i] */
      - (PyIntIntArgFunc) 0, /* sq_slice, x[i:j] */
      - (PyIntObjArgProc) 0, /* sq_ass_item, x[i]=v */
      - (PyIntIntObjArgProc) 0, /* sq_ass_slice, x[i:j]=v */
      - (objobjproc) 0,
      - #if PY_MAJOR_VERSION >= 2
      - (binaryfunc) 0,
      - 0,
      - #endif
      - };
      -
      /* Window object - Implementation
      */

      --- 1131,1136 ----
      ***************
      *** 1212,1220 ****
      }
      #endif

      ! static BufListObject TheBufferList =
      {
      ! PyObject_HEAD_INIT(&BufListType)
      };

      static WinListObject TheWindowList =
      --- 1194,1202 ----
      }
      #endif

      ! static BufMapObject TheBufferMap =
      {
      ! PyObject_HEAD_INIT(&BufMapType)
      };

      static WinListObject TheWindowList =
      ***************
      *** 1240,1246 ****
      PyType_Ready(&BufferType);
      PyType_Ready(&RangeType);
      PyType_Ready(&WindowType);
      ! PyType_Ready(&BufListType);
      PyType_Ready(&WinListType);
      PyType_Ready(&CurrentType);
      PyType_Ready(&OptionsType);
      --- 1222,1228 ----
      PyType_Ready(&BufferType);
      PyType_Ready(&RangeType);
      PyType_Ready(&WindowType);
      ! PyType_Ready(&BufMapType);
      PyType_Ready(&WinListType);
      PyType_Ready(&CurrentType);
      PyType_Ready(&OptionsType);
      ***************
      *** 1254,1260 ****
      VimError = Py_BuildValue("s", "vim.error");

      PyDict_SetItemString(dict, "error", VimError);
      ! PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferList);
      PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent);
      PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList);
      tmp = DictionaryNew(&globvardict);
      --- 1236,1242 ----
      VimError = Py_BuildValue("s", "vim.error");

      PyDict_SetItemString(dict, "error", VimError);
      ! PyDict_SetItemString(dict, "buffers", (PyObject *)(void *)&TheBufferMap);
      PyDict_SetItemString(dict, "current", (PyObject *)(void *)&TheCurrent);
      PyDict_SetItemString(dict, "windows", (PyObject *)(void *)&TheWindowList);
      tmp = DictionaryNew(&globvardict);
      *** ../vim-7.3.944/src/testdir/test86.ok 2013-05-12 21:16:17.000000000 +0200
      --- src/testdir/test86.ok 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 226,238 ****
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      >>> iminsert
      p/gopts1! KeyError
      inv: 3! KeyError
      --- 226,238 ----
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      >>> iminsert
      p/gopts1! KeyError
      inv: 3! KeyError
      ***************
      *** 244,256 ****
      wopts3! KeyError
      p/bopts1: 2
      G: 1
      ! W: 1:2 2:1 3:0 4:2
      ! B: 1:2 2:1 3:0 4:2
      del wopts3! KeyError
      del bopts3! ValueError
      G: 1
      ! W: 1:2 2:1 3:0 4:2
      ! B: 1:2 2:1 3:0 4:2
      >>> omnifunc
      p/gopts1! KeyError
      inv: 1! KeyError
      --- 244,256 ----
      wopts3! KeyError
      p/bopts1: 2
      G: 1
      ! W: 1:0 2:2 3:2 4:1
      ! B: 1:0 2:2 3:2 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 1
      ! W: 1:0 2:2 3:2 4:1
      ! B: 1:0 2:2 3:2 4:1
      >>> omnifunc
      p/gopts1! KeyError
      inv: 1! KeyError
      ***************
      *** 263,275 ****
      p/bopts1: ''
      inv: 1! ValueError
      G: ''
      ! W: 1:'B' 2:'C' 3:'A' 4:''
      ! B: 1:'B' 2:'C' 3:'A' 4:''
      del wopts3! KeyError
      del bopts3! ValueError
      G: ''
      ! W: 1:'B' 2:'C' 3:'A' 4:''
      ! B: 1:'B' 2:'C' 3:'A' 4:''
      >>> preserveindent
      p/gopts1! KeyError
      inv: 2! KeyError
      --- 263,275 ----
      p/bopts1: ''
      inv: 1! ValueError
      G: ''
      ! W: 1:'A' 2:'B' 3:'' 4:'C'
      ! B: 1:'A' 2:'B' 3:'' 4:'C'
      del wopts3! KeyError
      del bopts3! ValueError
      G: ''
      ! W: 1:'A' 2:'B' 3:'' 4:'C'
      ! B: 1:'A' 2:'B' 3:'' 4:'C'
      >>> preserveindent
      p/gopts1! KeyError
      inv: 2! KeyError
      ***************
      *** 282,294 ****
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      >>> path
      p/gopts1: '.,/usr/include,,'
      inv: 0! ValueError
      --- 282,294 ----
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      >>> path
      p/gopts1: '.,/usr/include,,'
      inv: 0! ValueError
      ***************
      *** 300,311 ****
      p/bopts1: None
      inv: 0! ValueError
      G: '.,,'
      ! W: 1:',,' 2:'.' 3:'.,,' 4:'.,,'
      ! B: 1:',,' 2:'.' 3:'.,,' 4:'.,,'
      del wopts3! KeyError
      G: '.,,'
      ! W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
      ! B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
      First line
      First line
      def
      --- 300,311 ----
      p/bopts1: None
      inv: 0! ValueError
      G: '.,,'
      ! W: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
      ! B: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
      del wopts3! KeyError
      G: '.,,'
      ! W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
      ! B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
      First line
      First line
      def
      *** ../vim-7.3.944/src/testdir/test87.ok 2013-05-12 21:16:17.000000000 +0200
      --- src/testdir/test87.ok 2013-05-15 13:34:06.000000000 +0200
      ***************
      *** 215,227 ****
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      >>> iminsert
      p/gopts1! KeyError
      inv: 3! KeyError
      --- 215,227 ----
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      >>> iminsert
      p/gopts1! KeyError
      inv: 3! KeyError
      ***************
      *** 233,245 ****
      wopts3! KeyError
      p/bopts1: 2
      G: 1
      ! W: 1:2 2:1 3:0 4:2
      ! B: 1:2 2:1 3:0 4:2
      del wopts3! KeyError
      del bopts3! ValueError
      G: 1
      ! W: 1:2 2:1 3:0 4:2
      ! B: 1:2 2:1 3:0 4:2
      >>> omnifunc
      p/gopts1! KeyError
      inv: 1! KeyError
      --- 233,245 ----
      wopts3! KeyError
      p/bopts1: 2
      G: 1
      ! W: 1:0 2:2 3:2 4:1
      ! B: 1:0 2:2 3:2 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 1
      ! W: 1:0 2:2 3:2 4:1
      ! B: 1:0 2:2 3:2 4:1
      >>> omnifunc
      p/gopts1! KeyError
      inv: 1! KeyError
      ***************
      *** 252,264 ****
      p/bopts1: b''
      inv: 1! ValueError
      G: ''
      ! W: 1:'B' 2:'C' 3:'A' 4:''
      ! B: 1:'B' 2:'C' 3:'A' 4:''
      del wopts3! KeyError
      del bopts3! ValueError
      G: ''
      ! W: 1:'B' 2:'C' 3:'A' 4:''
      ! B: 1:'B' 2:'C' 3:'A' 4:''
      >>> preserveindent
      p/gopts1! KeyError
      inv: 2! KeyError
      --- 252,264 ----
      p/bopts1: b''
      inv: 1! ValueError
      G: ''
      ! W: 1:'A' 2:'B' 3:'' 4:'C'
      ! B: 1:'A' 2:'B' 3:'' 4:'C'
      del wopts3! KeyError
      del bopts3! ValueError
      G: ''
      ! W: 1:'A' 2:'B' 3:'' 4:'C'
      ! B: 1:'A' 2:'B' 3:'' 4:'C'
      >>> preserveindent
      p/gopts1! KeyError
      inv: 2! KeyError
      ***************
      *** 271,283 ****
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:1 2:1 3:0 4:0
      ! B: 1:1 2:1 3:0 4:0
      >>> path
      p/gopts1: b'.,/usr/include,,'
      inv: 0! ValueError
      --- 271,283 ----
      p/bopts1: False
      inv: 2! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      del wopts3! KeyError
      del bopts3! ValueError
      G: 0
      ! W: 1:0 2:1 3:0 4:1
      ! B: 1:0 2:1 3:0 4:1
      >>> path
      p/gopts1: b'.,/usr/include,,'
      inv: 0! ValueError
      ***************
      *** 289,300 ****
      p/bopts1: None
      inv: 0! ValueError
      G: '.,,'
      ! W: 1:',,' 2:'.' 3:'.,,' 4:'.,,'
      ! B: 1:',,' 2:'.' 3:'.,,' 4:'.,,'
      del wopts3! KeyError
      G: '.,,'
      ! W: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
      ! B: 1:',,' 2:'.,,' 3:'.,,' 4:'.,,'
      First line
      First line
      def
      --- 289,300 ----
      p/bopts1: None
      inv: 0! ValueError
      G: '.,,'
      ! W: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
      ! B: 1:'.,,' 2:',,' 3:'.,,' 4:'.'
      del wopts3! KeyError
      G: '.,,'
      ! W: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
      ! B: 1:'.,,' 2:',,' 3:'.,,' 4:'.,,'
      First line
      First line
      def
      *** ../vim-7.3.944/src/version.c 2013-05-13 20:26:47.000000000 +0200
      --- src/version.c 2013-05-15 13:37:08.000000000 +0200
      ***************
      *** 730,731 ****
      --- 730,733 ----
      { /* Add new patch number below this line */
      + /**/
      + 945,
      /**/

      --
      ARTHUR: A scratch? Your arm's off!
      BLACK KNIGHT: No, it isn't.
      ARTHUR: Well, what's that then?
      BLACK KNIGHT: I've had worse.
      The Quest for the Holy Grail (Monty Python)

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ an exciting new programming language -- http://www.Zimbu.org ///
      \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

      --
      --
      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 vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    Your message has been successfully submitted and would be delivered to recipients shortly.