From a74e4946de074d2916e3d6004f7fa1810d12dda9 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sun, 4 Aug 2019 17:35:53 +0200 Subject: patch 8.1.1809: more functions can be used as a method Problem: More functions can be used as a method. Solution: Add has_key(), split(), str2list(), etc. --- runtime/doc/eval.txt | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index c86d13d53..296b3a157 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3575,9 +3575,10 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()* When {comp} is a string then the number of not overlapping occurrences of {expr} is returned. Zero is returned when {expr} is an empty string. + Can also be used as a |method|: > mylist->count(val) - +< *cscope_connection()* cscope_connection([{num} , {dbpath} [, {prepend}]]) Checks for the existence of a |cscope| connection. If no @@ -5408,6 +5409,9 @@ has_key({dict}, {key}) *has_key()* The result is a Number, which is 1 if |Dictionary| {dict} has an entry with key {key}. Zero otherwise. + Can also be used as a |method|: > + mydict->has_key(key) + haslocaldir([{winnr} [, {tabnr}]]) *haslocaldir()* The result is a Number: 1 when the window has set a local directory via |:lcd| @@ -8294,6 +8298,8 @@ split({expr} [, {pattern} [, {keepempty}]]) *split()* :let items = split(line, ':', 1) < The opposite function is |join()|. + Can also be used as a |method|: > + GetString()->split() sqrt({expr}) *sqrt()* Return the non-negative square root of Float {expr} as a @@ -8337,12 +8343,19 @@ str2list({expr} [, {utf8}]) *str2list()* properly: > str2list("á") returns [97, 769] +< Can also be used as a |method|: > + GetString()->str2list() + + str2nr({expr} [, {base}]) *str2nr()* Convert string {expr} to a number. {base} is the conversion base, it can be 2, 8, 10 or 16. + When {base} is omitted base 10 is used. This also means that a leading zero doesn't cause octal conversion to be used, as - with the default String to Number conversion. + with the default String to Number conversion. Example: > + let nr = str2nr('123') +< When {base} is 16 a leading "0x" or "0X" is ignored. With a different base the result will be zero. Similarly, when {base} is 8 a leading "0" is ignored, and when {base} is 2 a @@ -8470,6 +8483,9 @@ strlen({expr}) The result is a Number, which is the length of the String |strchars()|. Also see |len()|, |strdisplaywidth()| and |strwidth()|. + Can also be used as a |method|: > + GetString()->strlen() + strpart({src}, {start} [, {len}]) *strpart()* The result is a String, which is part of {src}, starting from byte {start}, with the byte length {len}. @@ -8514,6 +8530,9 @@ strtrans({expr}) *strtrans()* < This displays a newline in register a as "^@" instead of starting a new line. + Can also be used as a |method|: > + GetString()->strtrans() + strwidth({expr}) *strwidth()* The result is a Number, which is the number of display cells String {expr} occupies. A Tab character is counted as one @@ -8522,6 +8541,9 @@ strwidth({expr}) *strwidth()* Ambiguous, this function's return value depends on 'ambiwidth'. Also see |strlen()|, |strdisplaywidth()| and |strchars()|. + Can also be used as a |method|: > + GetString()->strwidth() + submatch({nr} [, {list}]) *submatch()* *E935* Only for an expression in a |:substitute| command or substitute() function. @@ -8589,6 +8611,9 @@ substitute({expr}, {pat}, {sub}, {flags}) *substitute()* |submatch()| returns. Example: > :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g') +< Can also be used as a |method|: > + GetString()->substitute(pat, sub, flags) + swapinfo({fname}) *swapinfo()* The result is a dictionary, which holds information about the swapfile {fname}. The available fields are: @@ -8674,12 +8699,19 @@ synIDattr({synID}, {what} [, {mode}]) *synIDattr()* cursor): > :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") < + Can also be used as a |method|: > + :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") + + synIDtrans({synID}) *synIDtrans()* The result is a Number, which is the translated syntax ID of {synID}. This is the syntax group ID of what is being used to highlight the character. Highlight links given with ":highlight link" are followed. + Can also be used as a |method|: > + :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") + synconcealed({lnum}, {col}) *synconcealed()* The result is a List with currently three items: 1. The first item in the list is 0 if the character at the @@ -8784,6 +8816,9 @@ system({expr} [, {input}]) *system()* *E677* Unlike ":!cmd" there is no automatic check for changed files. Use |:checktime| to force a check. + Can also be used as a |method|: > + :echo GetCmd()->system() + systemlist({expr} [, {input}]) *systemlist()* Same as |system()|, but returns a |List| with lines (parts of @@ -8794,6 +8829,9 @@ systemlist({expr} [, {input}]) *systemlist()* Returns an empty string on error. + Can also be used as a |method|: > + :echo GetCmd()->systemlist() + tabpagebuflist([{arg}]) *tabpagebuflist()* The result is a |List|, where each item is the number of the -- cgit v1.2.1