editline icon indicating copy to clipboard operation
editline copied to clipboard

Completion functions returning strings containing tabs or spaces display incorrectly

Open C0deH4cker opened this issue 9 years ago • 3 comments

In a project of mine, I wrote a completer function that does only return strdup("\t"); (to disable completion of filenames, which are meaningless for my project). However, this prints ^I instead of a tab as it should. When I try to return something like strdup("hello world"), it prints hello\ world instead. I assume that the issue is due to the very questionable implementation of CTL() and META(). It seems to me that the proper way of doing this is to use a type larger than a char, where the modifers are stored in higher bits. Of course this will require changing the public interface to libeditline, so maybe the current functions should be deprecated (but still remain), and new, proper functions should be added.

I just did some digging and found out that the string returned from my completer function is passed to insert_string(), which passes it to tty_string(), and then each character goes to tty_show(), which does use the ISCTL() and ISMETA() macros to incorrectly convert a tab into ^I. Also, it is line 1385 of editline.c which adds a newline before spaces. No idea why it does that though.

C0deH4cker avatar Sep 25 '15 06:09 C0deH4cker

If you want to disable TAB completion, simply add the following to your code:

rl_inhibit_complete = 1;

troglobit avatar Sep 25 '15 06:09 troglobit

Okay, I will do that for now, but I'm curious how you're supposed to complete a string that contains spaces without adding backslashes to them. That is still an issue I believe.

On Sep 25, 2015, at 2:48 AM, Joachim Nilsson [email protected] wrote:

If you want to disable TAB completion, simply add the following to your code:

rl_inhibit_complete = 1; — Reply to this email directly or view it on GitHub.

C0deH4cker avatar Sep 25 '15 07:09 C0deH4cker

It's a bit limited, admittedly. I think it was initially written to do filename completion.

Pull requests with fixes are most welcome! :smirk:

troglobit avatar Sep 25 '15 13:09 troglobit