Mercurial > vim
comparison runtime/doc/if_pyth.txt @ 8889:8755d57debaa v7.4.1731
commit https://github.com/vim/vim/commit/8110a091bc749d8748a20807a724a3af3ca6d509
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 14 15:56:09 2016 +0200
patch 7.4.1731
Problem: Python: turns partial into simple funcref.
Solution: Use partials like partials. (Nikolai Pavlov, closes https://github.com/vim/vim/issues/734)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 14 Apr 2016 16:00:06 +0200 |
parents | ed7251c3e2d3 |
children | 0bdeaf7092bc |
comparison
equal
deleted
inserted
replaced
8888:a63c61b66a49 | 8889:8755d57debaa |
---|---|
651 for i in l: # iteration | 651 for i in l: # iteration |
652 print isinstance(l, vim.List) # True | 652 print isinstance(l, vim.List) # True |
653 class List(vim.List): # Subclassing | 653 class List(vim.List): # Subclassing |
654 | 654 |
655 vim.Function object *python-Function* | 655 vim.Function object *python-Function* |
656 Function-like object, acting like vim |Funcref| object. Supports `.name` | 656 Function-like object, acting like vim |Funcref| object. Accepts special |
657 attribute and is callable. Accepts special keyword argument `self`, see | 657 keyword argument `self`, see |Dictionary-function|. You can also use |
658 |Dictionary-function|. You can also use `vim.Function(name)` constructor, | 658 `vim.Function(name)` constructor, it is the same as |
659 it is the same as `vim.bindeval('function(%s)'%json.dumps(name))`. | 659 `vim.bindeval('function(%s)'%json.dumps(name))`. |
660 | |
661 Attributes (read-only): | |
662 Attribute Description ~ | |
663 name Function name. | |
664 args `None` or a |python-List| object with arguments. Note that | |
665 this is a copy of the arguments list, constructed each time | |
666 you request this attribute. Modifications made to the list | |
667 will be ignored (but not to the containers inside argument | |
668 list: this is like |copy()| and not |deepcopy()|). | |
669 self `None` or a |python-Dictionary| object with self | |
670 dictionary. Note that explicit `self` keyword used when | |
671 calling resulting object overrides this attribute. | |
672 | |
673 Constructor additionally accepts `args` and `self` keywords. If any of | |
674 them is given then it constructs a partial, see |function()|. | |
660 | 675 |
661 Examples: > | 676 Examples: > |
662 f = vim.Function('tr') # Constructor | 677 f = vim.Function('tr') # Constructor |
663 print f('abc', 'a', 'b') # Calls tr('abc', 'a', 'b') | 678 print f('abc', 'a', 'b') # Calls tr('abc', 'a', 'b') |
664 vim.command(''' | 679 vim.command(''' |
668 ''') | 683 ''') |
669 f = vim.bindeval('function("DictFun")') | 684 f = vim.bindeval('function("DictFun")') |
670 print f(self={}) # Like call('DictFun', [], {}) | 685 print f(self={}) # Like call('DictFun', [], {}) |
671 print isinstance(f, vim.Function) # True | 686 print isinstance(f, vim.Function) # True |
672 | 687 |
688 p = vim.Function('DictFun', self={}) | |
689 print f() | |
690 p = vim.Function('tr', args=['abc', 'a']) | |
691 print f('b') | |
692 | |
673 ============================================================================== | 693 ============================================================================== |
674 8. pyeval() and py3eval() Vim functions *python-pyeval* | 694 8. pyeval() and py3eval() Vim functions *python-pyeval* |
675 | 695 |
676 To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| | 696 To facilitate bi-directional interface, you can use |pyeval()| and |py3eval()| |
677 functions to evaluate Python expressions and pass their values to VimL. | 697 functions to evaluate Python expressions and pass their values to VimL. |