/*
   * Execute next document update (i.e. that was queued from
   * {@link InteractiveInterpreterConsole#executeCommand(String)}
   * if present.
   */
  protected void consumeNextQueuedCommand() {
    Assert.isNotNull(page);
    Assert.isTrue(page.getViewer().isEditable());
    Assert.isTrue(promptInitialized);

    IDocument doc = getDocument();

    String command = delayedCommandQueue.poll();
    if (command != null) {
      boolean validCommand = true;
      try {
        if (command.startsWith("main();")) {
          // this command is special cased to make sure a main is defined
          // Paul has indicated new users are confused by the errors caused
          // by the lack of a main() method in the "executed" module.
          List<AbstractFunction> collection = new ArrayList<AbstractFunction>();
          getInterpreter().getEval().getCurrentEnvt().getAllFunctions("main", collection);
          if (collection.isEmpty()) {
            // main is not defined, dropping the command
            getInterpreter()
                .getEval()
                .getStdErr()
                .println("Dropping command: \"main();\" since main is not defined");
            validCommand = false;
          }
        }
        if (validCommand) {
          doc.replace(inputOffset, doc.getLength() - inputOffset, command);
        }
      } catch (BadLocationException blex) {
        // Ignore, can't happen.
      }
      if (validCommand) {
        moveCaretTo(doc.getLength());
      }
    }
  }