8b9a1c
To: vim_dev@googlegroups.com
8b9a1c
Subject: Patch 7.4.149
8b9a1c
Fcc: outbox
8b9a1c
From: Bram Moolenaar <Bram@moolenaar.net>
8b9a1c
Mime-Version: 1.0
8b9a1c
Content-Type: text/plain; charset=UTF-8
8b9a1c
Content-Transfer-Encoding: 8bit
8b9a1c
------------
8b9a1c
8b9a1c
Patch 7.4.149
8b9a1c
Problem:    Get E685 error when assigning a function to an autoload variable.
8b9a1c
	    (Yukihiro Nakadaira)
8b9a1c
Solution:   Instead of having a global no_autoload variable, pass an autoload
8b9a1c
	    flag down to where it is used. (ZyX)
8b9a1c
Files:	    src/eval.c, src/testdir/test55.in, src/testdir/test55.ok,
8b9a1c
	    src/testdir/test60.in, src/testdir/test60.ok,
8b9a1c
	    src/testdir/sautest/autoload/footest.vim
8b9a1c
8b9a1c
8b9a1c
*** ../vim-7.4.148/src/eval.c	2014-01-06 06:18:44.000000000 +0100
8b9a1c
--- src/eval.c	2014-01-14 15:14:05.000000000 +0100
8b9a1c
***************
8b9a1c
*** 125,133 ****
8b9a1c
   */
8b9a1c
  static hashtab_T	compat_hashtab;
8b9a1c
  
8b9a1c
- /* When using exists() don't auto-load a script. */
8b9a1c
- static int		no_autoload = FALSE;
8b9a1c
- 
8b9a1c
  /*
8b9a1c
   * When recursively copying lists and dicts we need to remember which ones we
8b9a1c
   * have done to avoid endless recursiveness.  This unique ID is used for that.
8b9a1c
--- 125,130 ----
8b9a1c
***************
8b9a1c
*** 156,161 ****
8b9a1c
--- 153,163 ----
8b9a1c
  /* Values for trans_function_name() argument: */
8b9a1c
  #define TFN_INT		1	/* internal function name OK */
8b9a1c
  #define TFN_QUIET	2	/* no error messages */
8b9a1c
+ #define TFN_NO_AUTOLOAD	4	/* do not use script autoloading */
8b9a1c
+ 
8b9a1c
+ /* Values for get_lval() flags argument: */
8b9a1c
+ #define GLV_QUIET	TFN_QUIET	/* no error messages */
8b9a1c
+ #define GLV_NO_AUTOLOAD	TFN_NO_AUTOLOAD	/* do not use script autoloading */
8b9a1c
  
8b9a1c
  /*
8b9a1c
   * Structure to hold info for a user function.
8b9a1c
***************
8b9a1c
*** 390,396 ****
8b9a1c
  static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg, int *first));
8b9a1c
  static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op));
8b9a1c
  static int check_changedtick __ARGS((char_u *arg));
8b9a1c
! static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int quiet, int fne_flags));
8b9a1c
  static void clear_lval __ARGS((lval_T *lp));
8b9a1c
  static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op));
8b9a1c
  static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u  *op));
8b9a1c
--- 392,398 ----
8b9a1c
  static char_u *list_arg_vars __ARGS((exarg_T *eap, char_u *arg, int *first));
8b9a1c
  static char_u *ex_let_one __ARGS((char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op));
8b9a1c
  static int check_changedtick __ARGS((char_u *arg));
8b9a1c
! static char_u *get_lval __ARGS((char_u *name, typval_T *rettv, lval_T *lp, int unlet, int skip, int flags, int fne_flags));
8b9a1c
  static void clear_lval __ARGS((lval_T *lp));
8b9a1c
  static void set_var_lval __ARGS((lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op));
8b9a1c
  static int tv_op __ARGS((typval_T *tv1, typval_T *tv2, char_u  *op));
8b9a1c
***************
8b9a1c
*** 770,776 ****
8b9a1c
  static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
8b9a1c
  static int eval_isnamec __ARGS((int c));
8b9a1c
  static int eval_isnamec1 __ARGS((int c));
8b9a1c
! static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose));
8b9a1c
  static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
8b9a1c
  static typval_T *alloc_tv __ARGS((void));
8b9a1c
  static typval_T *alloc_string_tv __ARGS((char_u *string));
8b9a1c
--- 772,778 ----
8b9a1c
  static char_u * make_expanded_name __ARGS((char_u *in_start, char_u *expr_start, char_u *expr_end, char_u *in_end));
8b9a1c
  static int eval_isnamec __ARGS((int c));
8b9a1c
  static int eval_isnamec1 __ARGS((int c));
8b9a1c
! static int get_var_tv __ARGS((char_u *name, int len, typval_T *rettv, int verbose, int no_autoload));
8b9a1c
  static int handle_subscript __ARGS((char_u **arg, typval_T *rettv, int evaluate, int verbose));
8b9a1c
  static typval_T *alloc_tv __ARGS((void));
8b9a1c
  static typval_T *alloc_string_tv __ARGS((char_u *string));
8b9a1c
***************
8b9a1c
*** 781,788 ****
8b9a1c
  static char_u *get_tv_string __ARGS((typval_T *varp));
8b9a1c
  static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf));
8b9a1c
  static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf));
8b9a1c
! static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp));
8b9a1c
! static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, int htname, char_u *varname, int writing));
8b9a1c
  static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname));
8b9a1c
  static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val));
8b9a1c
  static void delete_var __ARGS((hashtab_T *ht, hashitem_T *hi));
8b9a1c
--- 783,790 ----
8b9a1c
  static char_u *get_tv_string __ARGS((typval_T *varp));
8b9a1c
  static char_u *get_tv_string_buf __ARGS((typval_T *varp, char_u *buf));
8b9a1c
  static char_u *get_tv_string_buf_chk __ARGS((typval_T *varp, char_u *buf));
8b9a1c
! static dictitem_T *find_var __ARGS((char_u *name, hashtab_T **htp, int no_autoload));
8b9a1c
! static dictitem_T *find_var_in_ht __ARGS((hashtab_T *ht, int htname, char_u *varname, int no_autoload));
8b9a1c
  static hashtab_T *find_var_ht __ARGS((char_u *name, char_u **varname));
8b9a1c
  static void vars_clear_ext __ARGS((hashtab_T *ht, int free_val));
8b9a1c
  static void delete_var __ARGS((hashtab_T *ht, hashitem_T *hi));
8b9a1c
***************
8b9a1c
*** 1059,1065 ****
8b9a1c
      ga_init2(&redir_ga, (int)sizeof(char), 500);
8b9a1c
  
8b9a1c
      /* Parse the variable name (can be a dict or list entry). */
