   else
     new RegExp("(#{_.escapeRegExp(open)})|(#{_.escapeRegExp(close)})", 'g')
 
-findPair = (editor, from, pair, direction, fn) ->
+scanPair = (editor, from, pair, direction, fn) ->
   pattern = getPatternForPair(pair)
   switch direction
     when 'forward'

    filters

  findOpen: (from) ->
    stack = []
    openRange = null
    filters = @getFilters(from)

    findPair @editor, from, @pair, 'backward', (event) =>
      return if filters.some((filter) -> filter(event))

      {range, stop} = event
      if @getPairState(event) is 'close'
        stack.push(event)
      else
        stack.pop()
        openRange = range if stack.length is 0
      stop() if openRange?
    openRange

  findClose: (from) ->
    stack = []
    closeRange = null
    filters = @getFilters(from)

    isValidOpen = ({range}) =>
      openStart = range.start
      if @allowForwarding
        openStart.row is from.row
      else
        openStart.isEqual(from)

    findPair @editor, from, @pair, 'forward', (event) =>
      return if filters.some((filter) -> filter(event))

      {range, stop} = event
      if @getPairState(event) is 'open'
        stack.push(event)
      else
        openEvent = stack.pop()
        if stack.length is 0 and ((not openEvent?) or isValidOpen(openEvent))
          closeRange = range
          stop()
    closeRange

  getPairInfo: (from) ->
    pairInfo = null

      escaped = true
  escaped

# Return 'open' or 'close'
getPairState = (editor, event) ->
  {matchText, range, match} = event
  switch match.length
    when 2
      pairStateInBufferRange(editor, event)
    when 3
      switch
        when match[1] then 'open'
        when match[2] then 'close'

pairStateInBufferRange = (editor, {matchText, range}) ->
  text = getLineTextToBufferPosition(editor, range.end)
  escapedChar = _.escapeRegExp(matchText)
  bs = backSlashPattern
  patterns = [
    "#{bs}#{bs}#{escapedChar}"
    "[^#{bs}]?#{escapedChar}"
  ]
  pattern = new RegExp(patterns.join('|'))
  ['close', 'open'][(countChar(text, pattern) % 2)]

# -------------------------
class Pair extends TextObject
  @extend(false)
