comparison runtime/doc/eval.txt @ 17783:45eca7143d7c v8.1.1888

patch 8.1.1888: more functions can be used as methods commit https://github.com/vim/vim/commit/073e4b92e613d22ce7b16e0fbf5c0e40cb5f9b2c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 18 23:01:56 2019 +0200 patch 8.1.1888: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method.
author Bram Moolenaar <Bram@vim.org>
date Sun, 18 Aug 2019 23:15:03 +0200
parents 545119cd5554
children ce993ba17adb
comparison
equal deleted inserted replaced
17782:634884027f45 17783:45eca7143d7c
1 *eval.txt* For Vim version 8.1. Last change: 2019 Aug 17 1 *eval.txt* For Vim version 8.1. Last change: 2019 Aug 18
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
2935 and({expr}, {expr}) *and()* 2935 and({expr}, {expr}) *and()*
2936 Bitwise AND on the two arguments. The arguments are converted 2936 Bitwise AND on the two arguments. The arguments are converted
2937 to a number. A List, Dict or Float argument causes an error. 2937 to a number. A List, Dict or Float argument causes an error.
2938 Example: > 2938 Example: >
2939 :let flag = and(bits, 0x80) 2939 :let flag = and(bits, 0x80)
2940 < Can also be used as a |method|: >
2941 :let flag = bits->and(0x80)
2940 2942
2941 2943
2942 append({lnum}, {text}) *append()* 2944 append({lnum}, {text}) *append()*
2943 When {text} is a |List|: Append each item of the |List| as a 2945 When {text} is a |List|: Append each item of the |List| as a
2944 text line below line {lnum} in the current buffer. 2946 text line below line {lnum} in the current buffer.
3086 set balloonexpr=GetBalloonContent() 3088 set balloonexpr=GetBalloonContent()
3087 3089
3088 func BalloonCallback(result) 3090 func BalloonCallback(result)
3089 call balloon_show(a:result) 3091 call balloon_show(a:result)
3090 endfunc 3092 endfunc
3093 < Can also be used as a |method|: >
3094 GetText()->balloon_show()
3091 < 3095 <
3092 The intended use is that fetching the content of the balloon 3096 The intended use is that fetching the content of the balloon
3093 is initiated from 'balloonexpr'. It will invoke an 3097 is initiated from 'balloonexpr'. It will invoke an
3094 asynchronous method, in which a callback invokes 3098 asynchronous method, in which a callback invokes
3095 balloon_show(). The 'balloonexpr' itself can return an 3099 balloon_show(). The 'balloonexpr' itself can return an
3103 balloon_split({msg}) *balloon_split()* 3107 balloon_split({msg}) *balloon_split()*
3104 Split {msg} into lines to be displayed in a balloon. The 3108 Split {msg} into lines to be displayed in a balloon. The
3105 splits are made for the current window size and optimize to 3109 splits are made for the current window size and optimize to
3106 show debugger output. 3110 show debugger output.
3107 Returns a |List| with the split lines. 3111 Returns a |List| with the split lines.
3108 {only available when compiled with the |+balloon_eval_term| 3112 Can also be used as a |method|: >
3113 GetText()->balloon_split()->balloon_show()
3114
3115 < {only available when compiled with the |+balloon_eval_term|
3109 feature} 3116 feature}
3110 3117
3111 *browse()* 3118 *browse()*
3112 browse({save}, {title}, {initdir}, {default}) 3119 browse({save}, {title}, {initdir}, {default})
3113 Put up a file requester. This only works when "has("browse")" 3120 Put up a file requester. This only works when "has("browse")"
3115 The input fields are: 3122 The input fields are:
3116 {save} when |TRUE|, select file to write 3123 {save} when |TRUE|, select file to write
3117 {title} title for the requester 3124 {title} title for the requester
3118 {initdir} directory to start browsing in 3125 {initdir} directory to start browsing in
3119 {default} default file name 3126 {default} default file name
3120 When the "Cancel" button is hit, something went wrong, or 3127 An empty string is returned when the "Cancel" button is hit,
3121 browsing is not possible, an empty string is returned. 3128 something went wrong, or browsing is not possible.
3122 3129
3123 *browsedir()* 3130 *browsedir()*
3124 browsedir({title}, {initdir}) 3131 browsedir({title}, {initdir})
3125 Put up a directory requester. This only works when 3132 Put up a directory requester. This only works when
3126 "has("browse")" returns |TRUE| (only in some GUI versions). 3133 "has("browse")" returns |TRUE| (only in some GUI versions).
3142 The buffer will not have' 'buflisted' set and not be loaded 3149 The buffer will not have' 'buflisted' set and not be loaded
3143 yet. To add some text to the buffer use this: > 3150 yet. To add some text to the buffer use this: >
3144 let bufnr = bufadd('someName') 3151 let bufnr = bufadd('someName')
3145 call bufload(bufnr) 3152 call bufload(bufnr)
3146 call setbufline(bufnr, 1, ['some', 'text']) 3153 call setbufline(bufnr, 1, ['some', 'text'])
3154 < Can also be used as a |method|: >
3155 let bufnr = 'somename'->bufadd()
3147 3156
3148 bufexists({expr}) *bufexists()* 3157 bufexists({expr}) *bufexists()*
3149 The result is a Number, which is |TRUE| if a buffer called 3158 The result is a Number, which is |TRUE| if a buffer called
3150 {expr} exists. 3159 {expr} exists.
3151 If the {expr} argument is a number, buffer numbers are used. 3160 If the {expr} argument is a number, buffer numbers are used.
3164 bufexists() may report a buffer exists, but to use the name 3173 bufexists() may report a buffer exists, but to use the name
3165 with a |:buffer| command you may need to use |expand()|. Esp 3174 with a |:buffer| command you may need to use |expand()|. Esp
3166 for MS-Windows 8.3 names in the form "c:\DOCUME~1" 3175 for MS-Windows 8.3 names in the form "c:\DOCUME~1"
3167 Use "bufexists(0)" to test for the existence of an alternate 3176 Use "bufexists(0)" to test for the existence of an alternate
3168 file name. 3177 file name.
3169 *buffer_exists()* 3178
3170 Obsolete name: buffer_exists(). 3179 Can also be used as a |method|: >
3180 let exists = 'somename'->bufexists()
3181 <
3182 Obsolete name: buffer_exists(). *buffer_exists()*
3171 3183
3172 buflisted({expr}) *buflisted()* 3184 buflisted({expr}) *buflisted()*
3173 The result is a Number, which is |TRUE| if a buffer called 3185 The result is a Number, which is |TRUE| if a buffer called
3174 {expr} exists and is listed (has the 'buflisted' option set). 3186 {expr} exists and is listed (has the 'buflisted' option set).
3175 The {expr} argument is used like with |bufexists()|. 3187 The {expr} argument is used like with |bufexists()|.
3188
3189 Can also be used as a |method|: >
3190 let listed = 'somename'->buflisted()
3176 3191
3177 bufload({expr}) *bufload()* 3192 bufload({expr}) *bufload()*
3178 Ensure the buffer {expr} is loaded. When the buffer name 3193 Ensure the buffer {expr} is loaded. When the buffer name
3179 refers to an existing file then the file is read. Otherwise 3194 refers to an existing file then the file is read. Otherwise
3180 the buffer will be empty. If the buffer was already loaded 3195 the buffer will be empty. If the buffer was already loaded
3181 then there is no change. 3196 then there is no change.
3182 If there is an existing swap file for the file of the buffer, 3197 If there is an existing swap file for the file of the buffer,
3183 there will be no dialog, the buffer will be loaded anyway. 3198 there will be no dialog, the buffer will be loaded anyway.
3184 The {expr} argument is used like with |bufexists()|. 3199 The {expr} argument is used like with |bufexists()|.
3185 3200
3201 Can also be used as a |method|: >
3202 eval 'somename'->bufload()
3203
3186 bufloaded({expr}) *bufloaded()* 3204 bufloaded({expr}) *bufloaded()*
3187 The result is a Number, which is |TRUE| if a buffer called 3205 The result is a Number, which is |TRUE| if a buffer called
3188 {expr} exists and is loaded (shown in a window or hidden). 3206 {expr} exists and is loaded (shown in a window or hidden).
3189 The {expr} argument is used like with |bufexists()|. 3207 The {expr} argument is used like with |bufexists()|.
3208
3209 Can also be used as a |method|: >
3210 let loaded = 'somename'->bufloaded()
3190 3211
3191 bufname({expr}) *bufname()* 3212 bufname({expr}) *bufname()*
3192 The result is the name of a buffer, as it is displayed by the 3213 The result is the name of a buffer, as it is displayed by the
3193 ":ls" command. 3214 ":ls" command.
3194 If {expr} is a Number, that buffer number's name is given. 3215 If {expr} is a Number, that buffer number's name is given.
3207 with a listed buffer, that one is returned. Next unlisted 3228 with a listed buffer, that one is returned. Next unlisted
3208 buffers are searched for. 3229 buffers are searched for.
3209 If the {expr} is a String, but you want to use it as a buffer 3230 If the {expr} is a String, but you want to use it as a buffer
3210 number, force it to be a Number by adding zero to it: > 3231 number, force it to be a Number by adding zero to it: >
3211 :echo bufname("3" + 0) 3232 :echo bufname("3" + 0)
3233 < Can also be used as a |method|: >
3234 echo bufnr->bufname()
3235
3212 < If the buffer doesn't exist, or doesn't have a name, an empty 3236 < If the buffer doesn't exist, or doesn't have a name, an empty
3213 string is returned. > 3237 string is returned. >
3214 bufname("#") alternate buffer name 3238 bufname("#") alternate buffer name
3215 bufname(3) name of buffer 3 3239 bufname(3) name of buffer 3
3216 bufname("%") name of current buffer 3240 bufname("%") name of current buffer
3230 :let last_buffer = bufnr("$") 3254 :let last_buffer = bufnr("$")
3231 < The result is a Number, which is the highest buffer number 3255 < The result is a Number, which is the highest buffer number
3232 of existing buffers. Note that not all buffers with a smaller 3256 of existing buffers. Note that not all buffers with a smaller
3233 number necessarily exist, because ":bwipeout" may have removed 3257 number necessarily exist, because ":bwipeout" may have removed
3234 them. Use bufexists() to test for the existence of a buffer. 3258 them. Use bufexists() to test for the existence of a buffer.
3235 *buffer_number()* 3259
3236 Obsolete name: buffer_number(). 3260 Can also be used as a |method|: >
3261 echo bufref->bufnr()
3262 <
3263 Obsolete name: buffer_number(). *buffer_number()*
3237 *last_buffer_nr()* 3264 *last_buffer_nr()*
3238 Obsolete name for bufnr("$"): last_buffer_nr(). 3265 Obsolete name for bufnr("$"): last_buffer_nr().
3239 3266
3240 bufwinid({expr}) *bufwinid()* 3267 bufwinid({expr}) *bufwinid()*
3241 The result is a Number, which is the |window-ID| of the first 3268 The result is a Number, which is the |window-ID| of the first
5832 5859
5833 invert({expr}) *invert()* 5860 invert({expr}) *invert()*
5834 Bitwise invert. The argument is converted to a number. A 5861 Bitwise invert. The argument is converted to a number. A
5835 List, Dict or Float argument causes an error. Example: > 5862 List, Dict or Float argument causes an error. Example: >
5836 :let bits = invert(bits) 5863 :let bits = invert(bits)
5864 < Can also be used as a |method|: >
5865 :let bits = bits->invert()
5837 5866
5838 isdirectory({directory}) *isdirectory()* 5867 isdirectory({directory}) *isdirectory()*
5839 The result is a Number, which is |TRUE| when a directory 5868 The result is a Number, which is |TRUE| when a directory
5840 with the name {directory} exists. If {directory} doesn't 5869 with the name {directory} exists. If {directory} doesn't
5841 exist, or isn't a directory, the result is |FALSE|. {directory} 5870 exist, or isn't a directory, the result is |FALSE|. {directory}
6760 To turn a list of character numbers into a string: > 6789 To turn a list of character numbers into a string: >
6761 let list = [65, 66, 67] 6790 let list = [65, 66, 67]
6762 let str = join(map(list, {_, val -> nr2char(val)}), '') 6791 let str = join(map(list, {_, val -> nr2char(val)}), '')
6763 < Result: "ABC" 6792 < Result: "ABC"
6764 6793
6794
6765 or({expr}, {expr}) *or()* 6795 or({expr}, {expr}) *or()*
6766 Bitwise OR on the two arguments. The arguments are converted 6796 Bitwise OR on the two arguments. The arguments are converted
6767 to a number. A List, Dict or Float argument causes an error. 6797 to a number. A List, Dict or Float argument causes an error.
6768 Example: > 6798 Example: >
6769 :let bits = or(bits, 0x80) 6799 :let bits = or(bits, 0x80)
6800 < Can also be used as a |method|: >
6801 :let bits = bits->or(0x80)
6770 6802
6771 6803
6772 pathshorten({expr}) *pathshorten()* 6804 pathshorten({expr}) *pathshorten()*
6773 Shorten directory names in the path {expr} and return the 6805 Shorten directory names in the path {expr} and return the
6774 result. The tail, the file name, is kept as-is. The other 6806 result. The tail, the file name, is kept as-is. The other
9687 xor({expr}, {expr}) *xor()* 9719 xor({expr}, {expr}) *xor()*
9688 Bitwise XOR on the two arguments. The arguments are converted 9720 Bitwise XOR on the two arguments. The arguments are converted
9689 to a number. A List, Dict or Float argument causes an error. 9721 to a number. A List, Dict or Float argument causes an error.
9690 Example: > 9722 Example: >
9691 :let bits = xor(bits, 0x80) 9723 :let bits = xor(bits, 0x80)
9724 < Can also be used as a |method|: >
9725 :let bits = bits->xor(0x80)
9692 < 9726 <
9693 9727
9694 9728
9695 *feature-list* 9729 *feature-list*
9696 There are four types of features: 9730 There are four types of features: