On Thu, Feb 5, 2009 at 2:08 AM, Nazri Ramliy <[email protected]> wrote:
> Attached is the improved patch, now against r1341 from svn.
Hah! I caught myself again.
That patch contains inappropriate leftovers (and stray fflush ;) from
my dabbling with the vim_extended repository. I'm blaming it to the
wee hours.
Please use this cleaned-up patch instead.
Apologies,
nazri.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: ex_docmd.c
===================================================================
--- ex_docmd.c (revision 1341)
+++ 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: ex_getln.c
===================================================================
--- ex_getln.c (revision 1341)
+++ 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);
Index: misc1.c
===================================================================
--- misc1.c (revision 1341)
+++ misc1.c (working copy)
@@ -9205,7 +9205,97 @@
* 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;
+ char_u *cwd_orig;
+ char_u *dir;
+ 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 ||
+ (dir = alloc((int)(MAXPATHL))) == NULL)
+ return FAIL;
+
+ if (getcwd((char *)cwd_orig, MAXPATHL) == NULL)
+ /* Ignore it */ ;
+
+ for(;;)
+ {
+ /*
+ * Go through each path in 'path' option.
+ */
+ int dir_count;
+ garray_T ga_dirs;
+
+ STRCPY(cwd, cwd_orig);
+
+ dir[0] = 0;
+ copy_option_part(&path_option, dir, MAXPATHL, " ;,");
+
+ if (mch_isFullName(dir))
+ {
+ STRCPY(cwd, dir);
+ }
+ else
+ {
+ char_u *fullpath;
+ fullpath = concat_fnames(cwd_orig, dir, 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 += mch_expandpath(&ga, p, flags);
+ }
+ else
+ {
+ /*
+ * Add files from each expanded path.
+ */
+ int i;
+ char_u **file;
+ file = (ga_dirs.ga_data != NULL) ? (char_u **)ga_dirs.ga_data : (char_u **)"";
+ for (i = 0; i < dir_count ; i++)
+ if (mch_chdir(file[i]) == 0)
+ c += mch_expandpath(&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(dir);
+ vim_free(cwd);
+ vim_free(cwd_orig);
+ }
+ }
}
if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND)))
Index: vim.h
===================================================================
--- vim.h (revision 1341)
+++ 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. */