# HG changeset patch
# User ZyX <[email protected]>
# Date 1367415057 -14400
# Branch python-extended-2
# Node ID 1af3f5a86428608eddca083bb94c574910828bd6
# Parent 14b6c739b0be3839693bf9bfcf9103f4f135a65d
Add ability to assign to vim.current.{tabpage,buffer,window}
diff -r 14b6c739b0be -r 1af3f5a86428 runtime/doc/if_pyth.txt
--- a/runtime/doc/if_pyth.txt Mon Apr 29 08:27:55 2013 +0400
+++ b/runtime/doc/if_pyth.txt Wed May 01 17:30:57 2013 +0400
@@ -242,9 +242,9 @@
An object providing access (via specific attributes) to various
"current" objects available in vim:
vim.current.line The current line (RW) String
- vim.current.buffer The current buffer (RO) Buffer
- vim.current.window The current window (RO) Window
- vim.current.tabpage The current tab page (RO) TabPage
+ vim.current.buffer The current buffer (RW) Buffer
+ vim.current.window The current window (RW) Window
+ vim.current.tabpage The current tab page (RW) TabPage
vim.current.range The current line range (RO) Range
The last case deserves a little explanation. When the :python or
@@ -252,6 +252,22 @@
"current range". A range is a bit like a buffer, but with all access
restricted to a subset of lines. See |python-range| for more details.
+ Note: When assigning to vim.current.{buffer,window,tabpage} it expects
+ valid |python-buffer|, |python-window| or |python-tabpage| objects
+ respectively. Assigning triggers normal (with |autocommand|s)
+ switching to given buffer, window or tab page. It is the only way to
+ switch UI objects in python: you can't assign to
+ |python-tabpage|.window attribute. To switch without triggering
+ autocommands use >
+ py << EOF
+ saved_eventignore = vim.options['eventignore']
+ vim.options['eventignore'] = 'all'
+ try:
+ vim.current.buffer = vim.buffers[2] # Switch to buffer 2
+ finally:
+ vim.options['eventignore'] = saved_eventignore
+ EOF
+<
vim.vars *python-vars*
vim.vvars *python-vvars*
Dictionary-like objects holding dictionaries with global (|g:|) and
diff -r 14b6c739b0be -r 1af3f5a86428 src/if_py_both.h
--- a/src/if_py_both.h Mon Apr 29 08:27:55 2013 +0400
+++ b/src/if_py_both.h Wed May 01 17:30:57 2013 +0400
@@ -3242,6 +3242,80 @@
return 0;
}
+ else if (strcmp(name, "buffer") == 0)
+ {
+ int count;
+
+ if (value->ob_type != &BufferType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.buffer object"));
+ return -1;
+ }
+
+ if (CheckBuffer((BufferObject *)(value)))
+ return -1;
+ count = ((BufferObject *)(value))->buf->b_fnum;
+
+ if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
+ {
+ PyErr_SetVim(_("failed to switch to given buffer"));
+ return -1;
+ }
+
+ return 0;
+ }
+ else if (strcmp(name, "window") == 0)
+ {
+ int count;
+
+ if (value->ob_type != &WindowType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.window object"));
+ return -1;
+ }
+
+ if (CheckWindow((WindowObject *)(value)))
+ return -1;
+ count = get_win_number(((WindowObject *)(value))->win, firstwin);
+
+ if (!count)
+ {
+ PyErr_SetString(PyExc_ValueError,
+ _("failed to find window in the current tab page"));
+ return -1;
+ }
+
+ win_goto(((WindowObject *)(value))->win);
+ if (((WindowObject *)(value))->win != curwin)
+ {
+ PyErr_SetString(PyExc_RuntimeError,
+ _("did not switch to the specified window"));
+ return -1;
+ }
+
+ return 0;
+ }
+ else if (strcmp(name, "tabpage") == 0)
+ {
+ if (value->ob_type != &TabPageType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.tabpage object"));
+ return -1;
+ }
+
+ if (CheckTabPage((TabPageObject *)(value)))
+ return -1;
+
+ goto_tabpage_tp(((TabPageObject *)(value))->tab, TRUE, TRUE);
+ if (((TabPageObject *)(value))->tab != curtab)
+ {
+ PyErr_SetString(PyExc_RuntimeError,
+ _("did not switch to the specified tab page"));
+ return -1;
+ }
+
+ return 0;
+ }
else
{
PyErr_SetString(PyExc_AttributeError, name);
--
--
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.14b6c739b0be/runtime/doc/if_pyth.txt vim.1af3f5a86428/runtime/doc/if_pyth.txt
*** vim.14b6c739b0be/runtime/doc/if_pyth.txt 2013-05-01 19:11:31.936264024 +0400
--- vim.1af3f5a86428/runtime/doc/if_pyth.txt 2013-05-01 19:11:31.939263994 +0400
***************
*** 242,250 ****
An object providing access (via specific attributes) to various
"current" objects available in vim:
vim.current.line The current line (RW) String
! vim.current.buffer The current buffer (RO) Buffer
! vim.current.window The current window (RO) Window
! vim.current.tabpage The current tab page (RO) TabPage
vim.current.range The current line range (RO) Range
The last case deserves a little explanation. When the :python or
--- 242,250 ----
An object providing access (via specific attributes) to various
"current" objects available in vim:
vim.current.line The current line (RW) String
! vim.current.buffer The current buffer (RW) Buffer
! vim.current.window The current window (RW) Window
! vim.current.tabpage The current tab page (RW) TabPage
vim.current.range The current line range (RO) Range
The last case deserves a little explanation. When the :python or
***************
*** 252,257 ****
--- 252,273 ----
"current range". A range is a bit like a buffer, but with all access
restricted to a subset of lines. See |python-range| for more details.
+ Note: When assigning to vim.current.{buffer,window,tabpage} it expects
+ valid |python-buffer|, |python-window| or |python-tabpage| objects
+ respectively. Assigning triggers normal (with |autocommand|s)
+ switching to given buffer, window or tab page. It is the only way to
+ switch UI objects in python: you can't assign to
+ |python-tabpage|.window attribute. To switch without triggering
+ autocommands use >
+ py << EOF
+ saved_eventignore = vim.options['eventignore']
+ vim.options['eventignore'] = 'all'
+ try:
+ vim.current.buffer = vim.buffers[2] # Switch to buffer 2
+ finally:
+ vim.options['eventignore'] = saved_eventignore
+ EOF
+ <
vim.vars *python-vars*
vim.vvars *python-vvars*
Dictionary-like objects holding dictionaries with global (|g:|) and
diff -cr vim.14b6c739b0be/src/if_py_both.h vim.1af3f5a86428/src/if_py_both.h
*** vim.14b6c739b0be/src/if_py_both.h 2013-05-01 19:11:31.934264044 +0400
--- vim.1af3f5a86428/src/if_py_both.h 2013-05-01 19:11:31.941263976 +0400
***************
*** 3242,3247 ****
--- 3242,3321 ----
return 0;
}
+ else if (strcmp(name, "buffer") == 0)
+ {
+ int count;
+
+ if (value->ob_type != &BufferType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.buffer object"));
+ return -1;
+ }
+
+ if (CheckBuffer((BufferObject *)(value)))
+ return -1;
+ count = ((BufferObject *)(value))->buf->b_fnum;
+
+ if (do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, count, 0) == FAIL)
+ {
+ PyErr_SetVim(_("failed to switch to given buffer"));
+ return -1;
+ }
+
+ return 0;
+ }
+ else if (strcmp(name, "window") == 0)
+ {
+ int count;
+
+ if (value->ob_type != &WindowType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.window object"));
+ return -1;
+ }
+
+ if (CheckWindow((WindowObject *)(value)))
+ return -1;
+ count = get_win_number(((WindowObject *)(value))->win, firstwin);
+
+ if (!count)
+ {
+ PyErr_SetString(PyExc_ValueError,
+ _("failed to find window in the current tab page"));
+ return -1;
+ }
+
+ win_goto(((WindowObject *)(value))->win);
+ if (((WindowObject *)(value))->win != curwin)
+ {
+ PyErr_SetString(PyExc_RuntimeError,
+ _("did not switch to the specified window"));
+ return -1;
+ }
+
+ return 0;
+ }
+ else if (strcmp(name, "tabpage") == 0)
+ {
+ if (value->ob_type != &TabPageType)
+ {
+ PyErr_SetString(PyExc_TypeError, _("expected vim.tabpage object"));
+ return -1;
+ }
+
+ if (CheckTabPage((TabPageObject *)(value)))
+ return -1;
+
+ goto_tabpage_tp(((TabPageObject *)(value))->tab, TRUE, TRUE);
+ if (((TabPageObject *)(value))->tab != curtab)
+ {
+ PyErr_SetString(PyExc_RuntimeError,
+ _("did not switch to the specified tab page"));
+ return -1;
+ }
+
+ return 0;
+ }
else
{
PyErr_SetString(PyExc_AttributeError, name);