<commit_before># View to show the grammar name in the status bar.
class GrammarStatusView extends HTMLElement
  initialize: (@statusBar) ->
    @classList.add('grammar-status', 'inline-block')
    @grammarLink = document.createElement('a')
    @grammarLink.classList.add('inline-block')
    @grammarLink.href = '#'
    @appendChild(@grammarLink)
    @handleEvents()

  attach: ->
    if atom.config.get 'grammar-selector.showOnRightSideOfStatusBar'
      @statusBar.prependRight(this)
    else
      @statusBar.appendLeft(this)

  handleEvents: ->
    @activeItemSubscription = atom.workspace.onDidChangeActivePaneItem =>
      @subscribeToActiveTextEditor()

    @configSubscription = atom.config.observe 'grammar-selector.showOnRightSideOfStatusBar', =>
      @attach()

    clickHandler = ->
      atom.workspaceView.trigger('grammar-selector:show')
      false
    @addEventListener('click', clickHandler)
    @clickSubscription = dispose: => @removeEventListener('click', clickHandler)

    @subscribeToActiveTextEditor()

  destroy: ->
    @activeItemSubscription.dispose()
    @grammarSubscription.dispose()
    @clickSubscription.dispose()
    @configSubscription.off()
    @remove()

  getActiveTextEditor: ->
    atom.workspace.getActiveTextEditor()

  subscribeToActiveTextEditor: ->
    @grammarSubscription?.dispose()
    @grammarSubscription = @getActiveTextEditor()?.onDidChangeGrammar =>
      @updateGrammarText()
    @updateGrammarText()
<commit_msg>Guard against null subscriptions<commit_after># View to show the grammar name in the status bar.
class GrammarStatusView extends HTMLElement
  initialize: (@statusBar) ->
    @classList.add('grammar-status', 'inline-block')
    @grammarLink = document.createElement('a')
    @grammarLink.classList.add('inline-block')
    @grammarLink.href = '#'
    @appendChild(@grammarLink)
    @handleEvents()

  attach: ->
    if atom.config.get 'grammar-selector.showOnRightSideOfStatusBar'
      @statusBar.prependRight(this)
    else
      @statusBar.appendLeft(this)

  handleEvents: ->
    @activeItemSubscription = atom.workspace.onDidChangeActivePaneItem =>
      @subscribeToActiveTextEditor()

    @configSubscription = atom.config.observe 'grammar-selector.showOnRightSideOfStatusBar', =>
      @attach()

    clickHandler = ->
      atom.workspaceView.trigger('grammar-selector:show')
      false
    @addEventListener('click', clickHandler)
    @clickSubscription = dispose: => @removeEventListener('click', clickHandler)

    @subscribeToActiveTextEditor()

  destroy: ->
    @activeItemSubscription?.dispose()
    @grammarSubscription?.dispose()
    @clickSubscription?.dispose()
    @configSubscription?.off()
    @remove()

  getActiveTextEditor: ->
    atom.workspace.getActiveTextEditor()

  subscribeToActiveTextEditor: ->
    @grammarSubscription?.dispose()
    @grammarSubscription = @getActiveTextEditor()?.onDidChangeGrammar =>
      @updateGrammarText()
    @updateGrammarText()

{'fraction_non_alphanumeric': 0.12031091584994931, 'fraction_numerical': 0.0, 'mean_word_length': 4.323741007194244, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '495904', 'n_tokens_mistral': 863, 'n_tokens_neox': 864, 'n_words': 131}