Karsten Hopp fc5a69
To: vim_dev@googlegroups.com
Karsten Hopp fc5a69
Subject: Patch 7.3.952
Karsten Hopp fc5a69
Fcc: outbox
Karsten Hopp fc5a69
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp fc5a69
Mime-Version: 1.0
Karsten Hopp fc5a69
Content-Type: text/plain; charset=UTF-8
Karsten Hopp fc5a69
Content-Transfer-Encoding: 8bit
Karsten Hopp fc5a69
------------
Karsten Hopp fc5a69
Karsten Hopp fc5a69
Patch 7.3.952
Karsten Hopp fc5a69
Problem:    Python: It's not easy to change window/buffer/tabpage.
Karsten Hopp fc5a69
Solution:   Add ability to assign to vim.current.{tabpage,buffer,window}.
Karsten Hopp fc5a69
	    (ZyX)
Karsten Hopp fc5a69
Files:	    runtime/doc/if_pyth.txt, src/if_py_both.h
Karsten Hopp fc5a69
Karsten Hopp fc5a69
Karsten Hopp fc5a69
*** ../vim-7.3.951/runtime/doc/if_pyth.txt	2013-05-15 15:12:25.000000000 +0200
Karsten Hopp fc5a69
--- runtime/doc/if_pyth.txt	2013-05-15 15:48:39.000000000 +0200
Karsten Hopp fc5a69
***************
Karsten Hopp fc5a69
*** 242,250 ****
Karsten Hopp fc5a69
  	An object providing access (via specific attributes) to various
Karsten Hopp fc5a69
  	"current" objects available in vim:
Karsten Hopp fc5a69
  		vim.current.line	The current line (RW)		String
Karsten Hopp fc5a69
! 		vim.current.buffer	The current buffer (RO)		Buffer
Karsten Hopp fc5a69
! 		vim.current.window	The current window (RO)		Window
Karsten Hopp fc5a69
! 		vim.current.tabpage	The current tab page (RO)	TabPage
Karsten Hopp fc5a69
  		vim.current.range	The current line range (RO)	Range
Karsten Hopp fc5a69
  
Karsten Hopp fc5a69
  	The last case deserves a little explanation.  When the :python or
Karsten Hopp fc5a69
--- 242,250 ----
Karsten Hopp fc5a69
  	An object providing access (via specific attributes) to various
Karsten Hopp fc5a69
  	"current" objects available in vim:
Karsten Hopp fc5a69
  		vim.current.line	The current line (RW)		String
Karsten Hopp fc5a69
! 		vim.current.buffer	The current buffer (RW)		Buffer
Karsten Hopp fc5a69
! 		vim.current.window	The current window (RW)		Window
Karsten Hopp fc5a69
! 		vim.current.tabpage	The current tab page (RW)	TabPage
Karsten Hopp fc5a69
  		vim.current.range	The current line range (RO)	Range
Karsten Hopp fc5a69
  
Karsten Hopp fc5a69
  	The last case deserves a little explanation.  When the :python or
Karsten Hopp fc5a69
***************
Karsten Hopp fc5a69
*** 252,257 ****
Karsten Hopp fc5a69
--- 252,273 ----
Karsten Hopp fc5a69
  	"current range".  A range is a bit like a buffer, but with all access
Karsten Hopp fc5a69
  	restricted to a subset of lines.  See |python-range| for more details.
Karsten Hopp fc5a69
  
Karsten Hopp fc5a69
+ 	Note: When assigning to vim.current.{buffer,window,tabpage} it expects 
Karsten Hopp fc5a69
+ 	valid |python-buffer|, |python-window| or |python-tabpage| objects 
Karsten Hopp fc5a69
+ 	respectively. Assigning triggers normal (with |autocommand|s) 
Karsten Hopp fc5a69
+ 	switching to given buffer, window or tab page. It is the only way to 
Karsten Hopp fc5a69
+ 	switch UI objects in python: you can't assign to 
Karsten Hopp fc5a69
+ 	|python-tabpage|.window attribute. To switch without triggering 
Karsten Hopp fc5a69
+ 	autocommands use >
Karsten Hopp fc5a69
+ 	    py << EOF
Karsten Hopp fc5a69
+ 	    saved_eventignore = vim.options['eventignore']
Karsten Hopp fc5a69
+ 	    vim.options['eventignore'] = 'all'
Karsten Hopp fc5a69
+ 	    try:
Karsten Hopp fc5a69
+ 	        vim.current.buffer = vim.buffers[2] # Switch to buffer 2
Karsten Hopp fc5a69
+ 	    finally:
Karsten Hopp fc5a69
+ 	        vim.options['eventignore'] = saved_eventignore
Karsten Hopp fc5a69
+ 	    EOF
Karsten Hopp fc5a69
+ <
Karsten Hopp fc5a69
  vim.vars						*python-vars*
