# File lib/rbreadline.rb, line 8143
  def _rl_nsearch_init(dir, pchar)
    cxt = _rl_scxt_alloc(RL_SEARCH_NSEARCH, 0)
    if (dir < 0)
      cxt.sflags |= SF_REVERSE      # not strictly needed
    end
    cxt.direction = dir
    cxt.history_pos = cxt.save_line
    rl_maybe_save_line()
    # Clear the undo list, since reading the search string should create its
    #   own undo list, and the whole list will end up being freed when we
    #   finish reading the search string.
    @rl_undo_list = nil

    # Use the line buffer to read the search string.
    @rl_line_buffer[0,1] = 0.chr
    @rl_end = @rl_point = 0

    _p = _rl_make_prompt_for_search(pchar ? pchar : ':')
    rl_message(_p)
    _p = nil

    rl_setstate(RL_STATE_NSEARCH)
    @_rl_nscxt = cxt
    cxt
  end