question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wordbreak issue when completing before end of line

See original GitHub issue

repro.py

#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK

import argparse
import argcomplete

parser = argparse.ArgumentParser()
parser.add_argument('--pass', choices=('name_one', 'name_two'))
parser.add_argument('--fail', choices=('name:one', 'name:two'))
parser.add_argument('--other')
argcomplete.autocomplete(parser)

The following completion in the middle of the line results in faulty completion:

$ ./repro.py --fail name:<TAB> --other

It becomes this:

$ ./repro.py --fail name:name: --other

Instead I’d expect to need to double-tab for this output:

$ ./repro.py --fail name:<TAB><TAB> --other
one  two  

For comparison, it works fine at the end of the line:

$ ./repro.py --fail name:<TAB><TAB>
one  two  

If an underscore is used instead of a colon, it works in the middle of the line or at the end:

$ ./repro.py --pass name_<TAB><TAB>
name_one  name_two  
$ ./repro.py --pass name_<TAB><TAB> --other
name_one  name_two  

This appears to be due to the lexer clearing last_wordbreak_pos here: https://github.com/kislyuk/argcomplete/blob/5a20d6165fbb4d4d58559378919b05964870cc16/argcomplete/my_shlex.py#L296-L297

Commenting out those two lines resolved the issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
kislyukcommented, Nov 5, 2021

great point @evanunderscore, let’s leave that behavior as is.

1reaction
kislyukcommented, Nov 4, 2021

Thanks for confirming @evanunderscore. I’ve been thinking about this and while I think we should proceed with #352 in the short term, I also hope we can enable a future where arguments after the cursor can affect parser state. This can be useful with mutually exclusive arguments, etc.

I’ll merge #352 and then try to scope out a design for what would be necessary to enable that, in a separate PR/issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

wrap, overflow - wrap - , and - word - break - LogRocket Blog
Force line breaks are caused by explicit line-breaking controls or line breaks marking the end or start of blocks of text.
Read more >
How to prevent my words breaking on to a new line
1) Go to the “Page Layout” tab on the Ribbon · 2) Look for the “Page Setup” group · 3) Click on “Hyphenation”...
Read more >
word-break - CSS-Tricks
The word-break property in CSS can be used to change when line breaks ought to occur. Normally, line breaks in text can only...
Read more >
How to fix words splitting at the end of lines? - YouTube
Sometimes, words are seen splitting at the end of lines. This happens if the original document was written in a system with an...
Read more >
310. Why does my text wrap to the next line before reaching ...
Ensure that Indentation, both before and after text, are set to zero and that no special formatting has been set.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found