<commit_before>{SelectListView} = require 'atom'

# View to display a list of grammars to apply to the current editor.
module.exports =
class GrammarListView extends SelectListView
  initialize: (@editor) ->
    super

    @addClass('grammar-selector from-top overlay')
    @list.addClass('mark-active')

    @autoDetect = name: 'Auto Detect'
    @currentGrammar = @editor.getGrammar()
    @currentGrammar = @autoDetect if @currentGrammar is atom.syntax.nullGrammar

    @subscribe this, 'grammar-selector:show', =>
      @cancel()
      false

    @setItems(@getGrammars())

  getFilterKey: ->
    'name'

  viewForItem: (grammar) ->
    element = document.createElement('li')
    element.classList.add('active') if grammar is @currentGrammar
    element.textContent = grammar.name ? grammar.scopeName
    element

  confirmed: (grammar) ->
    @cancel()
    if grammar is @autoDetect
      atom.syntax.clearGrammarOverrideForPath(@editor.getPath())
    else
      atom.syntax.setGrammarOverrideForPath(@editor.getPath(), grammar.scopeName)
    @editor.reloadGrammar()

  attach: ->
    @storeFocusedElement()
    atom.workspaceView.append(this)
    @focusFilterEditor()

  getGrammars: ->
    grammars = atom.syntax.getGrammars().filter (grammar) ->
      grammar isnt atom.syntax.nullGrammar

    grammars.sort (grammarA, grammarB) ->
      if grammarA.scopeName is 'text.plain'
        -1
      else if grammarB.scopeName is 'text.plain'
        1
      else
        grammarA.name?.localeCompare?(grammarB.name) ? grammarA.scopeName?.localeCompare?(grammarB.name) ? 1<commit_msg>Call Editor::setGrammar instead of Editor::reloadGrammar<commit_after>{SelectListView} = require 'atom'

# View to display a list of grammars to apply to the current editor.
module.exports =
class GrammarListView extends SelectListView
  initialize: (@editor) ->
    super

    @addClass('grammar-selector from-top overlay')
    @list.addClass('mark-active')

    @autoDetect = name: 'Auto Detect'
    @currentGrammar = @editor.getGrammar()
    @currentGrammar = @autoDetect if @currentGrammar is atom.syntax.nullGrammar

    @subscribe this, 'grammar-selector:show', =>
      @cancel()
      false

    @setItems(@getGrammars())

  getFilterKey: ->
    'name'

  viewForItem: (grammar) ->
    element = document.createElement('li')
    element.classList.add('active') if grammar is @currentGrammar
    element.textContent = grammar.name ? grammar.scopeName
    element

  confirmed: (grammar) ->
    @cancel()
    if grammar is @autoDetect
      atom.syntax.clearGrammarOverrideForPath(@editor.getPath())
      @editor.reloadGrammar()
    else
      atom.syntax.setGrammarOverrideForPath(@editor.getPath(), grammar.scopeName)
      @editor.setGrammar(grammar)

  attach: ->
    @storeFocusedElement()
    atom.workspaceView.append(this)
    @focusFilterEditor()

  getGrammars: ->
    grammars = atom.syntax.getGrammars().filter (grammar) ->
      grammar isnt atom.syntax.nullGrammar

    grammars.sort (grammarA, grammarB) ->
      if grammarA.scopeName is 'text.plain'
        -1
      else if grammarB.scopeName is 'text.plain'
        1
      else
        grammarA.name?.localeCompare?(grammarB.name) ? grammarA.scopeName?.localeCompare?(grammarB.name) ? 1
{'fraction_non_alphanumeric': 0.11648690292758089, 'fraction_numerical': 0.0018489984591679508, 'mean_word_length': 3.4649243466299864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1435884', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1007, 'n_words': 208}