The patch implements the completion for find and sfind commands.

It expands the argument according to your path setting, and shows the
resulting matches with their fullpaths shortened relative to your
working directory and, if that is not possible, to your home
directory.

This is against r1365.

nazri.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Index: src/ex_docmd.c
===================================================================
--- src/ex_docmd.c	(revision 1365)
+++ src/ex_docmd.c	(working copy)
@@ -3422,6 +3422,10 @@
  */
     switch (ea.cmdidx)
     {
+	case CMD_find:
+	case CMD_sfind:
+	    xp->xp_context = EXPAND_FILES_IN_PATH;
+	    break;
 	case CMD_cd:
 	case CMD_chdir:
 	case CMD_lcd:
Index: src/vim.h
===================================================================
--- src/vim.h	(revision 1365)
+++ src/vim.h	(working copy)
@@ -708,6 +708,7 @@
 #define EXPAND_USER_DEFINED	30
 #define EXPAND_USER_LIST	31
 #define EXPAND_SHELLCMD		32
+#define EXPAND_FILES_IN_PATH    33
 
 /* Values for exmode_active (0 is no exmode) */
 #define EXMODE_NORMAL		1
@@ -739,6 +740,7 @@
 #define EW_KEEPALL	0x10	/* keep all matches */
 #define EW_SILENT	0x20	/* don't print "1 returned" from shell */
 #define EW_EXEC		0x40	/* executable files */
+#define EW_PATH		0x80	/* search in 'path' too */
 /* Note: mostly EW_NOTFOUND and EW_SILENT are mutually exclusive: EW_NOTFOUND
  * is used when executing commands and EW_SILENT for interactive expanding. */
 
Index: src/misc1.c
===================================================================
--- src/misc1.c	(revision 1365)
+++ src/misc1.c	(working copy)
@@ -9097,6 +9097,39 @@
 }
 #endif
 
+/* 
+ * Expand the files matching pattern, starting from the given path, save
+ * the matches in their equivalent fullpath.
+ */
+    int
+expand_to_fullpath(path, gap, pattern, flags)
+    char_u	*path;
+    garray_T	*gap;
+    char_u	*pattern;
+    int		flags;		/* EW_* flags */
+{
+    int cur_len = gap->ga_len;
+    int new_len;
+    int i;
+    int c;
+
+    char_u **files;
+    char_u *fullpath;
+
+    c = mch_expandpath(gap, pattern, flags);
+
+    files = (gap->ga_data != NULL) ? (char_u **)gap->ga_data : (char_u **)"";
+    new_len = gap->ga_len;
+
+    for(i = cur_len; i < new_len; i++)
+    {
+	fullpath = concat_fnames(path, files[i], TRUE);
+	vim_free(files[i]);
+	files[i] = fullpath;
+    }
+    return c;
+}
+
 /*
  * Generic wildcard expansion code.
  *
@@ -9205,7 +9238,93 @@
 	     * when EW_NOTFOUND is given.
 	     */
 	    if (mch_has_exp_wildcard(p))
