Karsten Hopp 82ff66
To: vim_dev@googlegroups.com
Karsten Hopp 82ff66
Subject: Patch 7.3.631
Karsten Hopp 82ff66
Fcc: outbox
Karsten Hopp 82ff66
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 82ff66
Mime-Version: 1.0
Karsten Hopp 82ff66
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 82ff66
Content-Transfer-Encoding: 8bit
Karsten Hopp 82ff66
------------
Karsten Hopp 82ff66
Karsten Hopp 82ff66
Patch 7.3.631
Karsten Hopp 82ff66
Problem:    Cannot complete user names.
Karsten Hopp 82ff66
Solution:   Add user name completion.  (Dominique Pelle)
Karsten Hopp 82ff66
Files:	    runtime/doc/map.txt, src/auto/configure, src/config.h.in,
Karsten Hopp 82ff66
	    src/configure.in, src/ex_docmd.c, src/ex_getln.c,
Karsten Hopp 82ff66
	    src/misc1.c, src/misc2.c, src/proto/misc1.pro, src/vim.h
Karsten Hopp 82ff66
Karsten Hopp 82ff66
Karsten Hopp 82ff66
*** ../vim-7.3.630/runtime/doc/map.txt	2012-04-30 18:48:38.000000000 +0200
Karsten Hopp 82ff66
--- runtime/doc/map.txt	2012-08-15 13:46:34.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 1227,1232 ****
Karsten Hopp 82ff66
--- 1244,1250 ----
Karsten Hopp 82ff66
  	-complete=syntax	syntax file names |'syntax'|
Karsten Hopp 82ff66
  	-complete=tag		tags
Karsten Hopp 82ff66
  	-complete=tag_listfiles	tags, file names are shown when CTRL-D is hit
Karsten Hopp 82ff66
+ 	-complete=user		user names
Karsten Hopp 82ff66
  	-complete=var		user variables
Karsten Hopp 82ff66
  	-complete=custom,{func} custom completion, defined via {func}
Karsten Hopp 82ff66
  	-complete=customlist,{func} custom completion, defined via {func}
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/auto/configure	2012-07-25 16:32:03.000000000 +0200
Karsten Hopp 82ff66
--- src/auto/configure	2012-08-15 13:48:06.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 10631,10637 ****
Karsten Hopp 82ff66
  fi
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  for ac_func in bcmp fchdir fchown fsync getcwd getpseudotty \
Karsten Hopp 82ff66
! 	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 82ff66
  	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 82ff66
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 82ff66
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 82ff66
--- 10631,10637 ----
Karsten Hopp 82ff66
  fi
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  for ac_func in bcmp fchdir fchown fsync getcwd getpseudotty \
Karsten Hopp 82ff66
! 	getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 82ff66
  	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 82ff66
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 82ff66
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/config.h.in	2012-02-05 22:51:27.000000000 +0100
Karsten Hopp 82ff66
--- src/config.h.in	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 161,166 ****
Karsten Hopp 82ff66
--- 161,167 ----
Karsten Hopp 82ff66
  #undef HAVE_FSYNC
Karsten Hopp 82ff66
  #undef HAVE_GETCWD
Karsten Hopp 82ff66
  #undef HAVE_GETPSEUDOTTY
Karsten Hopp 82ff66
+ #undef HAVE_GETPWENT
Karsten Hopp 82ff66
  #undef HAVE_GETPWNAM
Karsten Hopp 82ff66
  #undef HAVE_GETPWUID
Karsten Hopp 82ff66
  #undef HAVE_GETRLIMIT
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/configure.in	2012-07-25 16:32:03.000000000 +0200
Karsten Hopp 82ff66
--- src/configure.in	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 2994,3000 ****
Karsten Hopp 82ff66
  dnl Check for functions in one big call, to reduce the size of configure.
Karsten Hopp 82ff66
  dnl Can only be used for functions that do not require any include.
Karsten Hopp 82ff66
  AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \
Karsten Hopp 82ff66
! 	getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 82ff66
  	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 82ff66
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 82ff66
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 82ff66
--- 2994,3000 ----
Karsten Hopp 82ff66
  dnl Check for functions in one big call, to reduce the size of configure.
Karsten Hopp 82ff66
  dnl Can only be used for functions that do not require any include.
