 path = require 'path'
 Serializable = require 'serializable'
 Delegator = require 'delegato'
-{deprecate} = require 'grim'
+{includeDeprecations, deprecate} = require 'grim'
 {Model} = require 'theorist'
 EmitterMixin = require('emissary').Emitter
 {CompositeDisposable, Emitter} = require 'event-kit'

        for [foldStartRow, foldEndRow] in foldedRowRanges
          @createFold(foldStartRow + delta, foldEndRow + delta)
      return

  # Deprecated: Use {::duplicateLines} instead.
  duplicateLine: ->
    deprecate("Use TextEditor::duplicateLines() instead")
    @duplicateLines()

  replaceSelectedText: (options={}, fn) ->
    {selectWordIfEmpty} = options


  pixelRectForScreenRange: (screenRange) -> @displayBuffer.pixelRectForScreenRange(screenRange)

  ###
  Section: Utility
  ###

  inspect: ->
    "<TextEditor #{@id}>"

  logScreenLines: (start, end) -> @displayBuffer.logLines(start, end)

if includeDeprecations
  TextEditor::getViewClass = ->
    require './text-editor-view'

  TextEditor::joinLine = ->
    deprecate("Use TextEditor::joinLines() instead")
    @joinLines()

  TextEditor::scopesAtCursor = ->
    deprecate 'Use editor.getLastCursor().getScopeDescriptor() instead'
    @getLastCursor().getScopeDescriptor().getScopesArray()

  TextEditor::getCursorScopes = ->
    deprecate 'Use editor.getLastCursor().getScopeDescriptor() instead'
    @scopesAtCursor()

  TextEditor::getUri = ->
    deprecate("Use `::getURI` instead")
    @getURI()

  TextEditor::lineForBufferRow = (bufferRow) ->
    deprecate 'Use TextEditor::lineTextForBufferRow(bufferRow) instead'
    @lineTextForBufferRow(bufferRow)

  TextEditor::lineForScreenRow = (screenRow) ->
    deprecate "TextEditor::tokenizedLineForScreenRow(bufferRow) is the new name. But it's private. Try to use TextEditor::lineTextForScreenRow instead"
    @tokenizedLineForScreenRow(screenRow)

  TextEditor::linesForScreenRows = (start, end) ->
    deprecate "Use TextEditor::tokenizedLinesForScreenRows instead"
    @tokenizedLinesForScreenRows(start, end)

  TextEditor::lineLengthForBufferRow = (row) ->
    deprecate "Use editor.lineTextForBufferRow(row).length instead"
    @lineTextForBufferRow(row).length

  TextEditor::duplicateLine = ->
    deprecate("Use TextEditor::duplicateLines() instead")
    @duplicateLines()

  TextEditor::scopesForBufferPosition = (bufferPosition) ->
    deprecate 'Use ::scopeDescriptorForBufferPosition instead. The return value has changed! It now returns a `ScopeDescriptor`'
    @scopeDescriptorForBufferPosition(bufferPosition).getScopesArray()

  TextEditor::toggleSoftWrap = ->
    deprecate("Use TextEditor::toggleSoftWrapped instead")
    @toggleSoftWrapped()

  TextEditor::setSoftWrap = (softWrapped) ->
    deprecate("Use TextEditor::setSoftWrapped instead")
    @setSoftWrapped(softWrapped)

  TextEditor::backspaceToBeginningOfWord = ->
    deprecate("Use TextEditor::deleteToBeginningOfWord() instead")
    @deleteToBeginningOfWord()

  TextEditor::backspaceToBeginningOfLine = ->
    deprecate("Use TextEditor::deleteToBeginningOfLine() instead")
    @deleteToBeginningOfLine()

  TextEditor::getGutterDecorations = (propertyFilter) ->
    deprecate("Use ::getLineNumberDecorations instead")
    @getLineNumberDecorations(propertyFilter)

  TextEditor::getCursorScreenRow = ->
    deprecate('Use `editor.getCursorScreenPosition().row` instead')
    @getCursorScreenPosition().row

  TextEditor::moveCursorUp = (lineCount) ->
    deprecate("Use TextEditor::moveUp() instead")
    @moveUp(lineCount)

  TextEditor::moveCursorDown = (lineCount) ->
    deprecate("Use TextEditor::moveDown() instead")
    @moveDown(lineCount)

  TextEditor::moveCursorLeft = ->
    deprecate("Use TextEditor::moveLeft() instead")
    @moveLeft()

  TextEditor::moveCursorRight = ->
    deprecate("Use TextEditor::moveRight() instead")
    @moveRight()

  TextEditor::moveCursorToBeginningOfLine = ->
    deprecate("Use TextEditor::moveToBeginningOfLine() instead")
    @moveToBeginningOfLine()

  TextEditor::moveCursorToBeginningOfScreenLine = ->
    deprecate("Use TextEditor::moveToBeginningOfScreenLine() instead")
    @moveToBeginningOfScreenLine()

  TextEditor::moveCursorToFirstCharacterOfLine = ->
    deprecate("Use TextEditor::moveToFirstCharacterOfLine() instead")
    @moveToFirstCharacterOfLine()

  TextEditor::moveCursorToEndOfLine = ->
    deprecate("Use TextEditor::moveToEndOfLine() instead")
    @moveToEndOfLine()

  TextEditor::moveCursorToEndOfScreenLine = ->
    deprecate("Use TextEditor::moveToEndOfScreenLine() instead")
    @moveToEndOfScreenLine()

  TextEditor::moveCursorToBeginningOfWord = ->
    deprecate("Use TextEditor::moveToBeginningOfWord() instead")
    @moveToBeginningOfWord()

  TextEditor::moveCursorToEndOfWord = ->
    deprecate("Use TextEditor::moveToEndOfWord() instead")
    @moveToEndOfWord()

  TextEditor::moveCursorToTop = ->
    deprecate("Use TextEditor::moveToTop() instead")
    @moveToTop()

  TextEditor::moveCursorToBottom = ->
    deprecate("Use TextEditor::moveToBottom() instead")
    @moveToBottom()

  TextEditor::moveCursorToBeginningOfNextWord = ->
    deprecate("Use TextEditor::moveToBeginningOfNextWord() instead")
    @moveToBeginningOfNextWord()

  TextEditor::moveCursorToPreviousWordBoundary = ->
    deprecate("Use TextEditor::moveToPreviousWordBoundary() instead")
    @moveToPreviousWordBoundary()

  TextEditor::moveCursorToNextWordBoundary = ->
    deprecate("Use TextEditor::moveToNextWordBoundary() instead")
    @moveToNextWordBoundary()

  TextEditor::moveCursorToBeginningOfNextParagraph = ->
    deprecate("Use TextEditor::moveToBeginningOfNextParagraph() instead")
    @moveToBeginningOfNextParagraph()

  TextEditor::moveCursorToBeginningOfPreviousParagraph = ->
    deprecate("Use TextEditor::moveToBeginningOfPreviousParagraph() instead")
    @moveToBeginningOfPreviousParagraph()

  TextEditor::getCursor = ->
    deprecate("Use TextEditor::getLastCursor() instead")
    @getLastCursor()

  TextEditor::selectLine = ->
    deprecate('Use TextEditor::selectLinesContainingCursors instead')
    @selectLinesContainingCursors()

  TextEditor::selectWord = ->
    deprecate('Use TextEditor::selectWordsContainingCursors instead')
    @selectWordsContainingCursors()

  TextEditor::getSelection = (index) ->
    if index?
      deprecate("Use TextEditor::getSelections()[index] instead when getting a specific selection")
      @getSelections()[index]
    else
      deprecate("Use TextEditor::getLastSelection() instead")
      @getLastSelection()

  TextEditor::getSoftWrapped = ->
    deprecate("Use TextEditor::isSoftWrapped instead")
    @displayBuffer.isSoftWrapped()

  TextEditor::on = (eventName) ->
    switch eventName
      when 'title-changed'
        deprecate("Use TextEditor::onDidChangeTitle instead")
      when 'path-changed'
        deprecate("Use TextEditor::onDidChangePath instead")
      when 'modified-status-changed'
        deprecate("Use TextEditor::onDidChangeModified instead")
      when 'soft-wrap-changed'
        deprecate("Use TextEditor::onDidChangeSoftWrapped instead")
      when 'grammar-changed'
        deprecate("Use TextEditor::onDidChangeGrammar instead")
      when 'character-widths-changed'
        deprecate("Use TextEditor::onDidChangeCharacterWidths instead")
      when 'contents-modified'
        deprecate("Use TextEditor::onDidStopChanging instead")
      when 'contents-conflicted'
        deprecate("Use TextEditor::onDidConflict instead")

      when 'will-insert-text'
        deprecate("Use TextEditor::onWillInsertText instead")
      when 'did-insert-text'
        deprecate("Use TextEditor::onDidInsertText instead")

      when 'cursor-added'
        deprecate("Use TextEditor::onDidAddCursor instead")
      when 'cursor-removed'
        deprecate("Use TextEditor::onDidRemoveCursor instead")
      when 'cursor-moved'
        deprecate("Use TextEditor::onDidChangeCursorPosition instead")

      when 'selection-added'
        deprecate("Use TextEditor::onDidAddSelection instead")
      when 'selection-removed'
        deprecate("Use TextEditor::onDidRemoveSelection instead")
      when 'selection-screen-range-changed'
        deprecate("Use TextEditor::onDidChangeSelectionRange instead")

      when 'decoration-added'
        deprecate("Use TextEditor::onDidAddDecoration instead")
      when 'decoration-removed'
        deprecate("Use TextEditor::onDidRemoveDecoration instead")
      when 'decoration-updated'
        deprecate("Use Decoration::onDidChangeProperties instead. You will get the decoration back from `TextEditor::decorateMarker()`")
      when 'decoration-changed'
        deprecate("Use Marker::onDidChange instead. e.g. `editor::decorateMarker(...).getMarker().onDidChange()`")

      when 'screen-lines-changed'
        deprecate("Use TextEditor::onDidChange instead")

      when 'scroll-top-changed'
        deprecate("Use TextEditor::onDidChangeScrollTop instead")
      when 'scroll-left-changed'
        deprecate("Use TextEditor::onDidChangeScrollLeft instead")

      else
        deprecate("TextEditor::on is deprecated. Use documented event subscription methods instead.")

    EmitterMixin::on.apply(this, arguments)
