<commit_before>import sublime, sublime_plugin

# TODO: Consider adding one or more classes outside of the Command
# classes for better code modularization. Suboptimal parts of this
# code may be due to our use of class inheritance.
class IifefyCommand(sublime_plugin.TextCommand):

  def run(self, edit):
    self.settings = sublime.load_settings("Iifefy.sublime-settings")

    if self.somethingIsSelected():
      self.wrapSelections(edit)
    else:
      self.wrapAllContent(edit)

  def wrapSelections(self, edit):
    selections = self.view.sel()
    for selection in selections:
      if not selection.empty():
        self.generateIife(edit, selection)

  def wrapAllContent(self, edit):
    content = sublime.Region(0, self.view.size())
    self.generateIife(edit, content)

  def generateIife(self, edit, region):
    iifeContent = self.getIifeContent(region)
    iife = self.wrapIife(iifeContent, region)
    self.view.replace(edit, region, iife)

  def getIifeContent(self, region):
    iifeContent = ""
    lines = self.view.lines(region)
    precedingLinesEmpty = True
    for line in lines:
      precedingLinesEmpty = self.emptyLinesCheck(precedingLinesEmpty, line)

      if not precedingLinesEmpty:
        line = self.view.substr(line)
        line = self.wrapIifeLine(line)
        iifeContent = iifeContent + line

    return iifeContent

  def wrapIifeLine(self, line):
    return '\t' + line + '\n'

  # This is overriden by the IifefySkipCommentsCommand class.
  # IifefyCommand class passes String "content", while<commit_msg>fix issue where trailing whitespace was being added to blank lines<commit_after>import sublime, sublime_plugin

# TODO: Consider adding one or more classes outside of the Command
# classes for better code modularization. Suboptimal parts of this
# code may be due to our use of class inheritance.
class IifefyCommand(sublime_plugin.TextCommand):

  def run(self, edit):
    self.settings = sublime.load_settings("Iifefy.sublime-settings")

    if self.somethingIsSelected():
      self.wrapSelections(edit)
    else:
      self.wrapAllContent(edit)

  def wrapSelections(self, edit):
    selections = self.view.sel()
    for selection in selections:
      if not selection.empty():
        self.generateIife(edit, selection)

  def wrapAllContent(self, edit):
    content = sublime.Region(0, self.view.size())
    self.generateIife(edit, content)

  def generateIife(self, edit, region):
    iifeContent = self.getIifeContent(region)
    iife = self.wrapIife(iifeContent, region)
    self.view.replace(edit, region, iife)

  def getIifeContent(self, region):
    iifeContent = ""
    lines = self.view.lines(region)
    precedingLinesEmpty = True
    for line in lines:
      precedingLinesEmpty = self.emptyLinesCheck(precedingLinesEmpty, line)

      if not precedingLinesEmpty:
        line = self.view.substr(line)
        line = self.wrapIifeLine(line)
        iifeContent = iifeContent + line

    return iifeContent

  def wrapIifeLine(self, line):
    if not (line.isspace() or line == ''):
      line = '\t' + line
    return line + '\n'

  # This is overriden by the IifefySkipCommentsCommand class.
  # IifefyCommand class passes String "content", while
{'fraction_non_alphanumeric': 0.09178593652769135, 'fraction_numerical': 0.0006222775357809583, 'mean_word_length': 3.6459537572254335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2512769', 'n_tokens_mistral': 1006, 'n_tokens_neox': 959, 'n_words': 268}