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

[PATCH] (1/2) Add window.tabpage, make window.number work with non-current tab pages

Expand Messages
  • ZyX
    # HG changeset patch # User ZyX # Date 1368673074 -14400 # Branch python-extended-2 # Node ID 02c4f613343a69eeba16a8a4742f5a9dee269861 # Parent
    Message 1 of 3 , May 15, 2013
    • 0 Attachment
      # HG changeset patch
      # User ZyX <kp-pav@...>
      # Date 1368673074 -14400
      # Branch python-extended-2
      # Node ID 02c4f613343a69eeba16a8a4742f5a9dee269861
      # Parent 9ea73172864c892283abb0735b427cba5485820c
      Record tabpage in window

      Needed to report correct window.number for non-current-tabpage windows

      For backwards compatibility repr() result does not change.

      diff -r 9ea73172864c -r 02c4f613343a runtime/doc/if_pyth.txt
      --- a/runtime/doc/if_pyth.txt Thu May 16 05:49:26 2013 +0400
      +++ b/runtime/doc/if_pyth.txt Thu May 16 06:57:54 2013 +0400
      @@ -433,8 +433,9 @@
      This is zero in case it cannot be determined
      (e.g. when the window object belongs to other
      tab page).
      - row, col (read-only) On-screen window position in display cells.
      + row, col (read-only) On-screen window position in display cells.
      First position is zero.
      + tabpage (read-only) Window tab page.

      The height attribute is writable only if the screen is split horizontally.
      The width attribute is writable only if the screen is split vertically.
      diff -r 9ea73172864c -r 02c4f613343a src/if_py_both.h
      --- a/src/if_py_both.h Thu May 16 05:49:26 2013 +0400
      +++ b/src/if_py_both.h Thu May 16 06:57:54 2013 +0400
      @@ -31,6 +31,9 @@

      static int ConvertFromPyObject(PyObject *, typval_T *);
      static int _ConvertFromPyObject(PyObject *, typval_T *, PyObject *);
      +static PyObject *WindowNew(win_T *, tabpage_T *);
      +static PyObject *BufferNew (buf_T *);
      +static PyObject *LineToString(const char *);

      static PyInt RangeStart;
      static PyInt RangeEnd;
      @@ -1670,9 +1673,9 @@
      /* For current tab window.c does not bother to set or update tp_curwin
      */
      if (this->tab == curtab)
      - return WindowNew(curwin);
      + return WindowNew(curwin, curtab);
      else
      - return WindowNew(this->tab->tp_curwin);
      + return WindowNew(this->tab->tp_curwin, this->tab);
      }
      return NULL;
      }
      @@ -1754,6 +1757,7 @@
      {
      PyObject_HEAD
      win_T *win;
      + TabPageObject *tabObject;
      } WindowObject;

      static PyTypeObject WindowType;
      @@ -1771,7 +1775,7 @@
      }

      static PyObject *
      -WindowNew(win_T *win)
      +WindowNew(win_T *win, tabpage_T *tab)
      {
      /* We need to handle deletion of windows underneath us.
      * If we add a "w_python*_ref" field to the win_T structure,
      @@ -1804,6 +1808,8 @@
      WIN_PYTHON_REF(win) = self;
      }

      + self->tabObject = ((TabPageObject *)(TabPageNew(tab)));
      +
      return (PyObject *)(self);
      }

      @@ -1815,9 +1821,29 @@
      if (this->win && this->win != INVALID_WINDOW_VALUE)
      WIN_PYTHON_REF(this->win) = NULL;

      + Py_DECREF(((PyObject *)(this->tabObject)));
      +
      DESTRUCTOR_FINISH(self);
      }

      + static win_T *
      +get_firstwin(TabPageObject *tabObject)
      +{
      + if (tabObject)
      + {
      + if (CheckTabPage(tabObject))
      + return NULL;
      + /* For current tab window.c does not bother to set or update tp_firstwin
      + */
      + else if (tabObject->tab == curtab)
      + return firstwin;
      + else
      + return tabObject->tab->tp_firstwin;
      + }
      + else
      + return firstwin;
      +}
      +
      static PyObject *
      WindowAttr(WindowObject *this, char *name)
      {
      @@ -1847,10 +1873,20 @@
      return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
      (PyObject *) this);
      else if (strcmp(name, "number") == 0)
      - return PyLong_FromLong((long) get_win_number(this->win, firstwin));
      + {
      + if (CheckTabPage(this->tabObject))
      + return NULL;
      + return PyLong_FromLong((long)
      + get_win_number(this->win, get_firstwin(this->tabObject)));
      + }
      + else if (strcmp(name, "tabpage") == 0)
      + {
      + Py_INCREF(this->tabObject);
      + return (PyObject *)(this->tabObject);
      + }
      else if (strcmp(name,"__members__") == 0)
      - return Py_BuildValue("[ssssssss]", "buffer", "cursor", "height", "vars",
      - "options", "number", "row", "col");
      + return Py_BuildValue("[sssssssss]", "buffer", "cursor", "height",
      + "vars", "options", "number", "row", "col", "tabpage");
      else
      return NULL;
      }
      @@ -2016,31 +2052,13 @@
      DESTRUCTOR_FINISH(self);
      }

      - static win_T *
      -get_firstwin(WinListObject *this)
      -{
      - if (this->tabObject)
      - {
      - if (CheckTabPage(this->tabObject))
      - return NULL;
      - /* For current tab window.c does not bother to set or update tp_firstwin
      - */
      - else if (this->tabObject->tab == curtab)
      - return firstwin;
      - else
      - return this->tabObject->tab->tp_firstwin;
      - }
      - else
      - return firstwin;
      -}
      -
      static PyInt
      WinListLength(PyObject *self)
      {
      win_T *w;
      PyInt n = 0;

      - if (!(w = get_firstwin((WinListObject *)(self))))
      + if (!(w = get_firstwin(((WinListObject *)(self))->tabObject)))
      return -1;

      while (w != NULL)
      @@ -2055,14 +2073,15 @@
      static PyObject *
      WinListItem(PyObject *self, PyInt n)
      {
      + WinListObject *this = ((WinListObject *)(self));
      win_T *w;

      - if (!(w = get_firstwin((WinListObject *)(self))))
      + if (!(w = get_firstwin(this->tabObject)))
      return NULL;

      for (; w != NULL; w = W_NEXT(w), --n)
      if (n == 0)
      - return WindowNew(w);
      + return WindowNew(w, this->tabObject? this->tabObject->tab: curtab);

      PyErr_SetString(PyExc_IndexError, _("no such window"));
      return NULL;
      @@ -3231,7 +3250,7 @@
      if (strcmp(name, "buffer") == 0)
      return (PyObject *)BufferNew(curbuf);
      else if (strcmp(name, "window") == 0)
      - return (PyObject *)WindowNew(curwin);
      + return (PyObject *)WindowNew(curwin, curtab);
      else if (strcmp(name, "tabpage") == 0)
      return (PyObject *)TabPageNew(curtab);
      else if (strcmp(name, "line") == 0)
      diff -r 9ea73172864c -r 02c4f613343a src/if_python.c
      --- a/src/if_python.c Thu May 16 05:49:26 2013 +0400
      +++ b/src/if_python.c Thu May 16 06:57:54 2013 +0400
      @@ -610,11 +610,6 @@
      }
      #endif /* DYNAMIC_PYTHON */

      -static PyObject *BufferNew (buf_T *);
      -static PyObject *WindowNew(win_T *);
      -static PyObject *DictionaryNew(dict_T *);
      -static PyObject *LineToString(const char *);
      -
      static int initialised = 0;
      #define PYINITIALISED initialised

      diff -r 9ea73172864c -r 02c4f613343a src/if_python3.c
      --- a/src/if_python3.c Thu May 16 05:49:26 2013 +0400
      +++ b/src/if_python3.c Thu May 16 06:57:54 2013 +0400
      @@ -611,9 +611,6 @@
      }
      #endif /* DYNAMIC_PYTHON3 */

      -static PyObject *BufferNew (buf_T *);
      -static PyObject *WindowNew(win_T *);
      -static PyObject *LineToString(const char *);
      static PyObject *BufferDir(PyObject *, PyObject *);

      static int py3initialised = 0;
      diff -r 9ea73172864c -r 02c4f613343a src/testdir/test86.ok
      --- a/src/testdir/test86.ok Thu May 16 05:49:26 2013 +0400
      +++ b/src/testdir/test86.ok Thu May 16 06:57:54 2013 +0400
      @@ -333,14 +333,14 @@
      Current tab pages:
      <tabpage 0>(1): 1 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer test86.in>; cursor is at (955, 0)
      + <window object (unknown)>(1): displays buffer <buffer test86.in>; cursor is at (955, 0)
      <tabpage 1>(2): 1 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer 0>; cursor is at (1, 0)
      + <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
      <tabpage 2>(3): 2 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer a.1>; cursor is at (1, 0)
      - <window object (unknown)>(0): displays buffer <buffer 1>; cursor is at (1, 0)
      + <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0)
      + <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0)
      <tabpage 3>(4): 4 windows, current is <window 0>
      Windows:
      <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0)
      diff -r 9ea73172864c -r 02c4f613343a src/testdir/test87.ok
      --- a/src/testdir/test87.ok Thu May 16 05:49:26 2013 +0400
      +++ b/src/testdir/test87.ok Thu May 16 06:57:54 2013 +0400
      @@ -322,14 +322,14 @@
      Current tab pages:
      <tabpage 0>(1): 1 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer test87.in>; cursor is at (930, 0)
      + <window object (unknown)>(1): displays buffer <buffer test87.in>; cursor is at (930, 0)
      <tabpage 1>(2): 1 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer 0>; cursor is at (1, 0)
      + <window object (unknown)>(1): displays buffer <buffer 0>; cursor is at (1, 0)
      <tabpage 2>(3): 2 windows, current is <window object (unknown)>
      Windows:
      - <window object (unknown)>(0): displays buffer <buffer a.1>; cursor is at (1, 0)
      - <window object (unknown)>(0): displays buffer <buffer 1>; cursor is at (1, 0)
      + <window object (unknown)>(1): displays buffer <buffer a.1>; cursor is at (1, 0)
      + <window object (unknown)>(2): displays buffer <buffer 1>; cursor is at (1, 0)
      <tabpage 3>(4): 4 windows, current is <window 0>
      Windows:
      <window 0>(1): displays buffer <buffer c.2>; cursor is at (1, 0)

      --
      --
      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.
    • ZyX
      # HG changeset patch # User ZyX # Date 1368672552 -14400 # Branch python-extended-2 # Node ID 5f8adb1d88b905d73dc2b4d106740759a66113b3 # Parent
      Message 2 of 3 , May 15, 2013
      • 0 Attachment
        # HG changeset patch
        # User ZyX <kp-pav@...>
        # Date 1368672552 -14400
        # Branch python-extended-2
        # Node ID 5f8adb1d88b905d73dc2b4d106740759a66113b3
        # Parent 02c4f613343a69eeba16a8a4742f5a9dee269861
        Add tp_traverse and tp_clear

        diff -r 02c4f613343a -r 5f8adb1d88b9 src/if_py_both.h
        --- a/src/if_py_both.h Thu May 16 06:57:54 2013 +0400
        +++ b/src/if_py_both.h Thu May 16 06:49:12 2013 +0400
        @@ -543,6 +543,8 @@

        typedef PyObject *(*nextfun)(void **);
        typedef void (*destructorfun)(void *);
        +typedef int (*traversefun)(void *, visitproc, void *);
        +typedef int (*clearfun)(void **);

        /* Main purpose of this object is removing the need for do python initialization
        * (i.e. PyType_Ready and setting type attributes) for a big bunch of objects.
        @@ -554,10 +556,13 @@
        void *cur;
        nextfun next;
        destructorfun destruct;
        + traversefun traverse;
        + clearfun clear;
        } IterObject;

        static PyObject *
        -IterNew(void *start, destructorfun destruct, nextfun next)
        +IterNew(void *start, destructorfun destruct, nextfun next, traversefun traverse,
        + clearfun clear)
        {
        IterObject *self;

        @@ -565,6 +570,8 @@
        self->cur = start;
        self->next = next;
        self->destruct = destruct;
        + self->traverse = traverse;
        + self->clear = clear;

        return (PyObject *)(self);
        }
        @@ -579,6 +586,28 @@
        DESTRUCTOR_FINISH(self);
        }

        + static int
        +IterTraverse(PyObject *self, visitproc visit, void *arg)
        +{
        + IterObject *this = (IterObject *)(self);
        +
        + if (this->traverse != NULL)
        + return this->traverse(this->cur, visit, arg);
        + else
        + return 0;
        +}
        +
        + static int
        +IterClear(PyObject *self)
        +{
        + IterObject *this = (IterObject *)(self);
        +
        + if (this->clear != NULL)
        + return this->clear(&this->cur);
        + else
        + return 0;
        +}
        +
        static PyObject *
        IterNext(PyObject *self)
        {
        @@ -1034,7 +1063,8 @@
        lii->list = l;

        return IterNew(lii,
        - (destructorfun) ListIterDestruct, (nextfun) ListIterNext);
        + (destructorfun) ListIterDestruct, (nextfun) ListIterNext,
        + NULL, NULL);
        }

        static int
        @@ -1348,6 +1378,53 @@
        PyObject *fromObj;
        } OptionsObject;

        + static int
        +dummy_check(void *arg UNUSED)
        +{
        + return 0;
        +}
        +
        + static PyObject *
        +OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
        +{
        + OptionsObject *self;
        +
        + self = PyObject_NEW(OptionsObject, &OptionsType);
        + if (self == NULL)
        + return NULL;
        +
        + self->opt_type = opt_type;
        + self->from = from;
        + self->Check = Check;
        + self->fromObj = fromObj;
        + if (fromObj)
        + Py_INCREF(fromObj);
        +
        + return (PyObject *)(self);
        +}
        +
        + static void
        +OptionsDestructor(PyObject *self)
        +{
        + if (((OptionsObject *)(self))->fromObj)
        + Py_DECREF(((OptionsObject *)(self))->fromObj);
        + DESTRUCTOR_FINISH(self);
        +}
        +
        + static int
        +OptionsTraverse(PyObject *self, visitproc visit, void *arg)
        +{
        + Py_VISIT(((OptionsObject *)(self))->fromObj);
        + return 0;
        +}
        +
        + static int
        +OptionsClear(PyObject *self)
        +{
        + Py_CLEAR(((OptionsObject *)(self))->fromObj);
        + return 0;
        +}
        +
        static PyObject *
        OptionsItem(OptionsObject *this, PyObject *keyObject)
        {
        @@ -1562,39 +1639,6 @@
        return r;
        }

        - static int
        -dummy_check(void *arg UNUSED)
        -{
        - return 0;
        -}
        -
        - static PyObject *
        -OptionsNew(int opt_type, void *from, checkfun Check, PyObject *fromObj)
        -{
        - OptionsObject *self;
        -
        - self = PyObject_NEW(OptionsObject, &OptionsType);
        - if (self == NULL)
        - return NULL;
        -
        - self->opt_type = opt_type;
        - self->from = from;
        - self->Check = Check;
        - self->fromObj = fromObj;
        - if (fromObj)
        - Py_INCREF(fromObj);
        -
        - return (PyObject *)(self);
        -}
        -
        - static void
        -OptionsDestructor(PyObject *self)
        -{
        - if (((OptionsObject *)(self))->fromObj)
        - Py_DECREF(((OptionsObject *)(self))->fromObj);
        - DESTRUCTOR_FINISH(self);
        -}
        -
        static PyMappingMethods OptionsAsMapping = {
        (lenfunc) NULL,
        (binaryfunc) OptionsItem,
        @@ -1843,6 +1887,19 @@
        else
        return firstwin;
        }
        + static int
        +WindowTraverse(PyObject *self, visitproc visit, void *arg)
        +{
        + Py_VISIT(((PyObject *)(((WindowObject *)(self))->tabObject)));
        + return 0;
        +}
        +
        + static int
        +WindowClear(PyObject *self)
        +{
        + Py_CLEAR((((WindowObject *)(self))->tabObject));
        + return 0;
        +}

        static PyObject *
        WindowAttr(WindowObject *this, char *name)
        @@ -3197,6 +3254,20 @@
        }
        }

        + static int
        +BufMapIterTraverse(PyObject *buffer, visitproc visit, void *arg)
        +{
        + Py_VISIT(buffer);
        + return 0;
        +}
        +
        + static int
        +BufMapIterClear(PyObject **buffer)
        +{
        + Py_CLEAR(*buffer);
        + return 0;
        +}
        +
        static PyObject *
        BufMapIterNext(PyObject **buffer)
        {
        @@ -3232,7 +3303,8 @@

        buffer = BufferNew(firstbuf);
        return IterNew(buffer,
        - (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext);
        + (destructorfun) BufMapIterDestruct, (nextfun) BufMapIterNext,
        + (traversefun) BufMapIterTraverse, (clearfun) BufMapIterClear);
        }

        static PyMappingMethods BufMapAsMapping = {
        @@ -3841,6 +3913,8 @@
        IterType.tp_iter = IterIter;
        IterType.tp_iternext = IterNext;
        IterType.tp_dealloc = IterDestructor;
        + IterType.tp_traverse = IterTraverse;
        + IterType.tp_clear = IterClear;

        vim_memset(&BufferType, 0, sizeof(BufferType));
        BufferType.tp_name = "vim.buffer";
        @@ -3869,6 +3943,8 @@
        WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
        WindowType.tp_doc = "vim Window object";
        WindowType.tp_methods = WindowMethods;
        + WindowType.tp_traverse = WindowTraverse;
        + WindowType.tp_clear = WindowClear;
        #if PY_MAJOR_VERSION >= 3
        WindowType.tp_getattro = WindowGetattro;
        WindowType.tp_setattro = WindowSetattro;
        @@ -4007,6 +4083,8 @@
        OptionsType.tp_doc = "object for manipulating options";
        OptionsType.tp_as_mapping = &OptionsAsMapping;
        OptionsType.tp_dealloc = OptionsDestructor;
        + OptionsType.tp_traverse = OptionsTraverse;
        + OptionsType.tp_clear = OptionsClear;

        #if PY_MAJOR_VERSION >= 3
        vim_memset(&vimmodule, 0, sizeof(vimmodule));

        --
        --
        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.
      • Bram Moolenaar
        ... Thanks. I ll include it soon. ... I wonder if we can help the developer by giving more information about the type of the element, in a consistent way.
        Message 3 of 3 , May 16, 2013
        • 0 Attachment
          ZyX wrote:

          > # HG changeset patch
          > # User ZyX <kp-pav@...>
          > # Date 1368673074 -14400
          > # Branch python-extended-2
          > # Node ID 02c4f613343a69eeba16a8a4742f5a9dee269861
          > # Parent 9ea73172864c892283abb0735b427cba5485820c
          > Record tabpage in window
          >
          > Needed to report correct window.number for non-current-tabpage windows
          >
          > For backwards compatibility repr() result does not change.

          Thanks. I'll include it soon.

          > diff -r 9ea73172864c -r 02c4f613343a runtime/doc/if_pyth.txt
          > --- a/runtime/doc/if_pyth.txt Thu May 16 05:49:26 2013 +0400
          > +++ b/runtime/doc/if_pyth.txt Thu May 16 06:57:54 2013 +0400
          > @@ -433,8 +433,9 @@
          > This is zero in case it cannot be determined
          > (e.g. when the window object belongs to other
          > tab page).
          > - row, col (read-only) On-screen window position in display cells.
          > + row, col (read-only) On-screen window position in display cells.
          > First position is zero.
          > + tabpage (read-only) Window tab page.

          I wonder if we can help the developer by giving more information about
          the type of the element, in a consistent way. What you have here is an
          object, right? Not a tabpage number.


          --
          Life is a gift, living is an art. (Bram Moolenaar)

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