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.txt        2006/12/11 21:03:57     1.1
--- runtime/doc/eval.txt        2006/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;
!                       else
!                           p = tofree = concat_str(s, p);
                        if (mustfree)
                            vim_free(s);
                    }
***************
*** 2647,2653 ****
  /*
   * Set a variable that was parsed by get_lval() to "rettv".
   * "endp" points to just after the parsed name.
!  * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" or "=" for "=".
   */
      static void
  set_var_lval(lp, endp, rettv, copy, op)
--- 2650,2656 ----
  /*
   * Set a variable that was parsed by get_lval() to "rettv".
   * "endp" points to just after the parsed name.
!  * "op" is NULL, "+" for "+=", "-" for "-=", "." for ".=" "?" for "?=" or "=" 
for "=".
   */
      static void
  set_var_lval(lp, endp, rettv, copy, op)
***************
*** 2671,2678 ****
            {
                typval_T tv;
  
!               /* handle +=, -= and .= */
!               if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
                                                             &tv, TRUE) == OK)
                {
                    if (tv_op(&tv, rettv, op) == OK)
--- 2674,2686 ----
            {
                typval_T tv;
  
!               /* handle +=, -=, .= and ?= */
!               if (*op == '?')
!               {
!                   if( get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name), &tv, 
FALSE) == FAIL)
!                       set_var(lp->ll_name, rettv, copy);
!               }
!               else if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
                                                             &tv, TRUE) == OK)
                {
                    if (tv_op(&tv, rettv, op) == OK)



What is love?
"Love is when a girl puts on perfume and a boy puts on shaving cologne and they 
go out and smell each other."

Karl - age 5

Reply via email to