docs: def stack(nick, rest):
      'Manage short lists in pmxbot. See !stack help for more info'
      atoms = [atom.strip() for atom in rest.split(' ', 1) if atom.strip()]
      if len(atoms) == 0:
          subcommand = "show"
          rest = ""
      elif len(atoms) == 1:
          subcommand = atoms[0]
          rest = ""
      else:
          subcommand, rest = atoms
  
      start = rest.find("[")
      finish = rest.rfind("]")
      sp = rest.find(" ")
      if (
          start != -1 and finish != -1 and start < finish and
          (sp == -1 or start < sp)
      ):
          topic, index = [atom.strip() for atom in rest[:finish].split("[", 1)]
          if not topic:
              topic = nick
          new_item = rest[finish + 1:].strip()
      else:
          topic = nick
          index = None
          new_item = rest.strip()
  
      if subcommand == "topics" or subcommand == "list":
          items = Stack.store.get_topics()
          items.sort()
      else:
          items = Stack.store.get_items(topic)
      try:
          indices = parse_index(index, items)
      except ValueError:
          return helpdoc["index"]
  
      if debug:
          print("SUBCOMMAND", subcommand.ljust(8), "TOPIC", topic.ljust(8),
                "INDICES", str(indices).ljust(12), "ITEM", new_item)
  
      if subcommand == "add":
          if not new_item:
              return ('!stack add <topic[index]> item: '
                      'You must provide an item to add.')
  
          if not indices:
              items.insert(0, new_item)
          else:
              for i in reversed(sorted(set(indices))):
                  if i >= len(items):
                      items.append(new_item)
                  else:
                      items.insert(i + 1, new_item)
  
          Stack.store.save_items(topic, items)
      elif subcommand == "pop":
          if not indices:
              indices = [0]
  
          popped_items = [items.pop(i) for i in reversed(sorted(set(indices)))
                          if len(items) > i >= 0]
  
          Stack.store.save_items(topic, items)
  
          return output([("-", item) for item in reversed(popped_items)],
                        "(none popped)", pop=True)
      elif subcommand == "show":
          if new_item:
              return helpdoc["show"]
  
          if not indices:
              indices = range(len(items))
  
          return output(
              [(i + 1, items[i]) for i in indices if len(items) > i >= 0]
          )
      elif subcommand == "shuffle":
          if not indices:
              random.shuffle(items)
          else:
              items = [items[i] for i in indices if len(items) > i >= 0]
  
          Stack.store.save_items(topic, items)
  
          return output(enumerate(items, 1))
      elif subcommand == "topics" or subcommand == "list":
          if new_item:
              return helpdoc["topics"]
  
          if not indices:
              indices = range(len(items))
  
          return output(
              [(i + 1, items[i]) for i in indices if len(items) > i >= 0]
          )
      elif subcommand == "help":
          return helpdoc.get(new_item, helpdoc["help"])
      else:
          return helpdoc["stack"]