<commit_before>require "formula"

module Emacs
  def self.version
    Utils.popen_read("emacs", "--batch", "--eval", "(princ emacs-version)").to_f
  end

  def self.compile(*args)
    emacs_args = %w[emacs --batch -Q]

    # FIXME: lol
    formula_path = caller.first.gsub(/:.*/, "")
    f = Formulary.factory(formula_path)
    if f.deps.any?
      emacs_args << "-L"
      f.recursive_dependencies do |_, dep|
        Dir["#{dep.to_formula.opt_share}/emacs/site-lisp/**/*"].each do |x|
          x = Pathname.new(x)
          emacs_args << x if x.directory?
        end
      end
    end
    emacs_args << %w[-f batch-byte-compile]

    lisps = args.flatten
    lisps.each do |file|
      ohai "Byte compiling #{file}"
      emacs_args << file
      # TODO: why doesn't `system "emacs", *emacs_args` work here
      system emacs_args.join(" ")
    end
  end
end<commit_msg>Emacs.compile: pass the dir flag for each dir<commit_after>require "formula"

module Emacs
  def self.version
    Utils.popen_read("emacs", "--batch", "--eval", "(princ emacs-version)").to_f
  end

  def self.compile(*args)
    emacs_args = %w[emacs --batch -Q]

    # FIXME: lol
    formula_path = caller.first.gsub(/:.*/, "")
    f = Formulary.factory(formula_path)
    if f.deps.any?
      f.recursive_dependencies do |_, dep|
        Dir["#{dep.to_formula.opt_share}/emacs/site-lisp/**/*"].each do |x|
          x = Pathname.new(x)
          emacs_args << "--directory #{x}" if x.directory?
        end
      end
    end
    emacs_args << %w[-f batch-byte-compile]

    lisps = args.flatten
    lisps.each do |file|
      ohai "Byte compiling #{file}"
      emacs_args << file
      # TODO: why doesn't `system "emacs", *emacs_args` work here
      system emacs_args.join(" ")
    end
  end
end
{'fraction_non_alphanumeric': 0.15124153498871332, 'fraction_numerical': 0.0, 'mean_word_length': 2.462890625, 'pattern_counts': {'":': 0, '<': 17, '<?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': '1382808', 'n_tokens_mistral': 654, 'n_tokens_neox': 627, 'n_words': 145}