Karsten Hopp 6f24d0
To: vim_dev@googlegroups.com
Karsten Hopp 6f24d0
Subject: Patch 7.3.938
Karsten Hopp 6f24d0
Fcc: outbox
Karsten Hopp 6f24d0
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 6f24d0
Mime-Version: 1.0
Karsten Hopp 6f24d0
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 6f24d0
Content-Transfer-Encoding: 8bit
Karsten Hopp 6f24d0
------------
Karsten Hopp 6f24d0
Karsten Hopp 6f24d0
Patch 7.3.938
Karsten Hopp 6f24d0
Problem:    Python: not easy to get to window number.
Karsten Hopp 6f24d0
Solution:   Add vim.window.number. (ZyX)
Karsten Hopp 6f24d0
Files:	    runtime/doc/if_pyth.txt, src/if_py_both.h, src/proto/window.pro,
Karsten Hopp 6f24d0
	    src/window.c
Karsten Hopp 6f24d0
Karsten Hopp 6f24d0
Karsten Hopp 6f24d0
*** ../vim-7.3.937/runtime/doc/if_pyth.txt	2013-05-06 03:52:44.000000000 +0200
Karsten Hopp 6f24d0
--- runtime/doc/if_pyth.txt	2013-05-12 18:55:41.000000000 +0200
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 396,401 ****
Karsten Hopp 6f24d0
--- 396,405 ----
Karsten Hopp 6f24d0
  				|python-options|. If option is |global-local| 
Karsten Hopp 6f24d0
  				and local value is missing getting it will 
Karsten Hopp 6f24d0
  				return None.
Karsten Hopp 6f24d0
+ 	number (read-only)	Window number.  The first window has number 1.
Karsten Hopp 6f24d0
+ 				This is zero in case it cannot be determined
Karsten Hopp 6f24d0
+ 				(e.g. when the window object belongs to other
Karsten Hopp 6f24d0
+ 				tab page).
Karsten Hopp 6f24d0
  The height attribute is writable only if the screen is split horizontally.
Karsten Hopp 6f24d0
  The width attribute is writable only if the screen is split vertically.
Karsten Hopp 6f24d0
  
Karsten Hopp 6f24d0
*** ../vim-7.3.937/src/if_py_both.h	2013-05-12 18:44:44.000000000 +0200
Karsten Hopp 6f24d0
--- src/if_py_both.h	2013-05-12 18:48:07.000000000 +0200
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 1848,1856 ****
Karsten Hopp 6f24d0
      else if (strcmp(name, "options") == 0)
Karsten Hopp 6f24d0
  	return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
Karsten Hopp 6f24d0
  			(PyObject *) this);
Karsten Hopp 6f24d0
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp 6f24d0
  	return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
Karsten Hopp 6f24d0
! 		"options");
Karsten Hopp 6f24d0
      else
Karsten Hopp 6f24d0
  	return NULL;
Karsten Hopp 6f24d0
  }
Karsten Hopp 6f24d0
--- 1848,1858 ----
Karsten Hopp 6f24d0
      else if (strcmp(name, "options") == 0)
Karsten Hopp 6f24d0
  	return OptionsNew(SREQ_WIN, this->win, (checkfun) CheckWindow,
Karsten Hopp 6f24d0
  			(PyObject *) this);
Karsten Hopp 6f24d0
+     else if (strcmp(name, "number") == 0)
Karsten Hopp 6f24d0
+ 	return PyLong_FromLong((long) get_win_number(this->win));
Karsten Hopp 6f24d0
      else if (strcmp(name,"__members__") == 0)
Karsten Hopp 6f24d0
  	return Py_BuildValue("[ssssss]", "buffer", "cursor", "height", "vars",
Karsten Hopp 6f24d0
! 		"options", "number");
Karsten Hopp 6f24d0
      else
Karsten Hopp 6f24d0
  	return NULL;
Karsten Hopp 6f24d0
  }
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 1974,1990 ****
Karsten Hopp 6f24d0
      }
Karsten Hopp 6f24d0
      else
Karsten Hopp 6f24d0
      {
Karsten Hopp 6f24d0
! 	int	i = 0;
Karsten Hopp 6f24d0
! 	win_T	*w;
Karsten Hopp 6f24d0
  
Karsten Hopp 6f24d0
! 	for (w = firstwin; w != NULL && w != this->win; w = W_NEXT(w))
Karsten Hopp 6f24d0
! 	    ++i;
Karsten Hopp 6f24d0
! 
Karsten Hopp 6f24d0
! 	if (w == NULL)
Karsten Hopp 6f24d0
  	    vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
Karsten Hopp 6f24d0
  								      (self));
Karsten Hopp 6f24d0
  	else
