From 64a242ba865d0c09dca2ee2795c3d59b33303a2d Mon Sep 17 00:00:00 2001 From: Sergei Lebedev Date: Sat, 30 Jul 2011 18:08:39 +0400 Subject: [PATCH] `grepo.coffee` now completes both -n and -l --- apps/grepo_base/static/coffee/grepo.coffee | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/grepo_base/static/coffee/grepo.coffee b/apps/grepo_base/static/coffee/grepo.coffee index 62f185b..1af3084 100644 --- a/apps/grepo_base/static/coffee/grepo.coffee +++ b/apps/grepo_base/static/coffee/grepo.coffee @@ -24,14 +24,30 @@ grepo.match = (language) -> grepo.complete = (event, term) -> if event.keyCode is 9 # Try to auto-complete on TAB. - options = grepo.parse term.get_command() + command = term.get_command() + [command..., key, value] = command.split /\s+/ - if options? and options.language? - # a) auto-complete language - if not options.keywords.length - term.set_command "grepo -l #{grepo.match options.language} " + if key[0] isnt "-" + command.push key + + # seems like we have a -fBAR case. + if value[0] is "-" + [key, value] = [value.substring(0, 2), value.substring(2)] + # okay, complete keyword else # query the server for the closest matching tag. + return + + # complete an argument. + switch key + when "-n" + value = parseInt(value or "10", 10) * 2 + when "-l" + value = grepo.match(value) + + command.push key + command.push value + term.set_command command.join(" ") return no