<commit_before>require File.expand_path("../../Homebrew/emacs_formula", __FILE__)

class CompanyMode < EmacsFormula
  desc "Modular in-buffer completion framework for Emacs"
  homepage "http://company-mode.github.io"
  url "https://github.com/company-mode/company-mode/archive/0.8.12.tar.gz"
  sha256 "ff7f70a13e353181526f8a11145f543955fb3f76c6772cf6d79912782a5e95ef"
  head "https://github.com/company-mode/company-mode.git"

  depends_on :emacs => "24.1"
  depends_on "homebrew/emacs/cl-lib" if Emacs.version < 24.3

  def install
    system "make", "test-batch"
    system "make", "compile"

    (share/"emacs/site-lisp/company").install Dir["company*.el"],
                                              Dir["company*.elc"]
    doc.install "README.md"
  end

  def caveats; <<-EOS.undent
    Add the following to your init file:

    (require 'company)
    (add-hook 'after-init-hook 'global-company-mode)
  EOS
  end

  test do
    (testpath/"test.el").write <<-EOS.undent<commit_msg>company-mode: add with-web option<commit_after>require File.expand_path("../../Homebrew/emacs_formula", __FILE__)

class CompanyMode < EmacsFormula
  desc "Modular in-buffer completion framework for Emacs"
  homepage "http://company-mode.github.io"
  url "https://github.com/company-mode/company-mode/archive/0.8.12.tar.gz"
  sha256 "ff7f70a13e353181526f8a11145f543955fb3f76c6772cf6d79912782a5e95ef"
  head "https://github.com/company-mode/company-mode.git"

  depends_on :emacs => "24.1"
  depends_on "homebrew/emacs/cl-lib" if Emacs.version < 24.3

  option "with-web", "Install company-web"

  if build.with? "web"
    depends_on "homebrew/emacs/dash"
    depends_on "homebrew/emacs/web-completion-data"
  end

  resource "web" do
    url "https://github.com/osv/company-web/archive/v0.9.tar.gz"
    sha256 "c5e26ae5eb9f7c57684b24ad9a960fa86df5ab2e2dac14b7b1068f3853a98622"
  end

  def install
    if build.with? "web"
      resource("web").stage do
        byte_compile Dir["*.el"]
        (share/"emacs/site-lisp/company/web").install Dir["*.el"],
                                                      Dir["*.elc"]
      end
    end

    system "make", "test-batch"
    system "make", "compile"
    (share/"emacs/site-lisp/company").install Dir["company*.el"],
                                              Dir["company*.elc"]
    doc.install "README.md"
  end

  def caveats
    s = <<-EOS.undent
      Add the following to your init file:

      (require 'company)
      (add-hook 'after-init-hook 'global-company-mode)
    EOS
    if build.with? "web"
      s += <<-EOS.undent

      (require 'company-web-html)
    EOS
    end
    s
  end

  test do
    (testpath/"test.el").write <<-EOS.undent
{'fraction_non_alphanumeric': 0.13707280832095098, 'fraction_numerical': 0.05906389301634472, 'mean_word_length': 2.7042640990371387, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2322790', 'n_tokens_mistral': 1047, 'n_tokens_neox': 962, 'n_words': 173}