-		add_pat = mch_expandpath(&ga, p, flags);
+	    {
+		if ( ! (flags & EW_PATH) )
+		    add_pat = mch_expandpath(&ga, p, flags);
+		else
+		{
+		    /* 
+		     * Expand stuff in each expandable 'path' values.
+		     *
+		     * For each expandable 'path' values we get the list of all
+		     * directories and expand the file names in each the
+		     * directories.
+		     */
+		    int c = 0;
+		    char_u *cwd = NULL;
+		    char_u *cwd_orig = NULL;
+		    char_u *path_opt;
+		    char_u *path_option = *curbuf->b_p_path == NUL ? 
+						    p_path : curbuf->b_p_path;
+
+		    if ((cwd_orig = alloc((int)(MAXPATHL))) == NULL ||
+			(cwd = alloc((int)(MAXPATHL))) == NULL ||
+		        (path_opt = alloc((int)(MAXPATHL))) == NULL)
+		        return FAIL;
+
+		    if (getcwd((char *)cwd_orig, MAXPATHL) == NULL)
+			/* Ok to ignore it? */ ;
+
+		    for(;;)
+		    {
+			/* 
+			 * Go through each path in 'path' option.
+			 */
+			int dir_count;
+			garray_T ga_dirs;
+
+			STRCPY(cwd, cwd_orig);
+
+			path_opt[0] = 0;
+			copy_option_part(&path_option, path_opt, MAXPATHL, " ;,");
+
+			if (mch_isFullName(path_opt))
+			    STRCPY(cwd, path_opt);
+			else
+			{
+			    char_u *fullpath;
+			    fullpath = concat_fnames(cwd_orig, path_opt, TRUE);
+			    if (fullpath == NULL)
+				return FAIL; // Is it better to give emsg instead?
+			    STRNCPY(cwd, fullpath, MAXPATHL);
+			    vim_free(fullpath);
+			}
+
+			ga_init2(&ga_dirs, (int)sizeof(char_u *), 30);
+			dir_count = mch_expandpath(&ga_dirs, cwd, EW_DIR|EW_SILENT);
+
+			if (dir_count == 0)
+			{
+			    if (mch_chdir(cwd) == 0)
+				c += expand_to_fullpath(cwd, &ga, p, flags);
+			}
+			else 
+			{
+			    /* 
+			     * Add files from each expanded path.
+			     */
+			    int i;
+			    char_u **tmpdirs = (ga_dirs.ga_data != NULL) ? 
+						(char_u **)ga_dirs.ga_data : (char_u **)"";
+			    for (i = 0; i < dir_count && !got_int ; i++)
+				if (mch_chdir(tmpdirs[i]) == 0)
+				    c += expand_to_fullpath(tmpdirs[i], &ga, p, flags);
+			}
+			ga_clear(&ga_dirs);
+
+			if (path_option == NULL || *path_option == NUL)
+			    break;
+		    }
+
+		    add_pat  = c;
+		    if (mch_chdir(cwd_orig) != 0)
+			/* Ignore it */ ;
+
+		    vim_free(path_opt);
+		    vim_free(cwd);
+		    vim_free(cwd_orig);
+		}
+	    }
 	}
 
 	if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND)))
@@ -9231,6 +9350,17 @@
     *num_file = ga.ga_len;
     *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)"";
 
+    if (flags & EW_PATH)
+    {
+	shorten_filenames(*file, *num_file);
+	for(i = 0; i < *num_file && !got_int; i++)
+	{
+	    /* As (*file)[i] stores the fullpath, it is save to reuse 
+	     * it here. Is this ok for other platforms too? */
+	    home_replace(NULL, (*file)[i], (*file)[i], MAXPATHL, TRUE);
+	}
+    }
+
     recursive = FALSE;
 
     return (ga.ga_data != NULL) ? OK : FAIL;
Index: src/ex_getln.c
===================================================================
--- src/ex_getln.c	(revision 1365)
+++ src/ex_getln.c	(working copy)
@@ -4063,6 +4063,7 @@
     char_u	*tail;
 
     if (context != EXPAND_FILES
+	    && context != EXPAND_FILES_IN_PATH
 	    && context != EXPAND_SHELLCMD
 	    && context != EXPAND_DIRECTORIES)
     {
@@ -4377,7 +4378,9 @@
     if (options & WILD_SILENT)
 	flags |= EW_SILENT;
 
-    if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES)
+    if (xp->xp_context == EXPAND_FILES
+	    || xp->xp_context == EXPAND_DIRECTORIES
+	    || xp->xp_context == EXPAND_FILES_IN_PATH)
     {
 	/*
 	 * Expand file or directory names.
@@ -4407,6 +4410,8 @@
 
 	if (xp->xp_context == EXPAND_FILES)
 	    flags |= EW_FILE;
+	else if (xp->xp_context == EXPAND_FILES_IN_PATH)
+	    flags |= (EW_FILE | EW_PATH);
 	else
 	    flags = (flags | EW_DIR) & ~EW_FILE;
 	ret = expand_wildcards(1, &pat, num_file, file, flags);

Raspunde prin e-mail lui