Non Incremental Nature of Custom Completion

2011-12-06 Thread Bastien Dejean
Hi,

I've made a custom completion function for one of my tools:

https://github.com/baskerville/owl

And I'd like `compgen -f` to behave like the default bash filename
completion, but it doesn't: for example, if I type `f` and if the only
file starting with `f` in the current directory is a directory named
`foo`, then, if I press ``, I'll get `foo `, I'd like to get `foo/`
instead. 

Greetings,
-- 
 b.d
(| |)
 ^ ^



Re: A programmable completoin bug?

2011-12-06 Thread Chet Ramey
On 12/5/11 12:15 AM, Clark J. Wang wrote:
> On Mon, Dec 5, 2011 at 11:42, Chet Ramey  > wrote:
> 
> On 12/4/11 10:26 PM, Clark J. Wang wrote:
> > On Mon, Dec 5, 2011 at 11:10, Chet Ramey  
> > >> wrote:
> >
> >
> > I still can't reproduce it on Mac OS X or RHEL 5.7:
> >
> >
> > It's weird. :) Any other settings can affect this? What can I do to
> debug more?
> 
> Well, if it were me, I'd fire up gdb and set a breakpoint in
> pcomplete.c:gen_shell_function_matches.  I wonder if you've got something
> filtering out or ignoring those matches.
> 
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRUc...@case.edu   
>  http://cnswww.cns.cwru.edu/~chet/ 
> 
> 
> After more investigation I found that it's caused by "set
> completion-ignore-case on". After turning completion-ignore-case off it
> works fine. You can give it a try.

Yes, it's the case-ignoring code.  It looks like you're the first person
to hit this since the code went in over ten years ago.  The original code
doesn't handle the case where the text the user typed is longer than the
replacement text well.

The attached patch fixes the issue.  It will be in the next bash release.

Chet


-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.2-patched/lib/readline/complete.c	2011-01-16 15:32:57.0 -0500
--- lib/readline/complete.c	2011-12-06 15:54:16.0 -0500
***
*** 1148,1151 
--- 1174,1178 
register int i, c1, c2, si;
int low;		/* Count of max-matched characters. */
+   int lx;
char *dtext;		/* dequoted TEXT, if needed */
  #if defined (HANDLE_MULTIBYTE)
***
*** 1265,1283 
  
  	  si = strlen (text);
! 	  if (si <= low)
! 	{
! 	  for (i = 1; i <= matches; i++)
! 		if (strncmp (match_list[i], text, si) == 0)
! 		  {
! 		strncpy (match_list[0], match_list[i], low);
! 		break;
! 		  }
! 	  /* no casematch, use first entry */
! 	  if (i > matches)
! 		strncpy (match_list[0], match_list[1], low);
! 	}
! 	  else
! 	/* otherwise, just use the text the user typed. */
! 	strncpy (match_list[0], text, low);
  
  	  FREE (dtext);
--- 1292,1309 
  
  	  si = strlen (text);
! 	  lx = (si <= low) ? si : low;	/* check shorter of text and matches */
! 	  /* Try to preserve the case of what the user typed in the presence of
! 	 multiple matches: check each match for something that matches
! 	 what the user typed taking case into account; use it up to common
! 	 length of matches if one is found.  If not, just use first match. */
! 	  for (i = 1; i <= matches; i++)
! 	if (strncmp (match_list[i], text, lx) == 0)
! 	  {
! 		strncpy (match_list[0], match_list[i], low);
! 		break;
! 	  }
! 	  /* no casematch, use first entry */
! 	  if (i > matches)
! 	strncpy (match_list[0], match_list[1], low);
  
  	  FREE (dtext);