Karsten Hopp 82ff66
  AC_CHECK_FUNCS(bcmp fchdir fchown fsync getcwd getpseudotty \
Karsten Hopp 82ff66
! 	getpwent getpwnam getpwuid getrlimit gettimeofday getwd lstat memcmp \
Karsten Hopp 82ff66
  	memset mkdtemp nanosleep opendir putenv qsort readlink select setenv \
Karsten Hopp 82ff66
  	setpgid setsid sigaltstack sigstack sigset sigsetjmp sigaction \
Karsten Hopp 82ff66
  	sigvec strcasecmp strerror strftime stricmp strncasecmp \
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/ex_docmd.c	2012-08-02 21:24:38.000000000 +0200
Karsten Hopp 82ff66
--- src/ex_docmd.c	2012-08-15 13:54:29.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 3515,3520 ****
Karsten Hopp 82ff66
--- 3515,3537 ----
Karsten Hopp 82ff66
  #endif
Karsten Hopp 82ff66
  	    }
Karsten Hopp 82ff66
  	}
Karsten Hopp 82ff66
+ #if defined(FEAT_CMDL_COMPL)
Karsten Hopp 82ff66
+ 	/* Check for user names */
Karsten Hopp 82ff66
+ 	if (*xp->xp_pattern == '~')
Karsten Hopp 82ff66
+ 	{
Karsten Hopp 82ff66
+ 	    for (p = xp->xp_pattern + 1; *p != NUL && *p != '/'; ++p)
Karsten Hopp 82ff66
+ 		;
Karsten Hopp 82ff66
+ 	    /* Complete ~user only if it partially matches a user name.
Karsten Hopp 82ff66
+ 	     * A full match ~user<Tab> will be replaced by user's home
Karsten Hopp 82ff66
+ 	     * directory i.e. something like ~user<Tab> -> /home/user/ */
Karsten Hopp 82ff66
+ 	    if (*p == NUL && p > xp->xp_pattern + 1
Karsten Hopp 82ff66
+ 				       && match_user(xp->xp_pattern + 1) == 1)
Karsten Hopp 82ff66
+ 	    {
Karsten Hopp 82ff66
+ 		xp->xp_context = EXPAND_USER;
Karsten Hopp 82ff66
+ 		++xp->xp_pattern;
Karsten Hopp 82ff66
+ 	    }
Karsten Hopp 82ff66
+ 	}
Karsten Hopp 82ff66
+ #endif
Karsten Hopp 82ff66
      }
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  /*
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 5396,5401 ****
Karsten Hopp 82ff66
--- 5413,5419 ----
Karsten Hopp 82ff66
  #endif
Karsten Hopp 82ff66
      {EXPAND_TAGS, "tag"},
Karsten Hopp 82ff66
      {EXPAND_TAGS_LISTFILES, "tag_listfiles"},
Karsten Hopp 82ff66
+     {EXPAND_USER, "user"},
Karsten Hopp 82ff66
      {EXPAND_USER_VARS, "var"},
Karsten Hopp 82ff66
      {0, NULL}
Karsten Hopp 82ff66
  };
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/ex_getln.c	2012-08-08 18:01:00.000000000 +0200
Karsten Hopp 82ff66
--- src/ex_getln.c	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 4336,4341 ****
Karsten Hopp 82ff66
--- 4336,4342 ----
Karsten Hopp 82ff66
   *  EXPAND_EXPRESSION	    Complete internal or user defined function/variable
Karsten Hopp 82ff66
   *			    names in expressions, eg :while s^I
Karsten Hopp 82ff66
   *  EXPAND_ENV_VARS	    Complete environment variable names
Karsten Hopp 82ff66
+  *  EXPAND_USER		    Complete user names
Karsten Hopp 82ff66
   */
Karsten Hopp 82ff66
      static void
Karsten Hopp 82ff66
  set_expand_context(xp)
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 4681,4686 ****
Karsten Hopp 82ff66
--- 4682,4688 ----
Karsten Hopp 82ff66
  	    {EXPAND_LOCALES, get_locales, TRUE, FALSE},
Karsten Hopp 82ff66
  #endif
Karsten Hopp 82ff66
  	    {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE},
Karsten Hopp 82ff66
+ 	    {EXPAND_USER, get_users, TRUE, FALSE},
Karsten Hopp 82ff66
  	};
Karsten Hopp 82ff66
  	int	i;
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/misc1.c	2012-08-08 18:01:00.000000000 +0200
Karsten Hopp 82ff66
--- src/misc1.c	2012-08-15 13:57:53.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 18,23 ****
Karsten Hopp 82ff66
--- 18,28 ----
Karsten Hopp 82ff66
  static char_u *remove_tail __ARGS((char_u *p, char_u *pend, char_u *name));
