To: vim_dev@googlegroups.com Subject: Patch 7.4.1992 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1992 Problem: Values for true and false can be confusing. Solution: Update the documentation. Add a test. Make v:true evaluate to TRUE for a non-zero-arg. Files: runtime/doc/eval.txt, src/eval.c, src/Makefile, src/testdir/test_true_false.vim, src/testdir/test_alot.vim *** ../vim-7.4.1991/runtime/doc/eval.txt 2016-07-04 22:29:22.075959951 +0200 --- runtime/doc/eval.txt 2016-07-06 23:02:11.054595527 +0200 *************** *** 98,111 **** To avoid a leading zero to cause octal conversion, or for using a different base, use |str2nr()|. For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE. ! Note that in the command > :if "foo" ! "foo" is converted to 0, which means FALSE. To test for a non-empty string, ! use empty(): > :if !empty("foo") < *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* List, Dictionary, Funcref and Job types are not automatically converted. --- 100,128 ---- To avoid a leading zero to cause octal conversion, or for using a different base, use |str2nr()|. + *TRUE* *FALSE* For boolean operators Numbers are used. Zero is FALSE, non-zero is TRUE. + You can also use |v:false| and |v:true|. When TRUE is returned from a + function it is the Number one, FALSE is the number zero. ! Note that in the command: > :if "foo" ! :" NOT executed ! "foo" is converted to 0, which means FALSE. If the string starts with a ! non-zero number it means TRUE: > ! :if "8foo" ! :" executed ! To test for a non-empty string, use empty(): > :if !empty("foo") < + *non-zero-arg* + Function arguments often behave slightly different from |TRUE|: If the + argument is present and it evaluates to a non-zero Number, |v:true| or a + non-empty String, then the value is considere to be TRUE. + Note that " " and "0" are also non-empty strings, thus cause the mode to be + cleared. A List, Dictionary or Float is not a Number or String, thus + evaluates to FALSE. + *E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910* *E913* List, Dictionary, Funcref and Job types are not automatically converted. *************** *** 695,701 **** expr2 ? expr1 : expr1 The expression before the '?' is evaluated to a number. If it evaluates to ! non-zero, the result is the value of the expression between the '?' and ':', otherwise the result is the value of the expression after the ':'. Example: > :echo lnum == 1 ? "top" : lnum --- 709,715 ---- expr2 ? expr1 : expr1 The expression before the '?' is evaluated to a number. If it evaluates to ! |TRUE|, the result is the value of the expression between the '?' and ':', otherwise the result is the value of the expression after the ':'. Example: > :echo lnum == 1 ? "top" : lnum *************** *** 723,734 **** The "||" and "&&" operators take one argument on each side. The arguments are (converted to) Numbers. The result is: ! input output ~ ! n1 n2 n1 || n2 n1 && n2 ~ ! zero zero zero zero ! zero non-zero non-zero zero ! non-zero zero non-zero zero ! non-zero non-zero non-zero non-zero The operators can be concatenated, for example: > --- 737,748 ---- The "||" and "&&" operators take one argument on each side. The arguments are (converted to) Numbers. The result is: ! input output ~ ! n1 n2 n1 || n2 n1 && n2 ~ ! |FALSE| |FALSE| |FALSE| |FALSE| ! |FALSE| |TRUE| |TRUE| |FALSE| ! |TRUE| |FALSE| |TRUE| |FALSE| ! |TRUE| |TRUE| |TRUE| |TRUE| The operators can be concatenated, for example: > *************** *** 744,751 **** let a = 1 echo a || b ! This is valid even if there is no variable called "b" because "a" is non-zero, ! so the result must be non-zero. Similarly below: > echo exists("b") && b == "yes" --- 758,765 ---- let a = 1 echo a || b ! This is valid even if there is no variable called "b" because "a" is |TRUE|, ! so the result must be |TRUE|. Similarly below: > echo exists("b") && b == "yes" *************** *** 796,817 **** equal" and "is" can be used. This compares the key/values of the |Dictionary| recursively. Ignoring case means case is ignored when comparing item values. ! *E693* *E694* ! A |Funcref| can only be compared with a |Funcref| and only "equal" and "not ! equal" can be used. Case is never ignored. When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the expressions are referring to the same |List| or |Dictionary| instance. A copy of a |List| is different from the original |List|. When using "is" without a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot" equivalent to using "not equal". Except that a different type means the ! values are different: "4 == '4'" is true, "4 is '4'" is false and "0 is []" is ! false and not an error. "is#"/"isnot#" and "is?"/"isnot?" can be used to match ! and ignore case. When comparing a String with a Number, the String is converted to a Number, ! and the comparison is done on Numbers. This means that "0 == 'x'" is TRUE, ! because 'x' converted to a Number is zero. When comparing two Strings, this is done with strcmp() or stricmp(). This results in the mathematical difference (comparing byte values), not --- 810,849 ---- equal" and "is" can be used. This compares the key/values of the |Dictionary| recursively. Ignoring case means case is ignored when comparing item values. ! *E694* ! A |Funcref| can only be compared with a |Funcref| and only "equal", "not ! equal", "is" and "isnot" can be used. Case is never ignored. Whether ! arguments or a Dictionary are bound (with a partial) matters. The ! Dictionaries must also be equal (or the same, in case of "is") and the ! arguments must be equal (or the same). ! ! To compare Funcrefs to see if they refer to the same function, ignoring bound ! Dictionary and arguments, use |get()| to get the function name: > ! if get(Part1, 'name') == get(Part2, 'name') ! " Part1 and Part2 refer to the same function When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the expressions are referring to the same |List| or |Dictionary| instance. A copy of a |List| is different from the original |List|. When using "is" without a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot" equivalent to using "not equal". Except that a different type means the ! values are different: > ! echo 4 == '4' ! 1 ! echo 4 is '4' ! 0 ! echo 0 is [] ! 0 ! "is#"/"isnot#" and "is?"/"isnot?" can be used to match and ignore case. When comparing a String with a Number, the String is converted to a Number, ! and the comparison is done on Numbers. This means that: > ! echo 0 == 'x' ! 1 ! because 'x' converted to a Number is zero. However: > ! echo [0] == ['x'] ! 0 ! Inside a List or Dictionary this conversion is not used. When comparing two Strings, this is done with strcmp() or stricmp(). This results in the mathematical difference (comparing byte values), not *************** *** 889,895 **** - expr7 unary minus *expr-unary--* + expr7 unary plus *expr-unary-+* ! For '!' non-zero becomes zero, zero becomes one. For '-' the sign of the number is changed. For '+' the number is unchanged. --- 926,932 ---- - expr7 unary minus *expr-unary--* + expr7 unary plus *expr-unary-+* ! For '!' |TRUE| becomes |FALSE|, |FALSE| becomes |TRUE| (one). For '-' the sign of the number is changed. For '+' the number is unchanged. *************** *** 1846,1854 **** browse({save}, {title}, {initdir}, {default}) String put up a file requester browsedir({title}, {initdir}) String put up a directory requester ! bufexists({expr}) Number TRUE if buffer {expr} exists ! buflisted({expr}) Number TRUE if buffer {expr} is listed ! bufloaded({expr}) Number TRUE if buffer {expr} is loaded bufname({expr}) String Name of the buffer {expr} bufnr({expr} [, {create}]) Number Number of the buffer {expr} bufwinid({expr}) Number window ID of buffer {expr} --- 1898,1906 ---- browse({save}, {title}, {initdir}, {default}) String put up a file requester browsedir({title}, {initdir}) String put up a directory requester ! bufexists({expr}) Number |TRUE| if buffer {expr} exists ! buflisted({expr}) Number |TRUE| if buffer {expr} is listed ! bufloaded({expr}) Number |TRUE| if buffer {expr} is loaded bufname({expr}) String Name of the buffer {expr} bufnr({expr} [, {create}]) Number Number of the buffer {expr} bufwinid({expr}) Number window ID of buffer {expr} *************** *** 1903,1926 **** cursor({list}) Number move cursor to position in {list} deepcopy({expr} [, {noref}]) any make a full copy of {expr} delete({fname} [, {flags}]) Number delete the file or directory {fname} ! did_filetype() Number TRUE if FileType autocommand event used diff_filler({lnum}) Number diff filler lines about {lnum} diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} ! empty({expr}) Number TRUE if {expr} is empty escape({string}, {chars}) String escape {chars} in {string} with '\' eval({string}) any evaluate {string} into its value ! eventhandler() Number TRUE if inside an event handler executable({expr}) Number 1 if executable {expr} exists exepath({expr}) String full path of the command {expr} ! exists({expr}) Number TRUE if {expr} exists extend({expr1}, {expr2} [, {expr3}]) List/Dict insert items of {expr2} into {expr1} exp({expr}) Float exponential of {expr} expand({expr} [, {nosuf} [, {list}]]) any expand special keywords in {expr} feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer ! filereadable({file}) Number TRUE if {file} is a readable file ! filewritable({file}) Number TRUE if {file} is a writable file filter({expr}, {string}) List/Dict remove items from {expr} where {string} is 0 finddir({name}[, {path}[, {count}]]) --- 1955,1978 ---- cursor({list}) Number move cursor to position in {list} deepcopy({expr} [, {noref}]) any make a full copy of {expr} delete({fname} [, {flags}]) Number delete the file or directory {fname} ! did_filetype() Number |TRUE| if FileType autocmd event used diff_filler({lnum}) Number diff filler lines about {lnum} diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col} ! empty({expr}) Number |TRUE| if {expr} is empty escape({string}, {chars}) String escape {chars} in {string} with '\' eval({string}) any evaluate {string} into its value ! eventhandler() Number |TRUE| if inside an event handler executable({expr}) Number 1 if executable {expr} exists exepath({expr}) String full path of the command {expr} ! exists({expr}) Number |TRUE| if {expr} exists extend({expr1}, {expr2} [, {expr3}]) List/Dict insert items of {expr2} into {expr1} exp({expr}) Float exponential of {expr} expand({expr} [, {nosuf} [, {list}]]) any expand special keywords in {expr} feedkeys({string} [, {mode}]) Number add key sequence to typeahead buffer ! filereadable({file}) Number |TRUE| if {file} is a readable file ! filewritable({file}) Number |TRUE| if {file} is a writable file filter({expr}, {string}) List/Dict remove items from {expr} where {string} is 0 finddir({name}[, {path}[, {count}]]) *************** *** 1985,2001 **** glob2regpat({expr}) String convert a glob pat into a search pat globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) String do glob({expr}) for all dirs in {path} ! has({feature}) Number TRUE if feature {feature} supported ! has_key({dict}, {key}) Number TRUE if {dict} has entry {key} haslocaldir([{winnr} [, {tabnr}]]) ! Number TRUE if the window executed |:lcd| hasmapto({what} [, {mode} [, {abbr}]]) ! Number TRUE if mapping to {what} exists histadd({history}, {item}) String add an item to a history histdel({history} [, {item}]) String remove an item from a history histget({history} [, {index}]) String get the item {index} from a history histnr({history}) Number highest index of a history ! hlexists({name}) Number TRUE if highlight group {name} exists hlID({name}) Number syntax ID of highlight group {name} hostname() String name of the machine Vim is running on iconv({expr}, {from}, {to}) String convert encoding of {expr} --- 2037,2053 ---- glob2regpat({expr}) String convert a glob pat into a search pat globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) String do glob({expr}) for all dirs in {path} ! has({feature}) Number |TRUE| if feature {feature} supported ! has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key} haslocaldir([{winnr} [, {tabnr}]]) ! Number |TRUE| if the window executed |:lcd| hasmapto({what} [, {mode} [, {abbr}]]) ! Number |TRUE| if mapping to {what} exists histadd({history}, {item}) String add an item to a history histdel({history} [, {item}]) String remove an item from a history histget({history} [, {index}]) String get the item {index} from a history histnr({history}) Number highest index of a history ! hlexists({name}) Number |TRUE| if highlight group {name} exists hlID({name}) Number syntax ID of highlight group {name} hostname() String name of the machine Vim is running on iconv({expr}, {from}, {to}) String convert encoding of {expr} *************** *** 2012,2020 **** inputsecret({prompt} [, {text}]) String like input() but hiding the text insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] invert({expr}) Number bitwise invert ! isdirectory({directory}) Number TRUE if {directory} is a directory ! islocked({expr}) Number TRUE if {expr} is locked ! isnan({expr}) Number TRUE if {expr} is NaN items({dict}) List key-value pairs in {dict} job_getchannel({job}) Channel get the channel handle for {job} job_info({job}) Dict get information about {job} --- 2064,2072 ---- inputsecret({prompt} [, {text}]) String like input() but hiding the text insert({list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}] invert({expr}) Number bitwise invert ! isdirectory({directory}) Number |TRUE| if {directory} is a directory ! islocked({expr}) Number |TRUE| if {expr} is locked ! isnan({expr}) Number |TRUE| if {expr} is NaN items({dict}) List key-value pairs in {dict} job_getchannel({job}) Channel get the channel handle for {job} job_info({job}) Dict get information about {job} *************** *** 2199,2204 **** --- 2251,2257 ---- test_null_list() List null value for testing test_null_partial() Funcref null value for testing test_null_string() String null value for testing + test_settime({expr}) none set current time for testing timer_start({time}, {callback} [, {options}]) Number create a timer timer_stop({timer}) none stop a timer *************** *** 2400,2406 **** assert_true({actual} [, {msg}]) *assert_true()* When {actual} is not true an error message is added to |v:errors|, like with |assert_equal()|. ! A value is true when it is a non-zero number. When {actual} is not a number the assert fails. When {msg} is omitted an error in the form "Expected True but got {actual}" is produced. --- 2453,2459 ---- assert_true({actual} [, {msg}]) *assert_true()* When {actual} is not true an error message is added to |v:errors|, like with |assert_equal()|. ! A value is TRUE when it is a non-zero number. When {actual} is not a number the assert fails. When {msg} is omitted an error in the form "Expected True but got {actual}" is produced. *************** *** 2445,2453 **** *browse()* browse({save}, {title}, {initdir}, {default}) Put up a file requester. This only works when "has("browse")" ! returns non-zero (only in some GUI versions). The input fields are: ! {save} when non-zero, select file to write {title} title for the requester {initdir} directory to start browsing in {default} default file name --- 2498,2506 ---- *browse()* browse({save}, {title}, {initdir}, {default}) Put up a file requester. This only works when "has("browse")" ! returns |TRUE| (only in some GUI versions). The input fields are: ! {save} when |TRUE|, select file to write {title} title for the requester {initdir} directory to start browsing in {default} default file name *************** *** 2457,2463 **** *browsedir()* browsedir({title}, {initdir}) Put up a directory requester. This only works when ! "has("browse")" returns non-zero (only in some GUI versions). On systems where a directory browser is not supported a file browser is used. In that case: select a file in the directory to be used. --- 2510,2516 ---- *browsedir()* browsedir({title}, {initdir}) Put up a directory requester. This only works when ! "has("browse")" returns |TRUE| (only in some GUI versions). On systems where a directory browser is not supported a file browser is used. In that case: select a file in the directory to be used. *************** *** 2468,2474 **** browsing is not possible, an empty string is returned. bufexists({expr}) *bufexists()* ! The result is a Number, which is non-zero if a buffer called {expr} exists. If the {expr} argument is a number, buffer numbers are used. If the {expr} argument is a string it must match a buffer name --- 2521,2527 ---- browsing is not possible, an empty string is returned. bufexists({expr}) *bufexists()* ! The result is a Number, which is |TRUE| if a buffer called {expr} exists. If the {expr} argument is a number, buffer numbers are used. If the {expr} argument is a string it must match a buffer name *************** *** 2490,2501 **** Obsolete name: buffer_exists(). buflisted({expr}) *buflisted()* ! The result is a Number, which is non-zero if a buffer called {expr} exists and is listed (has the 'buflisted' option set). The {expr} argument is used like with |bufexists()|. bufloaded({expr}) *bufloaded()* ! The result is a Number, which is non-zero if a buffer called {expr} exists and is loaded (shown in a window or hidden). The {expr} argument is used like with |bufexists()|. --- 2543,2554 ---- Obsolete name: buffer_exists(). buflisted({expr}) *buflisted()* ! The result is a Number, which is |TRUE| if a buffer called {expr} exists and is listed (has the 'buflisted' option set). The {expr} argument is used like with |bufexists()|. bufloaded({expr}) *bufloaded()* ! The result is a Number, which is |TRUE| if a buffer called {expr} exists and is loaded (shown in a window or hidden). The {expr} argument is used like with |bufexists()|. *************** *** 2742,2748 **** complete_check() *complete_check()* Check for a key typed while looking for completion matches. This is to be used when looking for matches takes some time. ! Returns non-zero when searching for matches is to be aborted, zero otherwise. Only to be used by the function specified with the 'completefunc' option. --- 2800,2806 ---- complete_check() *complete_check()* Check for a key typed while looking for completion matches. This is to be used when looking for matches takes some time. ! Returns |TRUE| when searching for matches is to be aborted, zero otherwise. Only to be used by the function specified with the 'completefunc' option. *************** *** 3018,3024 **** in |List| or |Dictionary| {comp}. If {start} is given then start with the item with this index. {start} can only be used with a |List|. ! When {ic} is given and it's non-zero then case is ignored. *cscope_connection()* --- 3060,3066 ---- in |List| or |Dictionary| {comp}. If {start} is given then start with the item with this index. {start} can only be used with a |List|. ! When {ic} is given and it's |TRUE| then case is ignored. *cscope_connection()* *************** *** 3128,3134 **** when the line number is in a variable. *did_filetype()* ! did_filetype() Returns non-zero when autocommands are being executed and the FileType event has been triggered at least once. Can be used to avoid triggering the FileType event again in the scripts that detect the file type. |FileType| --- 3174,3180 ---- when the line number is in a variable. *did_filetype()* ! did_filetype() Returns |TRUE| when autocommands are being executed and the FileType event has been triggered at least once. Can be used to avoid triggering the FileType event again in the scripts that detect the file type. |FileType| *************** *** 3220,3230 **** Note that the current directory is used when {expr} starts with "./", which may be a problem for Vim: > echo exepath(v:progpath) ! < If {expr} cannot be found in $PATH or is not executable then an empty string is returned. *exists()* ! exists({expr}) The result is a Number, which is non-zero if {expr} is defined, zero otherwise. The {expr} argument is a string, which contains one of these: &option-name Vim option (only checks if it exists, --- 3267,3277 ---- Note that the current directory is used when {expr} starts with "./", which may be a problem for Vim: > echo exepath(v:progpath) ! < If {expr} cannot be found in $PATH or is not executable then an empty string is returned. *exists()* ! exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined, zero otherwise. The {expr} argument is a string, which contains one of these: &option-name Vim option (only checks if it exists, *************** *** 3320,3326 **** Expand wildcards and the following special keywords in {expr}. 'wildignorecase' applies. ! If {list} is given and it is non-zero, a List will be returned. Otherwise the result is a String and when there are several matches, they are separated by characters. [Note: in version 5.0 a space was used, which caused problems when a --- 3368,3374 ---- Expand wildcards and the following special keywords in {expr}. 'wildignorecase' applies. ! If {list} is given and it is |TRUE|, a List will be returned. Otherwise the result is a String and when there are several matches, they are separated by characters. [Note: in version 5.0 a space was used, which caused problems when a *************** *** 3379,3385 **** When {expr} does not start with '%', '#' or '<', it is expanded like a file name is expanded on the command line. 'suffixes' and 'wildignore' are used, unless the optional ! {nosuf} argument is given and it is non-zero. Names for non-existing files are included. The "**" item can be used to search in a directory tree. For example, to find all "README" files in the current directory and below: > --- 3427,3433 ---- When {expr} does not start with '%', '#' or '<', it is expanded like a file name is expanded on the command line. 'suffixes' and 'wildignore' are used, unless the optional ! {nosuf} argument is given and it is |TRUE|. Names for non-existing files are included. The "**" item can be used to search in a directory tree. For example, to find all "README" files in the current directory and below: > *************** *** 3457,3469 **** similar to using ":normal!". You can call feedkeys() several times without 'x' and then one time with 'x' (possibly with an empty {string}) to execute all the ! typeahead. Return value is always 0. filereadable({file}) *filereadable()* ! The result is a Number, which is TRUE when a file with the name {file} exists, and can be read. If {file} doesn't exist, ! or is a directory, the result is FALSE. {file} is any expression, which is used as a String. If you don't care about the file being readable you can use |glob()|. --- 3508,3527 ---- similar to using ":normal!". You can call feedkeys() several times without 'x' and then one time with 'x' (possibly with an empty {string}) to execute all the ! typeahead. Note that when Vim ends in Insert mode it ! will behave as if is typed, to avoid getting ! stuck, waiting for a character to be typed before the ! script continues. ! '!' When used with 'x' will not end Insert mode. Can be ! used in a test when a timer is set to exit Insert mode ! a little later. Useful for testing CursorHoldI. ! Return value is always 0. filereadable({file}) *filereadable()* ! The result is a Number, which is |TRUE| when a file with the name {file} exists, and can be read. If {file} doesn't exist, ! or is a directory, the result is |FALSE|. {file} is any expression, which is used as a String. If you don't care about the file being readable you can use |glob()|. *************** *** 3502,3508 **** If {expr2} is a |Funcref| it must take two arguments: 1. the key or the index of the current item. 2. the value of the current item. ! The function must return TRUE if the item should be kept. Example that keeps the odd items of a list: > func Odd(idx, val) return a:idx % 2 == 1 --- 3560,3566 ---- If {expr2} is a |Funcref| it must take two arguments: 1. the key or the index of the current item. 2. the value of the current item. ! The function must return |TRUE| if the item should be kept. Example that keeps the odd items of a list: > func Odd(idx, val) return a:idx % 2 == 1 *************** *** 4073,4085 **** bufname() to get the name lnum line number in the buffer (first line is 1) col column number (first column is 1) ! vcol non-zero: "col" is visual column ! zero: "col" is byte index nr error number pattern search pattern used to locate the error text description of the error type type of the error, 'E', '1', etc. ! valid non-zero: recognized error message When there is no error list or it's empty an empty list is returned. Quickfix list entries with non-existing buffer --- 4200,4212 ---- bufname() to get the name lnum line number in the buffer (first line is 1) col column number (first column is 1) ! vcol |TRUE|: "col" is visual column ! |FALSE|: "col" is byte index nr error number pattern search pattern used to locate the error text description of the error type type of the error, 'E', '1', etc. ! valid |TRUE|: recognized error message When there is no error list or it's empty an empty list is returned. Quickfix list entries with non-existing buffer *************** *** 4097,4112 **** The result is a String, which is the contents of register {regname}. Example: > :let cliptext = getreg('*') ! < getreg('=') returns the last evaluated value of the expression register. (For use in maps.) getreg('=', 1) returns the expression itself, so that it can be restored with |setreg()|. For other registers the extra argument is ignored, thus you can always give it. ! If {list} is present and non-zero result type is changed to ! |List|. Each list item is one text line. Use it if you care about zero bytes possibly present inside register: without third argument both NLs and zero bytes are represented as NLs (see |NL-used-for-Nul|). If {regname} is not specified, |v:register| is used. --- 4224,4244 ---- The result is a String, which is the contents of register {regname}. Example: > :let cliptext = getreg('*') ! < When {regname} was not set the result is a empty string. ! ! getreg('=') returns the last evaluated value of the expression register. (For use in maps.) getreg('=', 1) returns the expression itself, so that it can be restored with |setreg()|. For other registers the extra argument is ignored, thus you can always give it. ! ! If {list} is present and |TRUE|, the result type is changed ! to |List|. Each list item is one text line. Use it if you care about zero bytes possibly present inside register: without third argument both NLs and zero bytes are represented as NLs (see |NL-used-for-Nul|). + When the register was not set an empty list is returned. + If {regname} is not specified, |v:register| is used. *************** *** 4167,4191 **** :let list_is_on = getwinvar(2, '&list') :echo "myvar = " . getwinvar(1, 'myvar') < ! glob({expr} [, {nosuf} [, {list}]]) *glob()* Expand the file wildcards in {expr}. See |wildcards| for the use of special characters. ! Unless the optional {nosuf} argument is given and is non-zero, the 'suffixes' and 'wildignore' options apply: Names matching one of the patterns in 'wildignore' will be skipped and 'suffixes' affect the ordering of matches. 'wildignorecase' always applies. ! When {list} is present and it is non-zero the result is a List with all matching files. The advantage of using a List is, you also get filenames containing newlines correctly. Otherwise the result is a String and when there are several matches, they are separated by characters. If the expansion fails, the result is an empty String or List. A name for a non-existing file is not included. A symbolic link is only included if it points to an existing file. For most systems backticks can be used to get files names from any external command. Example: > --- 4299,4326 ---- :let list_is_on = getwinvar(2, '&list') :echo "myvar = " . getwinvar(1, 'myvar') < ! glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()* Expand the file wildcards in {expr}. See |wildcards| for the use of special characters. ! Unless the optional {nosuf} argument is given and is |TRUE|, the 'suffixes' and 'wildignore' options apply: Names matching one of the patterns in 'wildignore' will be skipped and 'suffixes' affect the ordering of matches. 'wildignorecase' always applies. ! When {list} is present and it is |TRUE| the result is a List with all matching files. The advantage of using a List is, you also get filenames containing newlines correctly. Otherwise the result is a String and when there are several matches, they are separated by characters. If the expansion fails, the result is an empty String or List. + A name for a non-existing file is not included. A symbolic link is only included if it points to an existing file. + However, when the {alllinks} argument is present and it is + |TRUE| then all symbolic links are included. For most systems backticks can be used to get files names from any external command. Example: > *************** *** 4220,4237 **** If the expansion fails for one of the directories, there is no error message. ! Unless the optional {nosuf} argument is given and is non-zero, the 'suffixes' and 'wildignore' options apply: Names matching one of the patterns in 'wildignore' will be skipped and 'suffixes' affect the ordering of matches. ! When {list} is present and it is non-zero the result is a List with all matching files. The advantage of using a List is, you also get filenames containing newlines correctly. Otherwise the result is a String and when there are several matches, they are separated by characters. Example: > :echo globpath(&rtp, "syntax/c.vim", 0, 1) < The "**" item can be used to search in a directory tree. For example, to find all "README.txt" files in the directories in 'runtimepath' and below: > --- 4357,4376 ---- If the expansion fails for one of the directories, there is no error message. ! Unless the optional {nosuf} argument is given and is |TRUE|, the 'suffixes' and 'wildignore' options apply: Names matching one of the patterns in 'wildignore' will be skipped and 'suffixes' affect the ordering of matches. ! When {list} is present and it is |TRUE| the result is a List with all matching files. The advantage of using a List is, you also get filenames containing newlines correctly. Otherwise the result is a String and when there are several matches, they are separated by characters. Example: > :echo globpath(&rtp, "syntax/c.vim", 0, 1) < + {alllinks} is used as with |glob()|. + The "**" item can be used to search in a directory tree. For example, to find all "README.txt" files in the directories in 'runtimepath' and below: > *************** *** 4266,4272 **** contains {what} in somewhere in the rhs (what it is mapped to) and this mapping exists in one of the modes indicated by {mode}. ! When {abbr} is there and it is non-zero use abbreviations instead of mappings. Don't forget to specify Insert and/or Command-line mode. Both the global mappings and the mappings local to the current --- 4405,4411 ---- contains {what} in somewhere in the rhs (what it is mapped to) and this mapping exists in one of the modes indicated by {mode}. ! When {abbr} is there and it is |TRUE| use abbreviations instead of mappings. Don't forget to specify Insert and/or Command-line mode. Both the global mappings and the mappings local to the current *************** *** 4425,4431 **** is not used here, case always matters. If {start} is given then start looking at the item with index {start} (may be negative for an item relative to the end). ! When {ic} is given and it is non-zero, ignore case. Otherwise case must match. -1 is returned when {expr} is not found in {list}. Example: > --- 4564,4570 ---- is not used here, case always matters. If {start} is given then start looking at the item with index {start} (may be negative for an item relative to the end). ! When {ic} is given and it is |TRUE|, ignore case. Otherwise case must match. -1 is returned when {expr} is not found in {list}. Example: > *************** *** 4553,4565 **** :let bits = invert(bits) isdirectory({directory}) *isdirectory()* ! The result is a Number, which is non-zero when a directory with the name {directory} exists. If {directory} doesn't ! exist, or isn't a directory, the result is FALSE. {directory} is any expression, which is used as a String. islocked({expr}) *islocked()* *E786* ! The result is a Number, which is non-zero when {expr} is the name of a locked variable. {expr} must be the name of a variable, |List| item or |Dictionary| entry, not the variable itself! Example: > --- 4692,4704 ---- :let bits = invert(bits) isdirectory({directory}) *isdirectory()* ! The result is a Number, which is |TRUE| when a directory with the name {directory} exists. If {directory} doesn't ! exist, or isn't a directory, the result is |FALSE|. {directory} is any expression, which is used as a String. islocked({expr}) *islocked()* *E786* ! The result is a Number, which is |TRUE| when {expr} is the name of a locked variable. {expr} must be the name of a variable, |List| item or |Dictionary| entry, not the variable itself! Example: > *************** *** 4572,4578 **** message. Use |exists()| to check for existence. isnan({expr}) *isnan()* ! Return non-zero if {expr} is a float with value NaN. > echo isnan(0.0 / 0.0) < 1 ~ --- 4711,4717 ---- message. Use |exists()| to check for existence. isnan({expr}) *isnan()* ! Return |TRUE| if {expr} is a float with value NaN. > echo isnan(0.0 / 0.0) < 1 ~ *************** *** 4986,4995 **** "" Normal, Visual and Operator-pending When {mode} is omitted, the modes for "" are used. ! When {abbr} is there and it is non-zero use abbreviations instead of mappings. ! When {dict} is there and it is non-zero return a dictionary containing all the information of the mapping with the following items: "lhs" The {lhs} of the mapping. --- 5129,5138 ---- "" Normal, Visual and Operator-pending When {mode} is omitted, the modes for "" are used. ! When {abbr} is there and it is |TRUE| use abbreviations instead of mappings. ! When {dict} is there and it is |TRUE| return a dictionary containing all the information of the mapping with the following items: "lhs" The {lhs} of the mapping. *************** *** 5018,5024 **** Check if there is a mapping that matches with {name} in mode {mode}. See |maparg()| for {mode} and special names in {name}. ! When {abbr} is there and it is non-zero use abbreviations instead of mappings. A match happens with a mapping that starts with {name} and with a mapping which is equal to the start of {name}. --- 5163,5169 ---- Check if there is a mapping that matches with {name} in mode {mode}. See |maparg()| for {mode} and special names in {name}. ! When {abbr} is there and it is |TRUE| use abbreviations instead of mappings. A match happens with a mapping that starts with {name} and with a mapping which is equal to the start of {name}. *************** *** 7142,7148 **** *test_disable_char_avail()* test_disable_char_avail({expr}) When {expr} is 1 the internal char_avail() function will ! return FALSE. When {expr} is 0 the char_avail() function will function normally. Only use this for a test where typeahead causes the test not to work. E.g., to trigger the CursorMovedI autocommand event. --- 7308,7314 ---- *test_disable_char_avail()* test_disable_char_avail({expr}) When {expr} is 1 the internal char_avail() function will ! return |FALSE|. When {expr} is 0 the char_avail() function will function normally. Only use this for a test where typeahead causes the test not to work. E.g., to trigger the CursorMovedI autocommand event. *************** *** 7173,7178 **** --- 7339,7349 ---- test_null_string() *test_null_string()* Return a String that is null. Only useful for testing. + test_settime({expr}) *test_settime()* + Set the time Vim uses internally. Currently only used for + timestamps in the history, as they are used in viminfo. + {expr} must evaluate to a number. When the value is zero the + normal behavior is restored. *timer_start()* timer_start({time}, {callback} [, {options}]) *************** *** 7371,7386 **** Visual mode that was used. If Visual mode is active, use |mode()| to get the Visual mode (e.g., in a |:vmap|). - *non-zero-arg* If [expr] is supplied and it evaluates to a non-zero Number or a non-empty String, then the Visual mode will be cleared and ! the old value is returned. Note that " " and "0" are also ! non-empty strings, thus cause the mode to be cleared. A List, ! Dictionary or Float is not a Number or String, thus does not ! cause the mode to be cleared. wildmenumode() *wildmenumode()* ! Returns non-zero when the wildmenu is active and zero otherwise. See 'wildmenu' and 'wildmode'. This can be used in mappings to handle the 'wildcharm' option gracefully. (Makes only sense with |mapmode-c| mappings). --- 7557,7568 ---- Visual mode that was used. If Visual mode is active, use |mode()| to get the Visual mode (e.g., in a |:vmap|). If [expr] is supplied and it evaluates to a non-zero Number or a non-empty String, then the Visual mode will be cleared and ! the old value is returned. See |non-zero-arg|. wildmenumode() *wildmenumode()* ! Returns |TRUE| when the wildmenu is active and |FALSE| otherwise. See 'wildmenu' and 'wildmode'. This can be used in mappings to handle the 'wildcharm' option gracefully. (Makes only sense with |mapmode-c| mappings). *** ../vim-7.4.1991/src/eval.c 2016-07-04 22:29:22.079959892 +0200 --- src/eval.c 2016-07-07 12:17:53.034795186 +0200 *************** *** 9414,9419 **** --- 9414,9421 ---- { return ((argvars[0].v_type == VAR_NUMBER && argvars[0].vval.v_number != 0) + || (argvars[0].v_type == VAR_SPECIAL + && argvars[0].vval.v_number == VVAL_TRUE) || (argvars[0].v_type == VAR_STRING && argvars[0].vval.v_string != NULL && *argvars[0].vval.v_string != NUL)); *************** *** 16350,16356 **** buf[1] = NUL; buf[2] = NUL; ! if (VIsual_active) { if (VIsual_select) buf[0] = VIsual_mode + 's' - 'v'; --- 16352,16364 ---- buf[1] = NUL; buf[2] = NUL; ! if (time_for_testing == 93784) ! { ! /* Testing the two-character code. */ ! buf[0] = 'x'; ! buf[1] = '!'; ! } ! else if (VIsual_active) { if (VIsual_select) buf[0] = VIsual_mode + 's' - 'v'; *** ../vim-7.4.1991/src/Makefile 2016-07-04 22:29:22.075959951 +0200 --- src/Makefile 2016-07-06 22:21:45.150411710 +0200 *************** *** 2068,2078 **** test_statusline \ test_syn_attr \ test_syntax \ - test_usercommands \ test_tabline \ test_tagjump \ test_timers \ test_undolevels \ test_unlet \ test_viminfo \ test_viml \ --- 2068,2079 ---- test_statusline \ test_syn_attr \ test_syntax \ test_tabline \ test_tagjump \ test_timers \ + test_true_false \ test_undolevels \ + test_usercommands \ test_unlet \ test_viminfo \ test_viml \ *** ../vim-7.4.1991/src/testdir/test_true_false.vim 2016-07-07 14:45:00.443725190 +0200 --- src/testdir/test_true_false.vim 2016-07-07 14:36:11.339567260 +0200 *************** *** 0 **** --- 1,125 ---- + " Test behavior of boolean-like values. + + " Test what is explained at ":help TRUE" and ":help FALSE". + func Test_if() + if v:false + call assert_true(false, 'v:false is false') + endif + if 0 + call assert_true(false, 'zero is false') + endif + if "0" + call assert_true(false, 'zero string is false') + endif + if "foo" + call assert_true(false, 'foo is false') + endif + if " " + call assert_true(false, 'space is false') + endif + if empty("foo") + call assert_true(false, 'foo is not empty') + endif + + if v:true + else + call assert_true(false, 'v:true is true') + endif + if 1 + else + call assert_true(false, 'one is true') + endif + if "1" + else + call assert_true(false, 'one string is true') + endif + if "1foo" + else + call assert_true(false, 'one in string is true') + endif + + call assert_fails('if [1]', 'E745') + call assert_fails('if {1: 1}', 'E728') + call assert_fails('if function("string")', 'E703') + call assert_fails('if 1.3")', 'E805') + endfunc + + function Try_arg_true_false(expr, false_val, true_val) + for v in ['v:false', '0', '"0"', '"foo"', '" "'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:false_val, r, 'result for ' . v . ' is not ' . string(a:false_val) . ' but ' . string(r)) + endfor + for v in ['v:true', '1', '"1"', '"1foo"'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:true_val, r, 'result for ' . v . ' is not ' . string(a:true_val) . ' but ' . string(r)) + endfor + endfunc + + " Test using TRUE or FALSE values for an argument. + func Test_true_false_arg() + call Try_arg_true_false('count(["a", "A"], "a", %v%)', 1, 2) + + set wildignore=*.swp + call Try_arg_true_false('expand("foo.swp", %v%)', "", "foo.swp") + call Try_arg_true_false('expand("foo.vim", 0, %v%)', "foo.vim", ["foo.vim"]) + + call setreg('a', ['x', 'y']) + call Try_arg_true_false('getreg("a", 1, %v%)', "x\ny\n", ['x', 'y']) + + set wildignore=*.vim + call Try_arg_true_false('glob("runtest.vim", %v%)', "", "runtest.vim") + set wildignore=*.swp + call Try_arg_true_false('glob("runtest.vim", 0, %v%)', "runtest.vim", ["runtest.vim"]) + if has('unix') + silent !ln -s doesntexit Xlink + call Try_arg_true_false('glob("Xlink", 0, 0, %v%)', "", "Xlink") + silent !rm Xlink + endif + + set wildignore=*.vim + call Try_arg_true_false('globpath(".", "runtest.vim", %v%)', "", "./runtest.vim") + set wildignore=*.swp + call Try_arg_true_false('globpath(".", "runtest.vim", 0, %v%)', "./runtest.vim", ["./runtest.vim"]) + if has('unix') + silent !ln -s doesntexit Xlink + call Try_arg_true_false('globpath(".", "Xlink", 0, 0, %v%)', "", "./Xlink") + silent !rm Xlink + endif + endfunc + + function Try_arg_non_zero(expr, false_val, true_val) + for v in ['v:false', '0', '[1]', '{2:3}', '3.4'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:false_val, r, 'result for ' . v . ' is not ' . a:false_val . ' but ' . r) + endfor + for v in ['v:true', '1', '" "', '"0"'] + let r = eval(substitute(a:expr, '%v%', v, '')) + call assert_equal(a:true_val, r, 'result for ' . v . ' is not ' . a:true_val . ' but ' . r) + endfor + endfunc + + + " Test using non-zero-arg for an argument. + func Test_non_zero_arg() + call test_settime(93784) + call Try_arg_non_zero("mode(%v%)", 'x', 'x!') + call test_settime(0) + + call Try_arg_non_zero("shellescape('foo%', %v%)", "'foo%'", "'foo\\%'") + + " visualmode() needs to be called twice to check + for v in [v:false, 0, [1], {2:3}, 3.4] + normal vv + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . string(v) . ' is not "v" but ' . r) + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . string(v) . ' is not "v" but ' . r) + endfor + for v in [v:true, 1, " ", "0"] + normal vv + let r = visualmode(v) + call assert_equal('v', r, 'result for ' . v . ' is not "v" but ' . r) + let r = visualmode(v) + call assert_equal('', r, 'result for ' . v . ' is not "" but ' . r) + endfor + endfunc *** ../vim-7.4.1991/src/testdir/test_alot.vim 2016-07-04 22:29:22.079959892 +0200 --- src/testdir/test_alot.vim 2016-07-06 22:22:48.789474845 +0200 *************** *** 33,38 **** --- 33,39 ---- source test_tabline.vim source test_tagjump.vim source test_timers.vim + source test_true_false.vim source test_undolevels.vim source test_unlet.vim source test_window_cmd.vim *** ../vim-7.4.1991/src/version.c 2016-07-07 14:29:05.965872369 +0200 --- src/version.c 2016-07-07 14:45:07.975613563 +0200 *************** *** 760,761 **** --- 760,763 ---- { /* Add new patch number below this line */ + /**/ + 1992, /**/ -- hundred-and-one symptoms of being an internet addict: 217. Your sex life has drastically improved...so what if it's only cyber-sex! /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///