Karsten Hopp 6f24d0
! 	    vim_snprintf(repr, 100, _("<window %d>"), i);
Karsten Hopp 6f24d0
  
Karsten Hopp 6f24d0
  	return PyString_FromString(repr);
Karsten Hopp 6f24d0
      }
Karsten Hopp 6f24d0
--- 1976,1988 ----
Karsten Hopp 6f24d0
      }
Karsten Hopp 6f24d0
      else
Karsten Hopp 6f24d0
      {
Karsten Hopp 6f24d0
! 	int	w = get_win_number(this->win);
Karsten Hopp 6f24d0
  
Karsten Hopp 6f24d0
! 	if (w == 0)
Karsten Hopp 6f24d0
  	    vim_snprintf(repr, 100, _("<window object (unknown) at %p>"),
Karsten Hopp 6f24d0
  								      (self));
Karsten Hopp 6f24d0
  	else
Karsten Hopp 6f24d0
! 	    vim_snprintf(repr, 100, _("<window %d>"), w - 1);
Karsten Hopp 6f24d0
  
Karsten Hopp 6f24d0
  	return PyString_FromString(repr);
Karsten Hopp 6f24d0
      }
Karsten Hopp 6f24d0
*** ../vim-7.3.937/src/proto/window.pro	2013-05-06 04:50:26.000000000 +0200
Karsten Hopp 6f24d0
--- src/proto/window.pro	2013-05-12 18:48:07.000000000 +0200
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 74,77 ****
Karsten Hopp 6f24d0
--- 74,78 ----
Karsten Hopp 6f24d0
  int match_delete __ARGS((win_T *wp, int id, int perr));
Karsten Hopp 6f24d0
  void clear_matches __ARGS((win_T *wp));
Karsten Hopp 6f24d0
  matchitem_T *get_match __ARGS((win_T *wp, int id));
Karsten Hopp 6f24d0
+ int get_win_number __ARGS((win_T *wp));
Karsten Hopp 6f24d0
  /* vim: set ft=c : */
Karsten Hopp 6f24d0
*** ../vim-7.3.937/src/window.c	2013-05-06 04:50:26.000000000 +0200
Karsten Hopp 6f24d0
--- src/window.c	2013-05-12 18:48:07.000000000 +0200
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 6731,6733 ****
Karsten Hopp 6f24d0
--- 6731,6750 ----
Karsten Hopp 6f24d0
      return cur;
Karsten Hopp 6f24d0
  }
Karsten Hopp 6f24d0
  #endif
Karsten Hopp 6f24d0
+ 
Karsten Hopp 6f24d0
+ #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Karsten Hopp 6f24d0
+     int
Karsten Hopp 6f24d0
+ get_win_number(win_T *wp)
Karsten Hopp 6f24d0
+ {
Karsten Hopp 6f24d0
+     int		i = 1;
Karsten Hopp 6f24d0
+     win_T	*w;
Karsten Hopp 6f24d0
+ 
Karsten Hopp 6f24d0
+     for (w = firstwin; w != NULL && w != wp; w = W_NEXT(w))
Karsten Hopp 6f24d0
+ 	++i;
Karsten Hopp 6f24d0
+ 
Karsten Hopp 6f24d0
+     if (w == NULL)
Karsten Hopp 6f24d0
+ 	return 0;
Karsten Hopp 6f24d0
+     else
Karsten Hopp 6f24d0
+ 	return i;
Karsten Hopp 6f24d0
+ }
Karsten Hopp 6f24d0
+ #endif
Karsten Hopp 6f24d0
*** ../vim-7.3.937/src/version.c	2013-05-12 18:44:44.000000000 +0200
Karsten Hopp 6f24d0
--- src/version.c	2013-05-12 18:52:29.000000000 +0200
Karsten Hopp 6f24d0
***************
Karsten Hopp 6f24d0
*** 730,731 ****
Karsten Hopp 6f24d0
--- 730,733 ----
Karsten Hopp 6f24d0
  {   /* Add new patch number below this line */
Karsten Hopp 6f24d0
+ /**/
Karsten Hopp 6f24d0
+     938,
Karsten Hopp 6f24d0
  /**/
Karsten Hopp 6f24d0
Karsten Hopp 6f24d0
-- 
Karsten Hopp 6f24d0
ARTHUR:  I did say sorry about the `old woman,' but from the behind you
Karsten Hopp 6f24d0
         looked--
Karsten Hopp 6f24d0
DENNIS:  What I object to is you automatically treat me like an inferior!
Karsten Hopp 6f24d0
ARTHUR:  Well, I AM king...
Karsten Hopp 6f24d0
                                  The Quest for the Holy Grail (Monty Python)
Karsten Hopp 6f24d0
Karsten Hopp 6f24d0
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 6f24d0
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 6f24d0
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 6f24d0
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///