Fix common single letter extension files not being detected

Fixes #4491
Fixes #4492
This commit is contained in:
Kovid Goyal 2022-01-10 14:20:18 +05:30
parent 5b8aca3a2f
commit b2bfc4408e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 2 deletions

View File

@ -82,6 +82,9 @@ Detailed list of changes
- macOS: Persist "Secure Keyboard Entry" across restarts to match the behavior - macOS: Persist "Secure Keyboard Entry" across restarts to match the behavior
of Terminal.app (:iss:`4471`) of Terminal.app (:iss:`4471`)
- hints kitten: Fix common single letter extension files not being detected
(:iss:`4491`)
0.24.1 [2022-01-06] 0.24.1 [2022-01-06]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -40,6 +40,8 @@ def kitty_common_opts() -> KittyCommonOpts:
DEFAULT_HINT_ALPHABET = string.digits + string.ascii_lowercase DEFAULT_HINT_ALPHABET = string.digits + string.ascii_lowercase
DEFAULT_REGEX = r'(?m)^\s*(.+)\s*$' DEFAULT_REGEX = r'(?m)^\s*(.+)\s*$'
FILE_EXTENSION = r'\.(?:[a-zA-Z0-9]{2,7}|[ahcmo])(?!\.)'
PATH_REGEX = fr'(?:\S*?/[\r\S]+)|(?:\S[\r\S]*{FILE_EXTENSION})\b'
class Mark: class Mark:
@ -355,7 +357,7 @@ def functions_for(args: HintsCLIOptions) -> Tuple[str, List[PostprocessorFunc]]:
) )
post_processors.append(url) post_processors.append(url)
elif args.type == 'path': elif args.type == 'path':
pattern = r'(?:\S*?/[\r\S]+)|(?:\S[\r\S]*\.[a-zA-Z0-9\r]{2,7})' pattern = PATH_REGEX
post_processors.extend((brackets, quotes)) post_processors.extend((brackets, quotes))
elif args.type == 'line': elif args.type == 'line':
pattern = '(?m)^\\s*(.+)[\\s\0]*$' pattern = '(?m)^\\s*(.+)[\\s\0]*$'
@ -412,7 +414,7 @@ def parse_input(text: str) -> str:
def linenum_marks(text: str, args: HintsCLIOptions, Mark: Type[Mark], extra_cli_args: Sequence[str], *a: Any) -> Generator[Mark, None, None]: def linenum_marks(text: str, args: HintsCLIOptions, Mark: Type[Mark], extra_cli_args: Sequence[str], *a: Any) -> Generator[Mark, None, None]:
regex = args.regex regex = args.regex
if regex == DEFAULT_REGEX: if regex == DEFAULT_REGEX:
regex = r'(?P<path>(?:\S*/\S+?)|(?:\S+[.][a-zA-Z0-9]{2,7})):(?P<line>\d+)' regex = fr'(?P<path>{PATH_REGEX}):(?P<line>\d+)'
yield from mark(regex, [brackets, quotes], text, args) yield from mark(regex, [brackets, quotes], text, args)