8b9a1c
!     redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, FALSE,
8b9a1c
  							     FNE_CHECK_START);
8b9a1c
      if (redir_endp == NULL || redir_lval->ll_name == NULL || *redir_endp != NUL)
8b9a1c
      {
8b9a1c
--- 1061,1067 ----
8b9a1c
      ga_init2(&redir_ga, (int)sizeof(char), 500);
8b9a1c
  
8b9a1c
      /* Parse the variable name (can be a dict or list entry). */
8b9a1c
!     redir_endp = get_lval(redir_varname, NULL, redir_lval, FALSE, FALSE, 0,
8b9a1c
  							     FNE_CHECK_START);
8b9a1c
      if (redir_endp == NULL || redir_lval->ll_name == NULL || *redir_endp != NUL)
8b9a1c
      {
8b9a1c
***************
8b9a1c
*** 1150,1156 ****
8b9a1c
  	    /* Call get_lval() again, if it's inside a Dict or List it may
8b9a1c
  	     * have changed. */
8b9a1c
  	    redir_endp = get_lval(redir_varname, NULL, redir_lval,
8b9a1c
! 					FALSE, FALSE, FALSE, FNE_CHECK_START);
8b9a1c
  	    if (redir_endp != NULL && redir_lval->ll_name != NULL)
8b9a1c
  		set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
8b9a1c
  	    clear_lval(redir_lval);
8b9a1c
--- 1152,1158 ----
8b9a1c
  	    /* Call get_lval() again, if it's inside a Dict or List it may
8b9a1c
  	     * have changed. */
8b9a1c
  	    redir_endp = get_lval(redir_varname, NULL, redir_lval,
8b9a1c
! 					FALSE, FALSE, 0, FNE_CHECK_START);
8b9a1c
  	    if (redir_endp != NULL && redir_lval->ll_name != NULL)
8b9a1c
  		set_var_lval(redir_lval, redir_endp, &tv, FALSE, (char_u *)".");
8b9a1c
  	    clear_lval(redir_lval);
8b9a1c
***************
8b9a1c
*** 2239,2245 ****
8b9a1c
  	    {
8b9a1c
  		if (tofree != NULL)
8b9a1c
  		    name = tofree;
8b9a1c
! 		if (get_var_tv(name, len, &tv, TRUE) == FAIL)
8b9a1c
  		    error = TRUE;
8b9a1c
  		else
8b9a1c
  		{
8b9a1c
--- 2241,2247 ----
8b9a1c
  	    {
8b9a1c
  		if (tofree != NULL)
8b9a1c
  		    name = tofree;
8b9a1c
! 		if (get_var_tv(name, len, &tv, TRUE, FALSE) == FAIL)
8b9a1c
  		    error = TRUE;
8b9a1c
  		else
8b9a1c
  		{
8b9a1c
***************
8b9a1c
*** 2474,2480 ****
8b9a1c
      {
8b9a1c
  	lval_T	lv;
8b9a1c
  
8b9a1c
! 	p = get_lval(arg, tv, &lv, FALSE, FALSE, FALSE, FNE_CHECK_START);
8b9a1c
  	if (p != NULL && lv.ll_name != NULL)
8b9a1c
  	{
8b9a1c
  	    if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL)
8b9a1c
--- 2476,2482 ----
8b9a1c
      {
8b9a1c
  	lval_T	lv;
8b9a1c
  
8b9a1c
! 	p = get_lval(arg, tv, &lv, FALSE, FALSE, 0, FNE_CHECK_START);
8b9a1c
  	if (p != NULL && lv.ll_name != NULL)
8b9a1c
  	{
8b9a1c
  	    if (endchars != NULL && vim_strchr(endchars, *skipwhite(p)) == NULL)
8b9a1c
***************
8b9a1c
*** 2519,2536 ****
8b9a1c
   * "unlet" is TRUE for ":unlet": slightly different behavior when something is
8b9a1c
   * wrong; must end in space or cmd separator.
8b9a1c
   *
8b9a1c
   * Returns a pointer to just after the name, including indexes.
8b9a1c
   * When an evaluation error occurs "lp->ll_name" is NULL;
8b9a1c
   * Returns NULL for a parsing error.  Still need to free items in "lp"!
8b9a1c
   */
8b9a1c
      static char_u *
8b9a1c
! get_lval(name, rettv, lp, unlet, skip, quiet, fne_flags)
8b9a1c
      char_u	*name;
8b9a1c
      typval_T	*rettv;
8b9a1c
      lval_T	*lp;
8b9a1c
      int		unlet;
8b9a1c
      int		skip;
8b9a1c
!     int		quiet;	    /* don't give error messages */
8b9a1c
      int		fne_flags;  /* flags for find_name_end() */
8b9a1c
  {
8b9a1c
      char_u	*p;
8b9a1c
--- 2521,2542 ----
8b9a1c
   * "unlet" is TRUE for ":unlet": slightly different behavior when something is
8b9a1c
   * wrong; must end in space or cmd separator.
8b9a1c
   *
8b9a1c
+  * flags:
8b9a1c
+  *  GLV_QUIET:       do not give error messages
8b9a1c
+  *  GLV_NO_AUTOLOAD: do not use script autoloading
8b9a1c
+  *
8b9a1c
   * Returns a pointer to just after the name, including indexes.
8b9a1c
   * When an evaluation error occurs "lp->ll_name" is NULL;
8b9a1c
   * Returns NULL for a parsing error.  Still need to free items in "lp"!
8b9a1c
   */
8b9a1c
      static char_u *
8b9a1c
! get_lval(name, rettv, lp, unlet, skip, flags, fne_flags)
8b9a1c
      char_u	*name;
8b9a1c
      typval_T	*rettv;
8b9a1c
      lval_T	*lp;
8b9a1c
      int		unlet;
8b9a1c
      int		skip;
8b9a1c
!     int		flags;	    /* GLV_ values */
8b9a1c
      int		fne_flags;  /* flags for find_name_end() */
8b9a1c
  {
8b9a1c
      char_u	*p;
8b9a1c
***************
8b9a1c
*** 2544,2549 ****
8b9a1c
--- 2550,2556 ----
8b9a1c
      char_u	*key = NULL;
8b9a1c
      int		len;
8b9a1c
      hashtab_T	*ht;
8b9a1c
+     int		quiet = flags & GLV_QUIET;
8b9a1c
  
8b9a1c
      /* Clear everything in "lp". */
8b9a1c
      vim_memset(lp, 0, sizeof(lval_T));
8b9a1c
***************
8b9a1c
*** 2591,2597 ****
8b9a1c
  
8b9a1c
      cc = *p;
8b9a1c
      *p = NUL;
8b9a1c
!     v = find_var(lp->ll_name, &ht;;
8b9a1c
      if (v == NULL && !quiet)
8b9a1c
  	EMSG2(_(e_undefvar), lp->ll_name);
8b9a1c
      *p = cc;
8b9a1c
--- 2598,2604 ----
8b9a1c
  
8b9a1c
      cc = *p;
8b9a1c
      *p = NUL;
8b9a1c
!     v = find_var(lp->ll_name, &ht, flags & GLV_NO_AUTOLOAD);
8b9a1c
      if (v == NULL && !quiet)
8b9a1c
  	EMSG2(_(e_undefvar), lp->ll_name);
8b9a1c
      *p = cc;
8b9a1c
***************
8b9a1c
*** 2904,2910 ****
8b9a1c
  
8b9a1c
  		/* handle +=, -= and .= */
8b9a1c
  		if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
8b9a1c
! 							     &tv, TRUE) == OK)
8b9a1c
  		{
8b9a1c
  		    if (tv_op(&tv, rettv, op) == OK)
8b9a1c
  			set_var(lp->ll_name, &tv, FALSE);
8b9a1c
--- 2911,2917 ----
8b9a1c
  
8b9a1c
  		/* handle +=, -= and .= */
8b9a1c
  		if (get_var_tv(lp->ll_name, (int)STRLEN(lp->ll_name),
8b9a1c
! 						      &tv, TRUE, FALSE) == OK)
8b9a1c
  		{
8b9a1c
  		    if (tv_op(&tv, rettv, op) == OK)
8b9a1c
  			set_var(lp->ll_name, &tv, FALSE);
8b9a1c
***************
8b9a1c
*** 3556,3562 ****
8b9a1c
      do
8b9a1c
      {
8b9a1c
  	/* Parse the name and find the end. */
8b9a1c
! 	name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, FALSE,
8b9a1c
  							     FNE_CHECK_START);
8b9a1c
  	if (lv.ll_name == NULL)
8b9a1c
  	    error = TRUE;	    /* error but continue parsing */
8b9a1c
--- 3563,3569 ----
8b9a1c
      do
8b9a1c
      {
8b9a1c
  	/* Parse the name and find the end. */
8b9a1c
! 	name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0,
8b9a1c
  							     FNE_CHECK_START);
8b9a1c
  	if (lv.ll_name == NULL)
8b9a1c
  	    error = TRUE;	    /* error but continue parsing */
8b9a1c
***************
8b9a1c
*** 3709,3715 ****
8b9a1c
  	    ret = FAIL;
8b9a1c
  	else
8b9a1c
  	{
8b9a1c
! 	    di = find_var(lp->ll_name, NULL);
8b9a1c
  	    if (di == NULL)
8b9a1c
  		ret = FAIL;
8b9a1c
  	    else
8b9a1c
--- 3716,3722 ----
8b9a1c
  	    ret = FAIL;
8b9a1c
  	else
8b9a1c
  	{
8b9a1c
! 	    di = find_var(lp->ll_name, NULL, TRUE);
8b9a1c
  	    if (di == NULL)
8b9a1c
  		ret = FAIL;
8b9a1c
  	    else
8b9a1c
***************
8b9a1c
*** 5179,5185 ****
8b9a1c
  		}
8b9a1c
  	    }
8b9a1c
  	    else if (evaluate)
8b9a1c
! 		ret = get_var_tv(s, len, rettv, TRUE);
8b9a1c
  	    else
8b9a1c
  		ret = OK;
8b9a1c
  	}
8b9a1c
--- 5186,5192 ----
8b9a1c
  		}
8b9a1c
  	    }
8b9a1c
  	    else if (evaluate)
8b9a1c
! 		ret = get_var_tv(s, len, rettv, TRUE, FALSE);
8b9a1c
  	    else
8b9a1c
  		ret = OK;
8b9a1c
  	}
8b9a1c
***************
8b9a1c
*** 8284,8290 ****
8b9a1c
  
8b9a1c
      cc = name[*lenp];
8b9a1c
      name[*lenp] = NUL;
8b9a1c
!     v = find_var(name, NULL);
8b9a1c
      name[*lenp] = cc;
8b9a1c
      if (v != NULL && v->di_tv.v_type == VAR_FUNC)
8b9a1c
      {
8b9a1c
--- 8291,8297 ----
8b9a1c
  
8b9a1c
      cc = name[*lenp];
8b9a1c
      name[*lenp] = NUL;
8b9a1c
!     v = find_var(name, NULL, FALSE);
8b9a1c
      name[*lenp] = cc;
8b9a1c
      if (v != NULL && v->di_tv.v_type == VAR_FUNC)
8b9a1c
      {
8b9a1c
***************
8b9a1c
*** 10039,10046 ****
8b9a1c
      int		n = FALSE;
8b9a1c
      int		len = 0;
8b9a1c
  
8b9a1c
-     no_autoload = TRUE;
8b9a1c
- 
8b9a1c
      p = get_tv_string(&argvars[0]);
8b9a1c
      if (*p == '$')			/* environment variable */
8b9a1c
      {
8b9a1c
--- 10046,10051 ----
8b9a1c
***************
8b9a1c
*** 10091,10097 ****
8b9a1c
  	{
8b9a1c
  	    if (tofree != NULL)
8b9a1c
  		name = tofree;
8b9a1c
! 	    n = (get_var_tv(name, len, &tv, FALSE) == OK);
8b9a1c
  	    if (n)
8b9a1c
  	    {
8b9a1c
  		/* handle d.key, l[idx], f(expr) */
8b9a1c
--- 10096,10102 ----
8b9a1c
  	{
8b9a1c
  	    if (tofree != NULL)
8b9a1c
  		name = tofree;
8b9a1c
! 	    n = (get_var_tv(name, len, &tv, FALSE, TRUE) == OK);
8b9a1c
  	    if (n)
8b9a1c
  	    {
8b9a1c
  		/* handle d.key, l[idx], f(expr) */
8b9a1c
***************
8b9a1c
*** 10107,10114 ****
8b9a1c
      }
8b9a1c
  
8b9a1c
      rettv->vval.v_number = n;
8b9a1c
- 
8b9a1c
-     no_autoload = FALSE;
8b9a1c
  }
8b9a1c
  
8b9a1c
  #ifdef FEAT_FLOAT
8b9a1c
--- 10112,10117 ----
8b9a1c
***************
8b9a1c
*** 13344,13351 ****
8b9a1c
      dictitem_T	*di;
8b9a1c
  
8b9a1c
      rettv->vval.v_number = -1;
8b9a1c
!     end = get_lval(get_tv_string(&argvars[0]), NULL, &lv, FALSE, FALSE, FALSE,
8b9a1c
! 							     FNE_CHECK_START);
8b9a1c
      if (end != NULL && lv.ll_name != NULL)
8b9a1c
      {
8b9a1c
  	if (*end != NUL)
8b9a1c
--- 13347,13354 ----
8b9a1c
      dictitem_T	*di;
8b9a1c
  
8b9a1c
      rettv->vval.v_number = -1;
8b9a1c
!     end = get_lval(get_tv_string(&argvars[0]), NULL, &lv, FALSE, FALSE,
8b9a1c
! 					GLV_NO_AUTOLOAD, FNE_CHECK_START);
8b9a1c
      if (end != NULL && lv.ll_name != NULL)
8b9a1c
      {
8b9a1c
  	if (*end != NUL)
8b9a1c
***************
8b9a1c
*** 13358,13364 ****
8b9a1c
  		    rettv->vval.v_number = 1;	    /* always locked */
8b9a1c
  		else
8b9a1c
  		{
8b9a1c
! 		    di = find_var(lv.ll_name, NULL);
8b9a1c
  		    if (di != NULL)
8b9a1c
  		    {
8b9a1c
  			/* Consider a variable locked when:
8b9a1c
--- 13361,13367 ----
8b9a1c
  		    rettv->vval.v_number = 1;	    /* always locked */
8b9a1c
  		else
8b9a1c
  		{
8b9a1c
! 		    di = find_var(lv.ll_name, NULL, TRUE);
8b9a1c
  		    if (di != NULL)
8b9a1c
  		    {
8b9a1c
  			/* Consider a variable locked when:
8b9a1c
***************
8b9a1c
*** 19774,19784 ****
8b9a1c
   * Return OK or FAIL.
8b9a1c
   */
8b9a1c
      static int
8b9a1c
! get_var_tv(name, len, rettv, verbose)
8b9a1c
      char_u	*name;
8b9a1c
      int		len;		/* length of "name" */
8b9a1c
      typval_T	*rettv;		/* NULL when only checking existence */
8b9a1c
      int		verbose;	/* may give error message */
8b9a1c
  {
8b9a1c
      int		ret = OK;
8b9a1c
      typval_T	*tv = NULL;
8b9a1c
--- 19777,19788 ----
8b9a1c
   * Return OK or FAIL.
8b9a1c
   */
8b9a1c
      static int
8b9a1c
! get_var_tv(name, len, rettv, verbose, no_autoload)
8b9a1c
      char_u	*name;
8b9a1c
      int		len;		/* length of "name" */
8b9a1c
      typval_T	*rettv;		/* NULL when only checking existence */
8b9a1c
      int		verbose;	/* may give error message */
8b9a1c
+     int		no_autoload;	/* do not use script autoloading */
8b9a1c
  {
8b9a1c
      int		ret = OK;
8b9a1c
      typval_T	*tv = NULL;
8b9a1c
***************
8b9a1c
*** 19805,19811 ****
8b9a1c
       */
8b9a1c
      else
8b9a1c
      {
8b9a1c
! 	v = find_var(name, NULL);
8b9a1c
  	if (v != NULL)
8b9a1c
  	    tv = &v->di_tv;
8b9a1c
      }
8b9a1c
--- 19809,19815 ----
8b9a1c
       */
8b9a1c
      else
8b9a1c
      {
8b9a1c
! 	v = find_var(name, NULL, no_autoload);
8b9a1c
  	if (v != NULL)
8b9a1c
  	    tv = &v->di_tv;
8b9a1c
      }
8b9a1c
***************
8b9a1c
*** 20207,20215 ****
8b9a1c
   * hashtab_T used.
8b9a1c
   */
8b9a1c
      static dictitem_T *
8b9a1c
! find_var(name, htp)
8b9a1c
      char_u	*name;
8b9a1c
      hashtab_T	**htp;
8b9a1c
  {
8b9a1c
      char_u	*varname;
8b9a1c
      hashtab_T	*ht;
8b9a1c
--- 20211,20220 ----
8b9a1c
   * hashtab_T used.
8b9a1c
   */
8b9a1c
      static dictitem_T *
8b9a1c
! find_var(name, htp, no_autoload)
8b9a1c
      char_u	*name;
8b9a1c
      hashtab_T	**htp;
8b9a1c
+     int		no_autoload;
8b9a1c
  {
8b9a1c
      char_u	*varname;
8b9a1c
      hashtab_T	*ht;
8b9a1c
***************
8b9a1c
*** 20219,20225 ****
8b9a1c
  	*htp = ht;
8b9a1c
      if (ht == NULL)
8b9a1c
  	return NULL;
8b9a1c
!     return find_var_in_ht(ht, *name, varname, htp != NULL);
8b9a1c
  }
8b9a1c
  
8b9a1c
  /*
8b9a1c
--- 20224,20230 ----
8b9a1c
  	*htp = ht;
8b9a1c
      if (ht == NULL)
8b9a1c
  	return NULL;
8b9a1c
!     return find_var_in_ht(ht, *name, varname, no_autoload || htp != NULL);
8b9a1c
  }
8b9a1c
  
8b9a1c
  /*
8b9a1c
***************
8b9a1c
*** 20227,20237 ****
8b9a1c
   * Returns NULL if not found.
8b9a1c
   */
8b9a1c
      static dictitem_T *
8b9a1c
! find_var_in_ht(ht, htname, varname, writing)
8b9a1c
      hashtab_T	*ht;
8b9a1c
      int		htname;
8b9a1c
      char_u	*varname;
8b9a1c
!     int		writing;
8b9a1c
  {
8b9a1c
      hashitem_T	*hi;
8b9a1c
  
8b9a1c
--- 20232,20242 ----
8b9a1c
   * Returns NULL if not found.
8b9a1c
   */
8b9a1c
      static dictitem_T *
8b9a1c
! find_var_in_ht(ht, htname, varname, no_autoload)
8b9a1c
      hashtab_T	*ht;
8b9a1c
      int		htname;
8b9a1c
      char_u	*varname;
8b9a1c
!     int		no_autoload;
8b9a1c
  {
8b9a1c
      hashitem_T	*hi;
8b9a1c
  
8b9a1c
***************
8b9a1c
*** 20263,20269 ****
8b9a1c
  	 * worked find the variable again.  Don't auto-load a script if it was
8b9a1c
  	 * loaded already, otherwise it would be loaded every time when
8b9a1c
  	 * checking if a function name is a Funcref variable. */
8b9a1c
! 	if (ht == &globvarht && !writing)
8b9a1c
  	{
8b9a1c
  	    /* Note: script_autoload() may make "hi" invalid. It must either
8b9a1c
  	     * be obtained again or not used. */
8b9a1c
--- 20268,20274 ----
8b9a1c
  	 * worked find the variable again.  Don't auto-load a script if it was
8b9a1c
  	 * loaded already, otherwise it would be loaded every time when
8b9a1c
  	 * checking if a function name is a Funcref variable. */
8b9a1c
! 	if (ht == &globvarht && !no_autoload)
8b9a1c
  	{
8b9a1c
  	    /* Note: script_autoload() may make "hi" invalid. It must either
8b9a1c
  	     * be obtained again or not used. */
8b9a1c
***************
8b9a1c
*** 20343,20349 ****
8b9a1c
  {
8b9a1c
      dictitem_T	*v;
8b9a1c
  
8b9a1c
!     v = find_var(name, NULL);
8b9a1c
      if (v == NULL)
8b9a1c
  	return NULL;
8b9a1c
      return get_tv_string(&v->di_tv);
8b9a1c
--- 20348,20354 ----
8b9a1c
  {
8b9a1c
      dictitem_T	*v;
8b9a1c
  
8b9a1c
!     v = find_var(name, NULL, FALSE);
8b9a1c
      if (v == NULL)
8b9a1c
  	return NULL;
8b9a1c
      return get_tv_string(&v->di_tv);
8b9a1c
***************
8b9a1c
*** 21672,21678 ****
8b9a1c
       */
8b9a1c
      if (fudi.fd_dict == NULL)
8b9a1c
      {
8b9a1c
! 	v = find_var(name, &ht;;
8b9a1c
  	if (v != NULL && v->di_tv.v_type == VAR_FUNC)
8b9a1c
  	{
8b9a1c
  	    emsg_funcname(N_("E707: Function name conflicts with variable: %s"),
8b9a1c
--- 21677,21683 ----
8b9a1c
       */
8b9a1c
      if (fudi.fd_dict == NULL)
8b9a1c
      {
8b9a1c
! 	v = find_var(name, &ht, FALSE);
8b9a1c
  	if (v != NULL && v->di_tv.v_type == VAR_FUNC)
8b9a1c
  	{
8b9a1c
  	    emsg_funcname(N_("E707: Function name conflicts with variable: %s"),
8b9a1c
***************
8b9a1c
*** 21830,21837 ****
8b9a1c
   * Also handles a Funcref in a List or Dictionary.
8b9a1c
   * Returns the function name in allocated memory, or NULL for failure.
8b9a1c
   * flags:
8b9a1c
!  * TFN_INT:   internal function name OK
8b9a1c
!  * TFN_QUIET: be quiet
8b9a1c
   * Advances "pp" to just after the function name (if no error).
8b9a1c
   */
8b9a1c
      static char_u *
8b9a1c
--- 21835,21843 ----
8b9a1c
   * Also handles a Funcref in a List or Dictionary.
8b9a1c
   * Returns the function name in allocated memory, or NULL for failure.
8b9a1c
   * flags:
8b9a1c
!  * TFN_INT:         internal function name OK
8b9a1c
!  * TFN_QUIET:       be quiet
8b9a1c
!  * TFN_NO_AUTOLOAD: do not use script autoloading
8b9a1c
   * Advances "pp" to just after the function name (if no error).
8b9a1c
   */
8b9a1c
      static char_u *
8b9a1c
***************
8b9a1c
*** 21869,21875 ****
8b9a1c
      if (lead > 2)
8b9a1c
  	start += lead;
8b9a1c
  
8b9a1c
!     end = get_lval(start, NULL, &lv, FALSE, skip, flags & TFN_QUIET,
8b9a1c
  					      lead > 2 ? 0 : FNE_CHECK_START);
8b9a1c
      if (end == start)
8b9a1c
      {
8b9a1c
--- 21875,21882 ----
8b9a1c
      if (lead > 2)
8b9a1c
  	start += lead;
8b9a1c
  
8b9a1c
!     /* Note that TFN_ flags use the same values as GLV_ flags. */
8b9a1c
!     end = get_lval(start, NULL, &lv, FALSE, skip, flags,
8b9a1c
  					      lead > 2 ? 0 : FNE_CHECK_START);
8b9a1c
      if (end == start)
8b9a1c
      {
8b9a1c
***************
8b9a1c
*** 22146,22152 ****
8b9a1c
      char_u  *p;
8b9a1c
      int	    n = FALSE;
8b9a1c
  
8b9a1c
!     p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL);
8b9a1c
      nm = skipwhite(nm);
8b9a1c
  
8b9a1c
      /* Only accept "funcname", "funcname ", "funcname (..." and
8b9a1c
--- 22153,22160 ----
8b9a1c
      char_u  *p;
8b9a1c
      int	    n = FALSE;
8b9a1c
  
8b9a1c
!     p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET|TFN_NO_AUTOLOAD,
8b9a1c
! 			    NULL);
8b9a1c
      nm = skipwhite(nm);
8b9a1c
  
8b9a1c
      /* Only accept "funcname", "funcname ", "funcname (..." and
8b9a1c
***************
8b9a1c
*** 22393,22402 ****
8b9a1c
      int		ret = FALSE;
8b9a1c
      int		i;
8b9a1c
  
8b9a1c
-     /* Return quickly when autoload disabled. */
8b9a1c
-     if (no_autoload)
8b9a1c
- 	return FALSE;
8b9a1c
- 
8b9a1c
      /* If there is no '#' after name[0] there is no package name. */
8b9a1c
      p = vim_strchr(name, AUTOLOAD_CHAR);
8b9a1c
      if (p == NULL || p == name)
8b9a1c
--- 22401,22406 ----
8b9a1c
*** ../vim-7.4.148/src/testdir/test55.in	2013-03-07 14:33:12.000000000 +0100
8b9a1c
--- src/testdir/test55.in	2014-01-14 14:48:10.000000000 +0100
8b9a1c
***************
8b9a1c
*** 282,287 ****
8b9a1c
--- 282,294 ----
8b9a1c
  :    $put =ps
8b9a1c
  :  endfor
8b9a1c
  :endfor
8b9a1c
+ :" :lockvar/islocked() triggering script autoloading
8b9a1c
+ :set rtp+=./sautest
8b9a1c
+ :lockvar g:footest#x
8b9a1c
+ :unlockvar g:footest#x
8b9a1c
+ :$put ='locked g:footest#x:'.islocked('g:footest#x')
8b9a1c
+ :$put ='exists g:footest#x:'.exists('g:footest#x')
8b9a1c
+ :$put ='g:footest#x: '.g:footest#x
8b9a1c
  :"
8b9a1c
  :" a:000 function argument
8b9a1c
  :" first the tests that should fail
8b9a1c
*** ../vim-7.4.148/src/testdir/test55.ok	2012-08-29 16:51:15.000000000 +0200
8b9a1c
--- src/testdir/test55.ok	2014-01-14 14:45:14.000000000 +0100
8b9a1c
***************
8b9a1c
*** 86,91 ****
8b9a1c
--- 86,94 ----
8b9a1c
  FFpFFpp
8b9a1c
  0000-000
8b9a1c
  ppppppp
8b9a1c
+ locked g:footest#x:-1
8b9a1c
+ exists g:footest#x:0
8b9a1c
+ g:footest#x: 1
8b9a1c
  caught a:000
8b9a1c
  caught a:000[0]
8b9a1c
  caught a:000[2]
8b9a1c
*** ../vim-7.4.148/src/testdir/test60.in	2010-05-15 13:04:10.000000000 +0200
8b9a1c
--- src/testdir/test60.in	2014-01-14 14:49:10.000000000 +0100
8b9a1c
***************
8b9a1c
*** 1,4 ****
8b9a1c
! Tests for the exists() function.  vim: set ft=vim :
8b9a1c
  
8b9a1c
  STARTTEST
8b9a1c
  :so small.vim
8b9a1c
--- 1,4 ----
8b9a1c
! Tests for the exists() function.  vim: set ft=vim ts=8 :
8b9a1c
  
8b9a1c
  STARTTEST
8b9a1c
  :so small.vim
8b9a1c
***************
8b9a1c
*** 11,18 ****
8b9a1c
  endfunction
8b9a1c
  :function! TestExists()
8b9a1c
      augroup myagroup
8b9a1c
! 	autocmd! BufEnter *.my echo 'myfile edited'
8b9a1c
      augroup END
8b9a1c
  
8b9a1c
      let test_cases = []
8b9a1c
  
8b9a1c
--- 11,20 ----
8b9a1c
  endfunction
8b9a1c
  :function! TestExists()
8b9a1c
      augroup myagroup
8b9a1c
! 	autocmd! BufEnter       *.my     echo "myfile edited"
8b9a1c
! 	autocmd! FuncUndefined  UndefFun exec "fu UndefFun()\nendfu"
8b9a1c
      augroup END
8b9a1c
+     set rtp+=./sautest
8b9a1c
  
8b9a1c
      let test_cases = []
8b9a1c
  
8b9a1c
***************
8b9a1c
*** 95,104 ****
8b9a1c
      " Non-existing user defined function
8b9a1c
      let test_cases += [['*MyxyzFunc', 0]]
8b9a1c
  
8b9a1c
      redir! > test.out
8b9a1c
  
8b9a1c
      for [test_case, result] in test_cases
8b9a1c
!       	echo test_case . ": " . result
8b9a1c
          call RunTest(test_case, result)
8b9a1c
      endfor
8b9a1c
  
8b9a1c
--- 97,111 ----
8b9a1c
      " Non-existing user defined function
8b9a1c
      let test_cases += [['*MyxyzFunc', 0]]
8b9a1c
  
8b9a1c
+     " Function that may be created by FuncUndefined event
8b9a1c
+     let test_cases += [['*UndefFun', 0]]
8b9a1c
+     " Function that may be created by script autoloading
8b9a1c
+     let test_cases += [['*footest#F', 0]]
8b9a1c
+ 
8b9a1c
      redir! > test.out
8b9a1c
  
8b9a1c
      for [test_case, result] in test_cases
8b9a1c
!         echo test_case . ": " . result
8b9a1c
          call RunTest(test_case, result)
8b9a1c
      endfor
8b9a1c
  
8b9a1c
***************
8b9a1c
*** 207,212 ****
8b9a1c
--- 214,227 ----
8b9a1c
  	echo "FAILED"
8b9a1c
      endif
8b9a1c
  
8b9a1c
+     " Non-existing autoload variable that may be autoloaded
8b9a1c
+     echo 'footest#x: 0'
8b9a1c
+     if !exists('footest#x')
8b9a1c
+ 	echo "OK"
8b9a1c
+     else
8b9a1c
+ 	echo "FAILED"
8b9a1c
+     endif
8b9a1c
+ 
8b9a1c
      " Valid local list
8b9a1c
      let local_list = ["blue", "orange"]
8b9a1c
      echo 'local_list: 1'
8b9a1c
***************
8b9a1c
*** 566,571 ****
8b9a1c
--- 581,590 ----
8b9a1c
  
8b9a1c
      call TestFuncArg("arg1", "arg2")
8b9a1c
  
8b9a1c
+     echo ' g:footest#x =' g:footest#x
8b9a1c
+     echo '   footest#F()' footest#F()
8b9a1c
+     echo 'UndefFun()' UndefFun()
8b9a1c
+ 
8b9a1c
      redir END
8b9a1c
  endfunction
8b9a1c
  :call TestExists()
8b9a1c
***************
8b9a1c
*** 576,580 ****
8b9a1c
--- 595,600 ----
8b9a1c
  :set ff=unix
8b9a1c
  :w
8b9a1c
  :qa!
8b9a1c
+ :while getchar(1) | call getchar() | endwhile
8b9a1c
  ENDTEST
8b9a1c
  
8b9a1c
*** ../vim-7.4.148/src/testdir/test60.ok	2010-05-15 13:04:10.000000000 +0200
8b9a1c
--- src/testdir/test60.ok	2014-01-14 14:50:50.000000000 +0100
8b9a1c
***************
8b9a1c
*** 71,76 ****
8b9a1c
--- 71,80 ----
8b9a1c
  OK
8b9a1c
  *MyxyzFunc: 0
8b9a1c
  OK
8b9a1c
+ *UndefFun: 0
8b9a1c
+ OK
8b9a1c
+ *footest#F: 0
8b9a1c
+ OK
8b9a1c
  :edit: 2
8b9a1c
  OK
8b9a1c
  :edit/a: 0
8b9a1c
***************
8b9a1c
*** 95,100 ****
8b9a1c
--- 99,106 ----
8b9a1c
  OK
8b9a1c
  local_var: 0
8b9a1c
  OK
8b9a1c
+ footest#x: 0
8b9a1c
+ OK
8b9a1c
  local_list: 1
8b9a1c
  OK
8b9a1c
  local_list[1]: 1
8b9a1c
***************
8b9a1c
*** 195,197 ****
8b9a1c
--- 201,206 ----
8b9a1c
  OK
8b9a1c
  a:2: 0
8b9a1c
  OK
8b9a1c
+  g:footest#x = 1
8b9a1c
+    footest#F() 0
8b9a1c
+ UndefFun() 0
8b9a1c
*** ../vim-7.4.148/src/testdir/sautest/autoload/footest.vim	1970-01-01 01:00:00.000000000 +0100
8b9a1c
--- src/testdir/sautest/autoload/footest.vim	2014-01-14 14:52:06.000000000 +0100
8b9a1c
***************
8b9a1c
*** 0 ****
8b9a1c
--- 1,5 ----
8b9a1c
+ " Autoload script used by test55 and test60
8b9a1c
+ let footest#x = 1
8b9a1c
+ func footest#F()
8b9a1c
+   return 0
8b9a1c
+ endfunc
8b9a1c
*** ../vim-7.4.148/src/version.c	2014-01-14 13:26:17.000000000 +0100
8b9a1c
--- src/version.c	2014-01-14 15:23:36.000000000 +0100
8b9a1c
***************
8b9a1c
*** 740,741 ****
8b9a1c
--- 740,743 ----
8b9a1c
  {   /* Add new patch number below this line */
8b9a1c
+ /**/
8b9a1c
+     149,
8b9a1c
  /**/
8b9a1c
8b9a1c
-- 
8b9a1c
hundred-and-one symptoms of being an internet addict:
8b9a1c
157. You fum through a magazine, you first check to see if it has a web
8b9a1c
     address.
8b9a1c
8b9a1c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
8b9a1c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
8b9a1c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
8b9a1c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///