Added conditional assignment operator

2006-12-11 Thread Eggum, DavidX S
Bram,

I've added the conditional assignment operator to the source code. Granted, we 
aren't adding features now and it isn't on the TODO list, but it was simple to 
add and it's pretty useful. Please set it on the shelf until we are ready for 
it. Thanks!

*** runtime/doc/eval.txt2006/12/11 21:03:57 1.1
--- runtime/doc/eval.txt2006/12/11 21:04:31
***
*** 5633,5638 
--- 5633,5648 
from the {expr}.  If {var-name} didn't exist yet, it
is created.
  
+ :let {var-name} ?= {expr1}*:let?=*
+   Set internal variable {var-name} to the result of the
+   expression {expr1} only if {var-name} doesn't exist.
+   This statement: 
+   let foo ?= bar
+  is equivalent to this: 
+   if !exists(foo)
+  let foo = bar
+   endif
+ 
  :let {var-name}[{idx}] = {expr1}  *E689*
Set a list item to the result of the expression
{expr1}.  {var-name} must refer to a list and {idx}
***
*** 5665,5670 
--- 5675,5684 
Append {expr1} to the environment variable {env-name}.
If the environment variable didn't exist yet this
works like =.
+ :let ${env-name} ?= {expr1}
+   Set environment variable {env-name} to the result of
+   the expression {expr1} if {env-name} doesn't exist.
+   The type is always String.
  
  :let @{reg-name} = {expr1}*:let-register* *:[EMAIL 
PROTECTED]
Write the result of the expression {expr1} in register
*** src/eval.c  2006/12/08 23:24:51 1.1
--- src/eval.c  2006/12/11 20:49:52
***
*** 1717,1724 
op[1] = NUL;
if (expr  argend)
{
!   if (vim_strchr((char_u *)+-., expr[-1]) != NULL)
!   op[0] = expr[-1];   /* +=, -= or .= */
}
expr = skipwhite(expr + 1);
  
--- 1717,1724 
op[1] = NUL;
if (expr  argend)
{
!   if (vim_strchr((char_u *)+-.?, expr[-1]) != NULL)
!   op[0] = expr[-1];   /* +=, -=, .= or ?= */
}
expr = skipwhite(expr + 1);
  
***
*** 1744,1751 
   * Assign the typevalue tv to the variable or variables at arg_start.
   * Handles both var with any type and [var, var; var] with a list type.
   * When nextchars is not NULL it points to a string with characters that
!  * must appear after the variable(s).  Use +, - or . for add, subtract
!  * or concatenate.
   * Returns OK or FAIL;
   */
  static int
--- 1744,1751 
   * Assign the typevalue tv to the variable or variables at arg_start.
   * Handles both var with any type and [var, var; var] with a list type.
   * When nextchars is not NULL it points to a string with characters that
!  * must appear after the variable(s).  Use +, -, . or ? for add,
!  * subtract, concatenate or conditional assign.
   * Returns OK or FAIL;
   */
  static int
***
*** 2125,2131 
  typval_T  *tv;/* value to assign to variable */
  int   copy;   /* copy value from tv */
  char_u*endchars;  /* valid chars after variable name  or NULL */
! char_u*op;/* +, -, .  or NULL*/
  {
  int   c1;
  char_u*name;
--- 2125,2131 
  typval_T  *tv;/* value to assign to variable */
  int   copy;   /* copy value from tv */
  char_u*endchars;  /* valid chars after variable name  or NULL */
! char_u*op;/* +, -, ., ?  or NULL*/
  {
  int   c1;
  char_u*name;
***
*** 2158,2171 
c1 = name[len];
name[len] = NUL;
p = get_tv_string_chk(tv);
!   if (p != NULL  op != NULL  *op == '.')
{
int mustfree = FALSE;
char_u  *s = vim_getenv(name, mustfree);
  
if (s != NULL)
{
!   p = tofree = concat_str(s, p);
if (mustfree)
vim_free(s);
}
--- 2158,2174 
c1 = name[len];
name[len] = NUL;
p = get_tv_string_chk(tv);
!   if (p != NULL  op != NULL  (*op == '.' || *op == '?'))
{
int mustfree = FALSE;
char_u  *s = vim_getenv(name, mustfree);
  
if (s != NULL)
{
!   if (*op == '?')
!   p = NULL;
!   

Re: Added conditional assignment operator

2006-12-11 Thread Bram Moolenaar

Dave Eggum wrote:

 I've added the conditional assignment operator to the source code.
 Granted, we aren't adding features now and it isn't on the TODO list,
 but it was simple to add and it's pretty useful. Please set it on the
 shelf until we are ready for it. Thanks!

Thanks.  I'll let people play with this and put it in the todo list
somewhere.  Bug fixing goes first!

-- 
Men may not be seen publicly in any kind of strapless gown.
[real standing law in Florida, United States of America]

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\download, build and distribute -- http://www.A-A-P.org///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///