Re: [RFC] Cleanup for make_source_files_completion_list

Doug Evans
2013-05-09T23:45:58Z

On Tue, May 7, 2013 at 12:46 PM, Keith Seitz <keiths@redhat.com> wrote:
> Hi,
>
> make_source_files_completion_list is only ever called with the first
> parameter twice, e.g.,
>
> fn_list = make_source_files_completion_list (text, text);
>
> Is there any reason to not whack the second parameter as the following patch
> does?

I looked into this a bit.
All make_foo_completion_list functions take "text" and "word".
And you can see how they're used in, e.g.,
completion_list_add_name and add_filename_to_list.
[grep for " + 5" in symtab.c. Heh.]

The caller of make_source_files_completion_list explains the decision
to pass "text" for "word" here:

/* If we only have file names as possible completion, we should
bring them in sync with what rl_complete expects. The
problem is that if the user types "break /foo/b TAB", and the
possible completions are "/foo/bar" and "/foo/baz"
rl_complete expects us to return "bar" and "baz", without the
leading directories, as possible completions, because `word'
starts at the "b". But we ignore the value of `word' when we
call make_source_files_completion_list above (because that
would not DTRT when the completion results in both symbols
and file names), so make_source_files_completion_list returns
the full "/foo/bar" and "/foo/baz" strings. This produces
wrong results when, e.g., there's only one possible
completion, because rl_complete will prepend "/foo/" to each
candidate completion. The loop below removes that leading
part. */

Note that if you remove "word" from make_source_files_completion_list
then add_filename_to_list collapses to a trivial function (which would
otherwise be great except there's basic core functionality that I
think should be kept). :-)

So to maintain consistency with all "make_foo_completion_list"
functions I think I'd like to keep make_source_files_completion_list
as is. Could be missing something of course.

OTOH the "text" arg to completion_list_add_name can go, it's unused.