@@ -1107,8 +1107,11 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, persistent_histor
11071107 # will be added if there is an unmatched opening quote
11081108 self .allow_closing_quote = True
11091109
1110- # If the tab-completion matches should be displayed in a way that is different than the actual match values,
1111- # then place those results in this list. path_complete uses this to show only the basename of completions.
1110+ # Use this list if you are completing strings that contain a common delimiter and you only want to
1111+ # display the final portion of the matches as the tab-completion suggestions. The full matches
1112+ # still must be returned from your completer function. For an example, look at path_complete()
1113+ # which uses this to show only the basename of paths as the suggestions. delimiter_complete() also
1114+ # populates this list.
11121115 self .display_matches = []
11131116
11141117 # ----- Methods related to presenting output to the user -----
@@ -2081,15 +2084,17 @@ def complete(self, text, state):
20812084 # Check if we need to add an opening quote
20822085 if not unclosed_quote :
20832086
2084- # Get the common prefix of all matches. This is the actual tab completion.
2085- common_prefix = os .path .commonprefix (self .completion_matches )
2087+ # Get the common prefix of the matches. This is the actual tab completion.
2088+ # Use display_matches instead of completion_matches to support cases of delimited
2089+ # match strings since only the final part of those matches matter in these checks.
2090+ common_prefix = os .path .commonprefix (self .display_matches )
20862091
20872092 # Join all matches into 1 string for ease of searching
2088- all_matches_str = '' .join (self .completion_matches )
2093+ all_matches_str = '' .join (self .display_matches )
20892094
2090- # If the tab completion will extend the text on the command line and any of
2091- # the matches have a space, then we will add an opening quote to the matches.
2092- if len ( common_prefix ) > len ( text ) and ' ' in all_matches_str :
2095+ # If there is a tab completion and any of the matches have a space,
2096+ # then we will add an opening quote to the completion matches.
2097+ if common_prefix and ' ' in all_matches_str :
20932098
20942099 # Figure out what kind of quote to add and save it as the unclosed_quote
20952100 if '"' in all_matches_str :
0 commit comments