prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.3k stars 714 forks source link

Treat / in line as just another character #1385

Open newts opened 3 years ago

newts commented 3 years ago

I need to autocomplete a bunch of strings in a hierarchy separated with / like "/foo/bar", "/food/boo" etc. if I type "/fo I would expect to see the completions for /foo and /food but I get nothing. Note that typing the first / shows all the completions starting with /.

Looks like / is a vi search command but I should in emacs mode both default and I set it explicitly. I even removed the handler in vi.py to see if that would help but no. It also seems to treat . and - similarly so I am wondering if I am missing an option somewhere?

If not here's a request to make this a feature.

newts commented 3 years ago

OK I finally cracked this nut with the document regexps. So this issue is more of a documentation feature request?

from: prompt_toolkit/document.py

need to add / to the regexps to be considered part of a word

# prompt_toolkit.document._FIND_WORDRE = re.compile(r"([a-zA-Z0-9/]+|[^a-zA-Z0-9_/\s]+)") prompt_toolkit.document._FIND_CURRENT_WORDRE = re.compile(r"^([a-zA-Z0-9/]+|[^a-zA-Z0-9_/\s]+)") prompt_toolkit.document._FIND_CURRENT_WORD_INCLUDE_TRAILING_WHITESPACERE = re.compile( r"^(([a-zA-Z0-9/]+|[^a-zA-Z0-9_/\s]+)\s*)" )