From 2712db8238846f7b4e24052dbe091ea87defc5ae Mon Sep 17 00:00:00 2001 From: Philip Sequeira Date: Wed, 22 Nov 2017 19:09:06 -0500 Subject: zsh completion: move generation to runtime and improve The completion function itself now parses --list-options on the first tab press and caches the results. This does mean a slight delay on that first tab press, but it will only do this if the argument being completed looks like an option (i.e. starts with "-"), so there is never a delay when just completing a file name. I've also put some effort into making it reasonably fast; on my machine it's consistently under 100 ms, more than half of which is mpv itself. Installation of zsh completion is now done unconditionally because it's nothing more than copying a file. If you really don't want it installed, set zshdir to empty: `./waf configure --zshdir= ...` Improvements in functionality compared to the old script: * Produces the right results for mpv binaries other than the one it was installed with (like a dev build for testing changes). * Does not require running mpv at build time, so it won't cause problems with cross compilation. * Handles aliases. * Slightly nicer handling of options that take comma-separated values and/or sub-options: A space is now inserted at the end instead of a comma, allowing you to immediately start typing the next argument, but typing a comma will still remove the automatically added space, and = and : will now do that too, so you can immediately add a sub-option. * More general/flexible handling of values for options that print their possible values with --option=help. The code as is could handle quite a few more options (*scale, demuxers, decoders, ...), but nobody wants to maintain that list here so we'll just stick with what the old completion script already did. --- waftools/generators/sources.py | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'waftools/generators') diff --git a/waftools/generators/sources.py b/waftools/generators/sources.py index bbca38c06d..0f5b993758 100644 --- a/waftools/generators/sources.py +++ b/waftools/generators/sources.py @@ -5,10 +5,6 @@ from TOOLS.matroska import generate_C_header, generate_C_definitions from TOOLS.file2string import file2string import os -def __zshcomp_cmd__(ctx, argument): - return '"${{BIN_PERL}}" "{0}/TOOLS/zsh.pl" "{1}" > "${{TGT}}"' \ - .format(ctx.srcnode.abspath(), argument) - def __wayland_scanner_cmd__(ctx, mode, dir, src, vendored_file): return "${{WAYSCAN}} {0} < {1} > ${{TGT}}".format( mode, @@ -49,14 +45,6 @@ def ebml_header(self): def ebml_definitions(self): execf(self, generate_C_definitions) -def __zshcomp__(ctx, **kwargs): - ctx( - rule = __zshcomp_cmd__(ctx, ctx.bldnode.abspath() + '/mpv'), - after = ("c", "cprogram",), - name = os.path.basename(kwargs['target']), - **kwargs - ) - def __wayland_protocol_code__(ctx, **kwargs): protocol_is_vendored = kwargs.get("vendored_protocol", False) file_name = kwargs['protocol'] + '.xml' @@ -105,4 +93,3 @@ def handle_add_object(tgen): BuildContext.file2string = __file2string__ BuildContext.wayland_protocol_code = __wayland_protocol_code__ BuildContext.wayland_protocol_header = __wayland_protocol_header__ -BuildContext.zshcomp = __zshcomp__ -- cgit v1.2.3