Mercurial > vim
view runtime/doc/scroll.txt @ 32936:c517845bd10e v9.0.1776
patch 9.0.1776: No support for stable Python 3 ABI
Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Sun Aug 20 21:18:38 2023 +0200
patch 9.0.1776: No support for stable Python 3 ABI
Problem: No support for stable Python 3 ABI
Solution: Support Python 3 stable ABI
Commits:
1) Support Python 3 stable ABI to allow mixed version interoperatbility
Vim currently supports embedding Python for use with plugins, and the
"dynamic" linking option allows the user to specify a locally installed
version of Python by setting `pythonthreedll`. However, one caveat is
that the Python 3 libs are not binary compatible across minor versions,
and mixing versions can potentially be dangerous (e.g. let's say Vim was
linked against the Python 3.10 SDK, but the user sets `pythonthreedll`
to a 3.11 lib). Usually, nothing bad happens, but in theory this could
lead to crashes, memory corruption, and other unpredictable behaviors.
It's also difficult for the user to tell something is wrong because Vim
has no way of reporting what Python 3 version Vim was linked with.
For Vim installed via a package manager, this usually isn't an issue
because all the dependencies would already be figured out. For prebuilt
Vim binaries like MacVim (my motivation for working on this), AppImage,
and Win32 installer this could potentially be an issue as usually a
single binary is distributed. This is more tricky when a new Python
version is released, as there's a chicken-and-egg issue with deciding
what Python version to build against and hard to keep in sync when a new
Python version just drops and we have a mix of users of different Python
versions, and a user just blindly upgrading to a new Python could lead to
bad interactions with Vim.
Python 3 does have a solution for this problem: stable ABI / limited API
(see https://docs.python.org/3/c-api/stable.html). The C SDK limits the
API to a set of functions that are promised to be stable across
versions. This pull request adds an ifdef config that allows us to turn
it on when building Vim. Vim binaries built with this option should be
safe to freely link with any Python 3 libraies without having the
constraint of having to use the same minor version.
Note: Python 2 has no such concept and this doesn't change how Python 2
integration works (not that there is going to be a new version of Python
2 that would cause compatibility issues in the future anyway).
---
Technical details:
======
The stable ABI can be accessed when we compile with the Python 3 limited
API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c`
and `if_py_both.h`) would now handle this and switch to limited API
mode. Without it set, Vim will still use the full API as before so this
is an opt-in change.
The main difference is that `PyType_Object` is now an opaque struct that
we can't directly create "static types" out of, and we have to create
type objects as "heap types" instead. This is because the struct is not
stable and changes from version to version (e.g. 3.8 added a
`tp_vectorcall` field to it). I had to change all the types to be
allocated on the heap instead with just a pointer to them.
Other functions are also simply missing in limited API, or they are
introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that
we need some other ways to do the same thing, so I had to abstract a few
things into macros, and sometimes re-implement functions like
`PyObject_NEW`.
One caveat is that in limited API, `OutputType` (used for replacing
`sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't
think has any real issue other than minor differences in how they
convert to a string and missing a couple functions like `mode()` and
`fileno()`.
Also fixed an existing bug where `tp_basicsize` was set incorrectly for
`BufferObject`, `TabListObject, `WinListObject`.
Technically, there could be a small performance drop, there is a little
more indirection with accessing type objects, and some APIs like
`PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any
difference, and any well-written Python plugin should try to avoid
excessing callbacks to the `vim` module in Python anyway.
I only tested limited API mode down to Python 3.7, which seemes to
compile and work fine. I haven't tried earlier Python versions.
2) Fix PyIter_Check on older Python vers / type##Ptr unused warning
For PyIter_Check, older versions exposed them as either macros (used in
full API), or a function (for use in limited API). A previous change
exposed PyIter_Check to the dynamic build because Python just moved it
to function-only in 3.10 anyway. Because of that, just make sure we
always grab the function in dynamic builds in earlier versions since
that's what Python eventually did anyway.
3) Move Py_LIMITED_API define to configure script
Can now use --with-python-stable-abi flag to customize what stable ABI
version to target. Can also use an env var to do so as well.
4) Show +python/dyn-stable in :version, and allow has() feature query
Not sure if the "/dyn-stable" suffix would break things, or whether we
should do it another way. Or just don't show it in version and rely on
has() feature checking.
5) Documentation first draft. Still need to implement v:python3_version
6) Fix PyIter_Check build breaks when compiling against Python 3.8
7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows
This adds configurable options for Windows make files (both MinGW and
MSVC). CI will also now exercise both traditional full API and stable
ABI for Linux and Windows in the matrix for coverage.
Also added a "dynamic" option to Linux matrix as a drive-by change to
make other scripting languages like Ruby / Perl testable under both
static and dynamic builds.
8) Fix inaccuracy in Windows docs
Python's own docs are confusing but you don't actually want to use
`python3.dll` for the dynamic linkage.
9) Add generated autoconf file
10) Add v:python3_version support
This variable indicates the version of Python3 that Vim was built
against (PY_VERSION_HEX), and will be useful to check whether the Python
library you are loading in dynamically actually fits it. When built with
stable ABI, it will be the limited ABI version instead
(`Py_LIMITED_API`), which indicates the minimum version of Python 3 the
user should have, rather than the exact match. When stable ABI is used,
we won't be exposing PY_VERSION_HEX in this var because it just doesn't
seem necessary to do so (the whole point of stable ABI is the promise
that it will work across versions), and I don't want to confuse the user
with too many variables.
Also, cleaned up some documentation, and added help tags.
11) Fix Python 3.7 compat issues
Fix a couple issues when using limited API < 3.8
- Crash on exit: In Python 3.7, if a heap-allocated type is destroyed
before all instances are, it would cause a crash later. This happens
when we destroyed `OptionsType` before calling `Py_Finalize` when
using the limited API. To make it worse, later versions changed the
semantics and now each instance has a strong reference to its own type
and the recommendation has changed to have each instance de-ref its
own type and have its type in GC traversal. To avoid dealing with
these cross-version variations, we just don't free the heap type. They
are static types in non-limited-API anyway and are designed to last
through the entirety of the app, and we also don't restart the Python
runtime and therefore do not need it to have absolutely 0 leaks.
See:
- https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api
- https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api
- PyIter_Check: This function is not provided in limited APIs older than
3.8. Previously I was trying to mock it out using manual
PyType_GetSlot() but it was brittle and also does not actually work
properly for static types (it will generate a Python error). Just
return false. It does mean using limited API < 3.8 is not recommended
as you lose the functionality to handle iterators, but from playing
with plugins I couldn't find it to be an issue.
- Fix loading of PyIter_Check so it will be done when limited API < 3.8.
Otherwise loading a 3.7 Python lib will fail even if limited API was
specified to use it.
12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API
We don't use this function unless limited API >= 3.10, but we were
loading it regardless. Usually it's ok in Unix-like systems where Python
just has a single lib that we load from, but in Windows where there is a
separate python3.dll this would not work as the symbol would not have
been exposed in this more limited DLL file. This makes it much clearer
under what condition is this function needed.
closes: #12032
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Aug 2023 21:30:04 +0200 |
parents | eb2638f278bf |
children | ab758d4eccdb |
line wrap: on
line source
*scroll.txt* For Vim version 9.0. Last change: 2022 Oct 17 VIM REFERENCE MANUAL by Bram Moolenaar Scrolling *scrolling* These commands move the contents of the window. If the cursor position is moved off of the window, the cursor is moved onto the window (with 'scrolloff' screen lines around it). A page is the number of lines in the window minus two. The mnemonics for these commands may be a bit confusing. Remember that the commands refer to moving the window (the part of the buffer that you see) upwards or downwards in the buffer. When the window moves upwards in the buffer, the text in the window moves downwards on your screen. See section |03.7| of the user manual for an introduction. 1. Scrolling downwards |scroll-down| 2. Scrolling upwards |scroll-up| 3. Scrolling relative to cursor |scroll-cursor| 4. Scrolling horizontally |scroll-horizontal| 5. Scrolling synchronously |scroll-binding| 6. Scrolling with a mouse wheel |scroll-mouse-wheel| ============================================================================== 1. Scrolling downwards *scroll-down* The following commands move the edit window (the part of the buffer that you see) downwards (this means that more lines downwards in the text buffer can be seen): *CTRL-E* CTRL-E Scroll window [count] lines downwards in the buffer. The text moves upwards on the screen. Mnemonic: Extra lines. *CTRL-D* CTRL-D Scroll window Downwards in the buffer. The number of lines comes from the 'scroll' option (default: half a screen). If [count] given, first set 'scroll' option to [count]. The cursor is moved the same number of lines down in the file (if possible; when lines wrap and when hitting the end of the file there may be a difference). When the cursor is on the last line of the buffer nothing happens and a beep is produced. See also 'startofline' option. <S-Down> or *<S-Down>* *<kPageDown>* <PageDown> or *<PageDown>* *CTRL-F* CTRL-F Scroll window [count] pages Forwards (downwards) in the buffer. See also 'startofline' option. When there is only one window the 'window' option might be used. *z+* z+ Without [count]: Redraw with the line just below the window at the top of the window. Put the cursor in that line, at the first non-blank in the line. With [count]: just like "z<CR>". ============================================================================== 2. Scrolling upwards *scroll-up* The following commands move the edit window (the part of the buffer that you see) upwards (this means that more lines upwards in the text buffer can be seen): *CTRL-Y* CTRL-Y Scroll window [count] lines upwards in the buffer. The text moves downwards on the screen. Note: When using the MS-Windows key bindings CTRL-Y is remapped to redo. *CTRL-U* CTRL-U Scroll window Upwards in the buffer. The number of lines comes from the 'scroll' option (default: half a screen). If [count] given, first set the 'scroll' option to [count]. The cursor is moved the same number of lines up in the file (if possible; when lines wrap and when hitting the end of the file there may be a difference). When the cursor is on the first line of the buffer nothing happens and a beep is produced. See also 'startofline' option. <S-Up> or *<S-Up>* *<kPageUp>* <PageUp> or *<PageUp>* *CTRL-B* CTRL-B Scroll window [count] pages Backwards (upwards) in the buffer. See also 'startofline' option. When there is only one window the 'window' option might be used. *z^* z^ Without [count]: Redraw with the line just above the window at the bottom of the window. Put the cursor in that line, at the first non-blank in the line. With [count]: First scroll the text to put the [count] line at the bottom of the window, then redraw with the line which is now at the top of the window at the bottom of the window. Put the cursor in that line, at the first non-blank in the line. ============================================================================== 3. Scrolling relative to cursor *scroll-cursor* The following commands reposition the edit window (the part of the buffer that you see) while keeping the cursor on the same line. Note that the 'scrolloff' option may cause context lines to show above and below the cursor. *z<CR>* z<CR> Redraw, line [count] at top of window (default cursor line). Put cursor at first non-blank in the line. *zt* zt Like "z<CR>", but leave the cursor in the same column. *zN<CR>* z{height}<CR> Redraw, make window {height} lines tall. This is useful to make the number of lines small when screen updating is very slow. Cannot make the height more than the physical screen height. *z.* z. Redraw, line [count] at center of window (default cursor line). Put cursor at first non-blank in the line. *zz* zz Like "z.", but leave the cursor in the same column. Careful: If caps-lock is on, this command becomes "ZZ": write buffer and exit! *z-* z- Redraw, line [count] at bottom of window (default cursor line). Put cursor at first non-blank in the line. *zb* zb Like "z-", but leave the cursor in the same column. ============================================================================== 4. Scrolling horizontally *scroll-horizontal* For the following four commands the cursor follows the screen. If the character that the cursor is on is moved off the screen, the cursor is moved to the closest character that is on the screen. The value of 'sidescroll' is not used. z<Right> or *zl* *z<Right>* zl Move the view on the text [count] characters to the right, thus scroll the text [count] characters to the left. This only works when 'wrap' is off. z<Left> or *zh* *z<Left>* zh Move the view on the text [count] characters to the left, thus scroll the text [count] characters to the right. This only works when 'wrap' is off. *zL* zL Move the view on the text half a screenwidth to the right, thus scroll the text half a screenwidth to the left. This only works when 'wrap' is off. *zH* zH Move the view on the text half a screenwidth to the left, thus scroll the text half a screenwidth to the right. This only works when 'wrap' is off. For the following two commands the cursor is not moved in the text, only the text scrolls on the screen. *zs* zs Scroll the text horizontally to position the cursor at the start (left side) of the screen. This only works when 'wrap' is off. *ze* ze Scroll the text horizontally to position the cursor at the end (right side) of the screen. This only works when 'wrap' is off. ============================================================================== 5. Scrolling synchronously *scroll-binding* Occasionally, it is desirable to bind two or more windows together such that when one window is scrolled, the other windows are also scrolled. In Vim, windows can be given this behavior by setting the (window-specific) 'scrollbind' option. When a window that has 'scrollbind' set is scrolled, all other 'scrollbind' windows are scrolled the same amount, if possible. The behavior of 'scrollbind' can be modified by the 'scrollopt' option. When using the scrollbars, the binding only happens when scrolling the window with focus (where the cursor is). You can use this to avoid scroll-binding for a moment without resetting options. When a window also has the 'diff' option set, the scroll-binding uses the differences between the two buffers to synchronize the position precisely. Otherwise the following method is used. *scrollbind-relative* Each 'scrollbind' window keeps track of its "relative offset," which can be thought of as the difference between the current window's vertical scroll position and the other window's vertical scroll position. When one of the 'scrollbind' windows is asked to vertically scroll past the beginning or end limit of its text, the window no longer scrolls, but remembers how far past the limit it wishes to be. The window keeps this information so that it can maintain the same relative offset, regardless of its being asked to scroll past its buffer's limits. However, if a 'scrollbind' window that has a relative offset that is past its buffer's limits is given the cursor focus, the other 'scrollbind' windows must jump to a location where the current window's relative offset is valid. This behavior can be changed by clearing the "jump" flag from the 'scrollopt' option. *syncbind* *:syncbind* *:sync* :syncbind Force all 'scrollbind' windows to have the same relative offset. I.e., when any of the 'scrollbind' windows is scrolled to the top of its buffer, all of the 'scrollbind' windows will also be at the top of their buffers. *scrollbind-quickadj* The 'scrollbind' flag is meaningful when using keyboard commands to vertically scroll a window, and also meaningful when using the vertical scrollbar of the window which has the cursor focus. However, when using the vertical scrollbar of a window which doesn't have the cursor focus, 'scrollbind' is ignored. This allows quick adjustment of the relative offset of 'scrollbind' windows. ============================================================================== 6. Scrolling with a mouse wheel *scroll-mouse-wheel* When your mouse has a scroll wheel, it should work with Vim in the GUI. How it works depends on your system. It might also work in an xterm |xterm-mouse-wheel|. By default only vertical scroll wheels are supported, but some GUIs also support horizontal scroll wheels. On MS-Windows, if the scroll action causes input focus -problems, see |intellimouse-wheel-problems|. For Win32 and the X11 GUIs (Motif and GTK) scrolling the wheel generates key presses <ScrollWheelUp>, <ScrollWheelDown>, <ScrollWheelLeft> and <ScrollWheelRight>. For example, if you push the scroll wheel upwards a <ScrollWheelUp> key press is generated causing the window to scroll upwards (while the text is actually moving downwards). The default action for these keys are: <ScrollWheelUp> scroll N lines up *<ScrollWheelUp>* <S-ScrollWheelUp> scroll one page up *<S-ScrollWheelUp>* <C-ScrollWheelUp> scroll one page up *<C-ScrollWheelUp>* <ScrollWheelDown> scroll N lines down *<ScrollWheelDown>* <S-ScrollWheelDown> scroll one page down *<S-ScrollWheelDown>* <C-ScrollWheelDown> scroll one page down *<C-ScrollWheelDown>* <ScrollWheelLeft> scroll N columns left *<ScrollWheelLeft>* <S-ScrollWheelLeft> scroll one page left *<S-ScrollWheelLeft>* <C-ScrollWheelLeft> scroll one page left *<C-ScrollWheelLeft>* <ScrollWheelRight> scroll N columns right *<ScrollWheelRight>* <S-ScrollWheelRight> scroll one page right *<S-ScrollWheelRight>* <C-ScrollWheelRight> scroll one page right *<C-ScrollWheelRight>* This should work in all modes, except when editing the command line. The value of N depends on the system. By default Vim scrolls three lines when moving vertically, and six columns when moving horizontally. On MS-Windows the amount of lines and columns for each scroll action is taken from the system-wide settings. Note that horizontal scrolling only works if 'nowrap' is set. Also, unless the "h" flag in 'guioptions' is set, the cursor moves to the longest visible line if the cursor line is about to be scrolled off the screen (similarly to how the horizontal scrollbar works). You can modify the default behavior by mapping the keys. For example, to make the scroll wheel move one line or half a page in Normal mode: > :map <ScrollWheelUp> <C-Y> :map <S-ScrollWheelUp> <C-U> :map <ScrollWheelDown> <C-E> :map <S-ScrollWheelDown> <C-D> You can also use Alt and Ctrl modifiers. This only works when Vim gets the scroll wheel events, of course. You can check if this works with the "xev" program. *mouse-scrolling-off* If you do not want the mouse to cause scrolling (e.g. because resting your palm on the touchpad causes scroll events), you can disable that with: > :map <ScrollWheelDown> <Nop> :map! <ScrollWheelDown> <Nop> :map <ScrollWheelUp> <Nop> :map! <ScrollWheelUp> <Nop> :map <ScrollWheelLeft> <Nop> :map! <ScrollWheelLeft> <Nop> :map <ScrollWheelRight> <Nop> :map! <ScrollWheelRight> <Nop> When using XFree86, the /etc/XF86Config file should have the correct entry for your mouse. For FreeBSD, this entry works for a Logitech scrollmouse: > Protocol "MouseMan" Device "/dev/psm0" ZAxisMapping 4 5 See the XFree86 documentation for information. *<MouseDown>* *<MouseUp>* The keys <MouseDown> and <MouseUp> have been deprecated. Use <ScrollWheelUp> instead of <MouseDown> and use <ScrollWheelDown> instead of <MouseUp>. *xterm-mouse-wheel* To use the mouse wheel in a new xterm you only have to make the scroll wheel work in your Xserver, as mentioned above. To use the mouse wheel in an older xterm you must do this: 1. Make it work in your Xserver, as mentioned above. 2. Add translations for the xterm, so that the xterm will pass a scroll event to Vim as an escape sequence. 3. Add mappings in Vim, to interpret the escape sequences as <ScrollWheelDown> or <ScrollWheelUp> keys. You can do the translations by adding this to your ~.Xdefaults file (or other file where your X resources are kept): > XTerm*VT100.Translations: #override \n\ s<Btn4Down>: string("0x9b") string("[64~") \n\ s<Btn5Down>: string("0x9b") string("[65~") \n\ <Btn4Down>: string("0x9b") string("[62~") \n\ <Btn5Down>: string("0x9b") string("[63~") \n\ <Btn4Up>: \n\ <Btn5Up>: Add these mappings to your vimrc file: > :map <M-Esc>[62~ <ScrollWheelUp> :map! <M-Esc>[62~ <ScrollWheelUp> :map <M-Esc>[63~ <ScrollWheelDown> :map! <M-Esc>[63~ <ScrollWheelDown> :map <M-Esc>[64~ <S-ScrollWheelUp> :map! <M-Esc>[64~ <S-ScrollWheelUp> :map <M-Esc>[65~ <S-ScrollWheelDown> :map! <M-Esc>[65~ <S-ScrollWheelDown> < vim:tw=78:ts=8:noet:ft=help:norl: