fix zsh autocompletion
fix zsh autocompletion

The ZSH autocompletion code was previously very slow because it called
qibuild multiple times for initializing global tables that ended up not
being used. Replace those tables by higher-order functions so that the
calls are lazy. This makes the completion much faster.

scripted commit:

  #!/usr/bin/env ruby

  array_def = /
    (?<lines> (?: .* \n ) *? ){0}
    (?<name> \S* ){0}
    (?<begin> ^\g<name>=\($ ){0}
    (?<end> ^\)$ ){0}

    \g<begin> \n
    \g<lines>
    \g<end>
  /x

  file = STDIN.read
  names = []
  file.gsub!(array_def) {
    names << $~["name"]

    "_arguments_for_#{$~["name"]}() {\n" +
    "  $@ \\\n" +
    $~["lines"].split(/\n/).map{ |l| "  " + l }.join(" \\\n") +
    "\n}"
  }

  call = /
    _arguments[\s\n\\]+
    \$(#{names.map{|n| Regexp.escape n }.join("|")}\b)
  /x

  loop {
    break unless file.gsub!(call) {
      "_arguments_for_#{$1} \\\n  _arguments"
    }
  }

  print file

Change-Id: Ib93ca004cdc9109a8b72acbb416c1a5f5fd6cbcc
Reviewed-on: http://gerrit.aldebaran.lan/66503
Tested-by: nrubinstein <958004d5663b4fd0a0d26fef541880ee5b34c6ef@aldebaran-robotics.com>
Reviewed-by: ncornu <13ba26b8f12d26c819f48749c65f2f7f5c1d13db@aldebaran.com>
Tested-by: gerrit

aldebaran/qibuild,aldebaran/qibuild,aldebaran/qibuild,aldebaran/qibuild