# File lib/rbreadline.rb, line 5399
  def rl_get_previous_history(count, key)
    if (count < 0)
      return (rl_get_next_history(-count, key))
    end
    if (count == 0)
      return 0
    end
    # either not saved by rl_newline or at end of line, so set appropriately.
    if (@_rl_history_saved_point == -1 && (@rl_point!=0 || @rl_end!=0))
      @_rl_history_saved_point = (@rl_point == @rl_end) ? -1 : @rl_point
    end

    # If we don't have a line saved, then save this one.
    rl_maybe_save_line()

    # If the current line has changed, save the changes.
    rl_maybe_replace_line()

    temp = old_temp = nil
    while (count>0)
      temp = previous_history()
      if temp.nil?
        break
      end
      old_temp = temp
      count -= 1
    end

    # If there was a large argument, and we moved back to the start of the
    #   history, that is not an error.  So use the last value found.
    if (temp.nil? && old_temp)
      temp = old_temp
    end

    if temp.nil?
      rl_ding()
    else
      rl_replace_from_history(temp, 0)
      _rl_history_set_point()
    end

    0
  end