Karsten Hopp 82ff66
  static int copy_indent __ARGS((int size, char_u	*src));
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
+ /* All user names (for ~user completion as done by shell). */
Karsten Hopp 82ff66
+ #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
Karsten Hopp 82ff66
+ static garray_T	ga_users;
Karsten Hopp 82ff66
+ #endif
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
  /*
Karsten Hopp 82ff66
   * Count the size (in window cells) of the indent in the current line.
Karsten Hopp 82ff66
   */
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 3782,3787 ****
Karsten Hopp 82ff66
--- 3787,3800 ----
Karsten Hopp 82ff66
  {
Karsten Hopp 82ff66
      vim_free(homedir);
Karsten Hopp 82ff66
  }
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ # ifdef FEAT_CMDL_COMPL
Karsten Hopp 82ff66
+     void
Karsten Hopp 82ff66
+ free_users()
Karsten Hopp 82ff66
+ {
Karsten Hopp 82ff66
+     ga_clear_strings(&ga_users);
Karsten Hopp 82ff66
+ }
Karsten Hopp 82ff66
+ # endif
Karsten Hopp 82ff66
  #endif
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  /*
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 4451,4456 ****
Karsten Hopp 82ff66
--- 4464,4543 ----
Karsten Hopp 82ff66
      return name;
Karsten Hopp 82ff66
  # endif
Karsten Hopp 82ff66
  }
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ /*
Karsten Hopp 82ff66
+  * Find all user names for user completion.
Karsten Hopp 82ff66
+  * Done only once and then cached.
Karsten Hopp 82ff66
+  */
Karsten Hopp 82ff66
+     static void
Karsten Hopp 82ff66
+ init_users() {
Karsten Hopp 82ff66
+     static int	lazy_init_done = FALSE;
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+     if (lazy_init_done)
Karsten Hopp 82ff66
+ 	return;
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+     lazy_init_done = TRUE;
Karsten Hopp 82ff66
+     ga_init2(&ga_users, sizeof(char_u *), 20);
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
Karsten Hopp 82ff66
+     {
Karsten Hopp 82ff66
+ 	char_u*		user;
Karsten Hopp 82ff66
+ 	struct passwd*	pw;
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ 	setpwent();
Karsten Hopp 82ff66
+ 	while ((pw = getpwent()) != NULL)
Karsten Hopp 82ff66
+ 	    /* pw->pw_name shouldn't be NULL but just in case... */
Karsten Hopp 82ff66
+ 	    if (pw->pw_name != NULL)
Karsten Hopp 82ff66
+ 	    {
Karsten Hopp 82ff66
+ 		if (ga_grow(&ga_users, 1) == FAIL)
Karsten Hopp 82ff66
+ 		    break;
Karsten Hopp 82ff66
+ 		user = vim_strsave((char_u*)pw->pw_name);
Karsten Hopp 82ff66
+ 		if (user == NULL)
Karsten Hopp 82ff66
+ 		    break;
Karsten Hopp 82ff66
+ 		((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user;
Karsten Hopp 82ff66
+ 	    }
Karsten Hopp 82ff66
+ 	endpwent();
Karsten Hopp 82ff66
+     }
Karsten Hopp 82ff66
+ # endif
Karsten Hopp 82ff66
+ }
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ /*
Karsten Hopp 82ff66
+  * Function given to ExpandGeneric() to obtain an user names.
Karsten Hopp 82ff66
+  */
Karsten Hopp 82ff66
+     char_u*
Karsten Hopp 82ff66
+ get_users(xp, idx)
Karsten Hopp 82ff66
+     expand_T	*xp UNUSED;
Karsten Hopp 82ff66
+     int		idx;
Karsten Hopp 82ff66
+ {
Karsten Hopp 82ff66
+     init_users();
Karsten Hopp 82ff66
+     if (idx < ga_users.ga_len)
Karsten Hopp 82ff66
+ 	return ((char_u **)ga_users.ga_data)[idx];
Karsten Hopp 82ff66
+     return NULL;
Karsten Hopp 82ff66
+ }
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+ /*
Karsten Hopp 82ff66
+  * Check whether name matches a user name. Return:
Karsten Hopp 82ff66
+  * 0 if name does not match any user name.
Karsten Hopp 82ff66
+  * 1 if name partially matches the beginning of a user name.
Karsten Hopp 82ff66
+  * 2 is name fully matches a user name.
Karsten Hopp 82ff66
+  */
Karsten Hopp 82ff66
+ int match_user(name)
Karsten Hopp 82ff66
+     char_u* name;
Karsten Hopp 82ff66
+ {
Karsten Hopp 82ff66
+     int i;
Karsten Hopp 82ff66
+     int n = (int)STRLEN(name);
Karsten Hopp 82ff66
+     int result = 0;
Karsten Hopp 82ff66
+ 
Karsten Hopp 82ff66
+     init_users();
Karsten Hopp 82ff66
+     for (i = 0; i < ga_users.ga_len; i++)
Karsten Hopp 82ff66
+     {
Karsten Hopp 82ff66
+ 	if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
Karsten Hopp 82ff66
+ 	    return 2; /* full match */
Karsten Hopp 82ff66
+ 	if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
Karsten Hopp 82ff66
+ 	    result = 1; /* partial match */
Karsten Hopp 82ff66
+     }
Karsten Hopp 82ff66
+     return result;
Karsten Hopp 82ff66
+ }
Karsten Hopp 82ff66
  #endif
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  /*
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/misc2.c	2012-06-29 15:51:26.000000000 +0200
Karsten Hopp 82ff66
--- src/misc2.c	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 1110,1115 ****
Karsten Hopp 82ff66
--- 1110,1118 ----
Karsten Hopp 82ff66
      free_all_marks();
Karsten Hopp 82ff66
      alist_clear(&global_alist);
Karsten Hopp 82ff66
      free_homedir();
Karsten Hopp 82ff66
+ # if defined(FEAT_CMDL_COMPL)
Karsten Hopp 82ff66
+     free_users();
Karsten Hopp 82ff66
+ # endif
Karsten Hopp 82ff66
      free_search_patterns();
Karsten Hopp 82ff66
      free_old_sub();
Karsten Hopp 82ff66
      free_last_insert();
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/proto/misc1.pro	2012-06-06 16:12:54.000000000 +0200
Karsten Hopp 82ff66
--- src/proto/misc1.pro	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 50,55 ****
Karsten Hopp 82ff66
--- 50,56 ----
Karsten Hopp 82ff66
  void vim_beep __ARGS((void));
Karsten Hopp 82ff66
  void init_homedir __ARGS((void));
Karsten Hopp 82ff66
  void free_homedir __ARGS((void));
Karsten Hopp 82ff66
+ void free_users __ARGS((void));
Karsten Hopp 82ff66
  char_u *expand_env_save __ARGS((char_u *src));
Karsten Hopp 82ff66
  char_u *expand_env_save_opt __ARGS((char_u *src, int one));
Karsten Hopp 82ff66
  void expand_env __ARGS((char_u *src, char_u *dst, int dstlen));
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 57,62 ****
Karsten Hopp 82ff66
--- 58,65 ----
Karsten Hopp 82ff66
  char_u *vim_getenv __ARGS((char_u *name, int *mustfree));
Karsten Hopp 82ff66
  void vim_setenv __ARGS((char_u *name, char_u *val));
Karsten Hopp 82ff66
  char_u *get_env_name __ARGS((expand_T *xp, int idx));
Karsten Hopp 82ff66
+ char_u *get_users __ARGS((expand_T *xp, int idx));
Karsten Hopp 82ff66
+ int match_user __ARGS((char_u* name));
Karsten Hopp 82ff66
  void home_replace __ARGS((buf_T *buf, char_u *src, char_u *dst, int dstlen, int one));
Karsten Hopp 82ff66
  char_u *home_replace_save __ARGS((buf_T *buf, char_u *src));
Karsten Hopp 82ff66
  int fullpathcmp __ARGS((char_u *s1, char_u *s2, int checkname));
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/vim.h	2012-07-10 17:14:50.000000000 +0200
Karsten Hopp 82ff66
--- src/vim.h	2012-08-15 13:46:35.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 782,787 ****
Karsten Hopp 82ff66
--- 782,788 ----
Karsten Hopp 82ff66
  #define EXPAND_OWNSYNTAX	39
Karsten Hopp 82ff66
  #define EXPAND_LOCALES		40
Karsten Hopp 82ff66
  #define EXPAND_HISTORY		41
Karsten Hopp 82ff66
+ #define EXPAND_USER		42
Karsten Hopp 82ff66
  
Karsten Hopp 82ff66
  /* Values for exmode_active (0 is no exmode) */
Karsten Hopp 82ff66
  #define EXMODE_NORMAL		1
Karsten Hopp 82ff66
*** ../vim-7.3.630/src/version.c	2012-08-15 13:30:55.000000000 +0200
Karsten Hopp 82ff66
--- src/version.c	2012-08-15 14:01:12.000000000 +0200
Karsten Hopp 82ff66
***************
Karsten Hopp 82ff66
*** 716,717 ****
Karsten Hopp 82ff66
--- 716,719 ----
Karsten Hopp 82ff66
  {   /* Add new patch number below this line */
Karsten Hopp 82ff66
+ /**/
Karsten Hopp 82ff66
+     631,
Karsten Hopp 82ff66
  /**/
Karsten Hopp 82ff66
Karsten Hopp 82ff66
-- 
Karsten Hopp 82ff66
"Marriage is the process of finding out what kind of man your wife
Karsten Hopp 82ff66
would have preferred"
Karsten Hopp 82ff66
Karsten Hopp 82ff66
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 82ff66
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 82ff66
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 82ff66
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///