Karsten Hopp fc5a69
  vim.vvars						*python-vvars*
Karsten Hopp fc5a69
  	Dictionary-like objects holding dictionaries with global (|g:|) and 
Karsten Hopp fc5a69
*** ../vim-7.3.951/src/if_py_both.h	2013-05-15 15:44:24.000000000 +0200
Karsten Hopp fc5a69
--- src/if_py_both.h	2013-05-15 15:48:39.000000000 +0200
Karsten Hopp fc5a69
***************
Karsten Hopp fc5a69
*** 3244,3249 ****
Karsten Hopp fc5a69
--- 3244,3323 ----
Karsten Hopp fc5a69
  
Karsten Hopp fc5a69
  	return 0;
Karsten Hopp fc5a69
      }
Karsten Hopp fc5a69
+     else if (strcmp(name, "buffer") == 0)
Karsten Hopp fc5a69
+     {
Karsten Hopp fc5a69
+ 	int count;
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (value->ob_type != &BufferType)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_TypeError, _("expected vim.buffer object"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (CheckBuffer((BufferObject *)(value)))
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	count = ((BufferObject *)(value))->buf->b_fnum;
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetVim(_("failed to switch to given buffer"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	return 0;
Karsten Hopp fc5a69
+     }
Karsten Hopp fc5a69
+     else if (strcmp(name, "window") == 0)
Karsten Hopp fc5a69
+     {
Karsten Hopp fc5a69
+ 	int count;
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (value->ob_type != &WindowType)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_TypeError, _("expected vim.window object"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (CheckWindow((WindowObject *)(value)))
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	count = get_win_number(((WindowObject *)(value))->win, firstwin);
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (!count)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_ValueError,
Karsten Hopp fc5a69
+ 		    _("failed to find window in the current tab page"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	win_goto(((WindowObject *)(value))->win);
Karsten Hopp fc5a69
+ 	if (((WindowObject *)(value))->win != curwin)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_RuntimeError,
Karsten Hopp fc5a69
+ 		    _("did not switch to the specified window"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	return 0;
Karsten Hopp fc5a69
+     }
Karsten Hopp fc5a69
+     else if (strcmp(name, "tabpage") == 0)
Karsten Hopp fc5a69
+     {
Karsten Hopp fc5a69
+ 	if (value->ob_type != &TabPageType)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_TypeError, _("expected vim.tabpage object"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	if (CheckTabPage((TabPageObject *)(value)))
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	goto_tabpage_tp(((TabPageObject *)(value))->tab, TRUE, TRUE);
Karsten Hopp fc5a69
+ 	if (((TabPageObject *)(value))->tab != curtab)
Karsten Hopp fc5a69
+ 	{
Karsten Hopp fc5a69
+ 	    PyErr_SetString(PyExc_RuntimeError,
Karsten Hopp fc5a69
+ 		    _("did not switch to the specified tab page"));
Karsten Hopp fc5a69
+ 	    return -1;
Karsten Hopp fc5a69
+ 	}
Karsten Hopp fc5a69
+ 
Karsten Hopp fc5a69
+ 	return 0;
Karsten Hopp fc5a69
+     }
Karsten Hopp fc5a69
      else
Karsten Hopp fc5a69
      {
Karsten Hopp fc5a69
  	PyErr_SetString(PyExc_AttributeError, name);
Karsten Hopp fc5a69
*** ../vim-7.3.951/src/version.c	2013-05-15 15:44:24.000000000 +0200
Karsten Hopp fc5a69
--- src/version.c	2013-05-15 15:49:12.000000000 +0200
Karsten Hopp fc5a69
***************
Karsten Hopp fc5a69
*** 730,731 ****
Karsten Hopp fc5a69
--- 730,733 ----
Karsten Hopp fc5a69
  {   /* Add new patch number below this line */
Karsten Hopp fc5a69
+ /**/
Karsten Hopp fc5a69
+     952,
Karsten Hopp fc5a69
  /**/
Karsten Hopp fc5a69
Karsten Hopp fc5a69
-- 
Karsten Hopp fc5a69
Trees moving back and forth is what makes the wind blow.
Karsten Hopp fc5a69
Karsten Hopp fc5a69
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp fc5a69
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp fc5a69
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp fc5a69
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///