<commit_before>;;; packages.el --- Ruby Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2016 <NAME> & Contributors
;;
;; Author: <NAME> <<EMAIL>>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(setq ruby-packages
      '(
        bundler
        chruby
        company
        (enh-ruby-mode :toggle ruby-enable-enh-ruby-mode)
        evil-matchit
        flycheck
        popwin
        rbenv
        robe
        rspec-mode
        rubocop
        (ruby-mode :location built-in :toggle (not ruby-enable-enh-ruby-mode))
        ruby-test-mode
        ruby-tools
        rvm
        smartparens
        rake
        ))

(defun ruby/init-bundler ()
  (use-package bundler
    :defer t
    :init
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (spacemacs/declare-prefix-for-mode mode "mb" "ruby/bundle")
      (spacemacs/set-leader-keys-for-major-mode mode
        "bc" 'bundle-check
        "bi" 'bundle-install
        "bs" 'bundle-console
        "bu" 'bundle-update
        "bx" 'bundle-exec
        "bo" 'bundle-open))))

(defun ruby/post-init-company ()
  (spacemacs|add-company-hook ruby-mode)
  (spacemacs|add-company-hook enh-ruby-mode)
  (with-eval-after-load 'company-dabbrev-code
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (push mode company-dabbrev-code-modes))))

(defun ruby/init-chruby ()
  (use-package chruby
    :if (equal ruby-version-manager 'chruby)
    :commands chruby-use-corresponding
    :defer t
    :init
    (progn
      (spacemacs/add-to-hooks 'chruby-use-corresponding
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/init-enh-ruby-mode ()
  (use-package enh-ruby-mode
    :mode (("Appraisals\\'" . enh-ruby-mode)
           ("\\(Rake\\|Thor\\|Guard\\|Gem\\|Cap\\|Vagrant\\|Berks\\|Pod\\|Puppet\\)file\\'" . enh-ruby-mode)
           ("\\.\\(rb\\|rabl\\|ru\\|builder\\|rake\\|thor\\|gemspec\\|jbuilder\\)\\'" . enh-ruby-mode))
    :interpreter "ruby"
    :config
    (progn
      (setq enh-ruby-deep-indent-paren nil
            enh-ruby-hanging-paren-deep-indent-level 2))))

(defun ruby/post-init-evil-matchit ()
  (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
    (add-hook hook `turn-on-evil-matchit-mode)))

(defun ruby/post-init-flycheck ()
  (spacemacs/add-flycheck-hook 'ruby-mode)
  (spacemacs/add-flycheck-hook 'enh-ruby-mode))

(defun ruby/post-init-popwin ()
  (push '("*rspec-compilation*" :dedicated t :position bottom :stick t :noselect t :height 0.4)
        popwin:special-display-config)
  (push '("*rake-compilation*" :dedicated t :position bottom :stick t :noselect t :height 0.4)
        popwin:special-display-config))

(defun ruby/init-rbenv ()
  (use-package rbenv
    :if (equal ruby-version-manager 'rbenv)
    :defer t
    :init
    (progn
      (defun spacemacs//enable-rbenv ()
        "Enable rbenv, use .ruby-version if exists."
        (require 'rbenv)
        (let ((version-file-path (rbenv--locate-file ".ruby-version")))
          (global-rbenv-mode)
          ;; try to use the ruby defined in .ruby-version
          (if version-file-path
              (progn
                (rbenv-use (rbenv--read-version-from-file
                            version-file-path))
                (message (concat "[rbenv] Using ruby version "
                                 "from .ruby-version file.")))
            (message "[rbenv] Using the currently activated ruby."))))
      (spacemacs/add-to-hooks 'spacemacs//enable-rbenv
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/init-robe ()
  (use-package robe
    :defer t
    :init
    (progn
      (spacemacs/register-repl 'robe 'robe-start "robe")
      (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
        (add-hook hook 'robe-mode))
      (when (configuration-layer/package-usedp 'company)
        (push 'company-robe company-backends-enh-ruby-mode)
        (push 'company-robe company-backends-ruby-mode)))
    :config
    (progn
      (spacemacs|hide-lighter robe-mode)

      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mg" "ruby/goto")
        (spacemacs/declare-prefix-for-mode mode "mh" "ruby/docs")
        (spacemacs/declare-prefix-for-mode mode "ms" "ruby/repl")
        (spacemacs/set-leader-keys-for-major-mode mode
          "'" 'robe-start
          ;; robe mode specific
          "gg" 'robe-jump
          "hd" 'robe-doc
          "rsr" 'robe-rails-refresh
          ;; inf-enh-ruby-mode
          "sf" 'ruby-send-definition
          "sF" 'ruby-send-definition-and-go
          "si" 'robe-start
          "sr" 'ruby-send-region
          "sR" 'ruby-send-region-and-go
          "ss" 'ruby-switch-to-inf)))))

(defun ruby/init-rspec-mode ()
  (use-package rspec-mode
    :defer t
    ;; there is no :init block to add the hooks since rspec-mode
    ;; setup the hook via an autoload
    :config
    (progn
      (spacemacs|hide-lighter rspec-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/set-leader-keys-for-major-mode mode
          "ta"    'rspec-verify-all
          "tb"    'rspec-verify
          "tc"    'rspec-verify-continue
          "te"    'rspec-toggle-example-pendingness
          "tf"    'rspec-verify-method
          "tl"    'rspec-run-last-failed
          "tm"    'rspec-verify-matching
          "tr"    'rspec-rerun
          "tt"    'rspec-verify-single
          "t~"    'rspec-toggle-spec-and-target-find-example
          "t TAB" 'rspec-toggle-spec-and-target)))))

(defun ruby/init-rubocop ()
  (use-package rubocop
    :defer t
    :init (spacemacs/add-to-hooks 'rubocop-mode '(ruby-mode-hook
                                                  enh-ruby-mode-hook))
    :config
    (progn
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mrr" "ruby/RuboCop")
        (spacemacs/set-leader-keys-for-major-mode mode
          "rrd" 'rubocop-check-directory
          "rrD" 'rubocop-autocorrect-directory
          "rrf" 'rubocop-check-current-file
          "rrF" 'rubocop-autocorrect-current-file
          "rrp" 'rubocop-check-project
          "rrP" 'rubocop-autocorrect-project)))))

(defun ruby/init-ruby-mode ()
  (use-package ruby-mode
    :defer t
    :mode (("Appraisals\\'" . ruby-mode)
           ("Puppetfile" . ruby-mode))
    :init (spacemacs/declare-prefix-for-mode 'ruby-mode "mt" "ruby/test")
    :config
    (progn
      (spacemacs/set-leader-keys-for-major-mode 'ruby-mode
        "'" 'ruby-toggle-string-quotes
        "{" 'ruby-toggle-block))))

(defun ruby/init-ruby-tools ()
  (use-package ruby-tools
    :defer t
    :init
    (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
      (add-hook hook 'ruby-tools-mode))
    :config
    (progn
      (spacemacs|hide-lighter ruby-tools-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mx" "ruby/text")
        (spacemacs/set-leader-keys-for-major-mode mode
          "x\'" 'ruby-tools-to-single-quote-string
          "x\"" 'ruby-tools-to-double-quote-string
          "x:" 'ruby-tools-to-symbol)))))

(defun ruby/init-ruby-test-mode ()
  "Define keybindings for ruby test mode"
  (use-package ruby-test-mode)
    :defer t
    :init
    (progn
      (defun spacemacs//ruby-enable-ruby-test-mode ()
        "Conditionally enable `ruby-test-mode'"
        (when (eq 'ruby-test ruby-test-runner)
          (ruby-test-mode)))
      (spacemacs/add-to-hooks
       'spacemacs//ruby-enable-ruby-test-mode '(ruby-mode-hook
                                                enh-ruby-mode-hook)))
    :config
    (progn
      (spacemacs|hide-lighter ruby-test-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/set-leader-keys-for-major-mode mode
          "tb" 'ruby-test-run
          "tt" 'ruby-test-run-at-point))))

(defun ruby/init-rvm ()
  (use-package rvm
    :if (equal ruby-version-manager 'rvm)
    :defer t
    :init
    (progn
      (setq rspec-use-rvm t)
      (spacemacs/add-to-hooks 'rvm-activate-corresponding-ruby
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/post-init-smartparens ()
  (spacemacs|use-package-add-hook smartparens
    :post-config
    (sp-with-modes (if ruby-enable-enh-ruby-mode 'enh-ruby-mode 'ruby-mode)
      (sp-local-pair
       "{" "}"
       :pre-handlers '(sp-ruby-pre-handler)
       :post-handlers '(sp-ruby-post-handler
                        (spacemacs/smartparens-pair-newline-and-indent "RET"))
       :suffix ""))))

(defun ruby/init-rake ()
  (use-package rake
    :defer t
    :init (setq rake-cache-file (concat spacemacs-cache-directory "rake.cache"))
    :config
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (spacemacs/set-leader-keys-for-major-mode mode
        "kk"    'rake
        "kr"    'rake-rerun
        "kR"    'rake-regenerate-cache
        "kf"    'rake-find-task))))
<commit_msg>[ruby-layer] Adding ruby/rspec-verify-directory method for running specs for a specific directory.<commit_after>;;; packages.el --- Ruby Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2016 <NAME> & Contributors
;;
;; Author: <NAME> <<EMAIL>>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3

(setq ruby-packages
      '(
        bundler
        chruby
        company
        (enh-ruby-mode :toggle ruby-enable-enh-ruby-mode)
        evil-matchit
        flycheck
        popwin
        rbenv
        robe
        rspec-mode
        rubocop
        (ruby-mode :location built-in :toggle (not ruby-enable-enh-ruby-mode))
        ruby-test-mode
        ruby-tools
        rvm
        smartparens
        rake
        ))

(defun ruby/init-bundler ()
  (use-package bundler
    :defer t
    :init
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (spacemacs/declare-prefix-for-mode mode "mb" "ruby/bundle")
      (spacemacs/set-leader-keys-for-major-mode mode
        "bc" 'bundle-check
        "bi" 'bundle-install
        "bs" 'bundle-console
        "bu" 'bundle-update
        "bx" 'bundle-exec
        "bo" 'bundle-open))))

(defun ruby/post-init-company ()
  (spacemacs|add-company-hook ruby-mode)
  (spacemacs|add-company-hook enh-ruby-mode)
  (with-eval-after-load 'company-dabbrev-code
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (push mode company-dabbrev-code-modes))))

(defun ruby/init-chruby ()
  (use-package chruby
    :if (equal ruby-version-manager 'chruby)
    :commands chruby-use-corresponding
    :defer t
    :init
    (progn
      (spacemacs/add-to-hooks 'chruby-use-corresponding
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/init-enh-ruby-mode ()
  (use-package enh-ruby-mode
    :mode (("Appraisals\\'" . enh-ruby-mode)
           ("\\(Rake\\|Thor\\|Guard\\|Gem\\|Cap\\|Vagrant\\|Berks\\|Pod\\|Puppet\\)file\\'" . enh-ruby-mode)
           ("\\.\\(rb\\|rabl\\|ru\\|builder\\|rake\\|thor\\|gemspec\\|jbuilder\\)\\'" . enh-ruby-mode))
    :interpreter "ruby"
    :config
    (progn
      (setq enh-ruby-deep-indent-paren nil
            enh-ruby-hanging-paren-deep-indent-level 2))))

(defun ruby/post-init-evil-matchit ()
  (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
    (add-hook hook `turn-on-evil-matchit-mode)))

(defun ruby/post-init-flycheck ()
  (spacemacs/add-flycheck-hook 'ruby-mode)
  (spacemacs/add-flycheck-hook 'enh-ruby-mode))

(defun ruby/post-init-popwin ()
  (push '("*rspec-compilation*" :dedicated t :position bottom :stick t :noselect t :height 0.4)
        popwin:special-display-config)
  (push '("*rake-compilation*" :dedicated t :position bottom :stick t :noselect t :height 0.4)
        popwin:special-display-config))

(defun ruby/init-rbenv ()
  (use-package rbenv
    :if (equal ruby-version-manager 'rbenv)
    :defer t
    :init
    (progn
      (defun spacemacs//enable-rbenv ()
        "Enable rbenv, use .ruby-version if exists."
        (require 'rbenv)
        (let ((version-file-path (rbenv--locate-file ".ruby-version")))
          (global-rbenv-mode)
          ;; try to use the ruby defined in .ruby-version
          (if version-file-path
              (progn
                (rbenv-use (rbenv--read-version-from-file
                            version-file-path))
                (message (concat "[rbenv] Using ruby version "
                                 "from .ruby-version file.")))
            (message "[rbenv] Using the currently activated ruby."))))
      (spacemacs/add-to-hooks 'spacemacs//enable-rbenv
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/init-robe ()
  (use-package robe
    :defer t
    :init
    (progn
      (spacemacs/register-repl 'robe 'robe-start "robe")
      (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
        (add-hook hook 'robe-mode))
      (when (configuration-layer/package-usedp 'company)
        (push 'company-robe company-backends-enh-ruby-mode)
        (push 'company-robe company-backends-ruby-mode)))
    :config
    (progn
      (spacemacs|hide-lighter robe-mode)

      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mg" "ruby/goto")
        (spacemacs/declare-prefix-for-mode mode "mh" "ruby/docs")
        (spacemacs/declare-prefix-for-mode mode "ms" "ruby/repl")
        (spacemacs/set-leader-keys-for-major-mode mode
          "'" 'robe-start
          ;; robe mode specific
          "gg" 'robe-jump
          "hd" 'robe-doc
          "rsr" 'robe-rails-refresh
          ;; inf-enh-ruby-mode
          "sf" 'ruby-send-definition
          "sF" 'ruby-send-definition-and-go
          "si" 'robe-start
          "sr" 'ruby-send-region
          "sR" 'ruby-send-region-and-go
          "ss" 'ruby-switch-to-inf)))))

(defun ruby/init-rspec-mode ()
  (use-package rspec-mode
    :defer t
    ;; there is no :init block to add the hooks since rspec-mode
    ;; setup the hook via an autoload
    :config
    (progn
      (defun ruby/rspec-verify-directory (dir)
        (interactive "Drspec directory: ")
        (rspec-run-single-file dir (rspec-core-options)))
      (spacemacs|hide-lighter rspec-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/set-leader-keys-for-major-mode mode
          "ta"    'rspec-verify-all
          "tb"    'rspec-verify
          "tc"    'rspec-verify-continue
          "td"    'ruby/rspec-verify-directory
          "te"    'rspec-toggle-example-pendingness
          "tf"    'rspec-verify-method
          "tl"    'rspec-run-last-failed
          "tm"    'rspec-verify-matching
          "tr"    'rspec-rerun
          "tt"    'rspec-verify-single
          "t~"    'rspec-toggle-spec-and-target-find-example
          "t TAB" 'rspec-toggle-spec-and-target)))))

(defun ruby/init-rubocop ()
  (use-package rubocop
    :defer t
    :init (spacemacs/add-to-hooks 'rubocop-mode '(ruby-mode-hook
                                                  enh-ruby-mode-hook))
    :config
    (progn
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mrr" "ruby/RuboCop")
        (spacemacs/set-leader-keys-for-major-mode mode
          "rrd" 'rubocop-check-directory
          "rrD" 'rubocop-autocorrect-directory
          "rrf" 'rubocop-check-current-file
          "rrF" 'rubocop-autocorrect-current-file
          "rrp" 'rubocop-check-project
          "rrP" 'rubocop-autocorrect-project)))))

(defun ruby/init-ruby-mode ()
  (use-package ruby-mode
    :defer t
    :mode (("Appraisals\\'" . ruby-mode)
           ("Puppetfile" . ruby-mode))
    :init (spacemacs/declare-prefix-for-mode 'ruby-mode "mt" "ruby/test")
    :config
    (progn
      (spacemacs/set-leader-keys-for-major-mode 'ruby-mode
        "'" 'ruby-toggle-string-quotes
        "{" 'ruby-toggle-block))))

(defun ruby/init-ruby-tools ()
  (use-package ruby-tools
    :defer t
    :init
    (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
      (add-hook hook 'ruby-tools-mode))
    :config
    (progn
      (spacemacs|hide-lighter ruby-tools-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/declare-prefix-for-mode mode "mx" "ruby/text")
        (spacemacs/set-leader-keys-for-major-mode mode
          "x\'" 'ruby-tools-to-single-quote-string
          "x\"" 'ruby-tools-to-double-quote-string
          "x:" 'ruby-tools-to-symbol)))))

(defun ruby/init-ruby-test-mode ()
  "Define keybindings for ruby test mode"
  (use-package ruby-test-mode)
    :defer t
    :init
    (progn
      (defun spacemacs//ruby-enable-ruby-test-mode ()
        "Conditionally enable `ruby-test-mode'"
        (when (eq 'ruby-test ruby-test-runner)
          (ruby-test-mode)))
      (spacemacs/add-to-hooks
       'spacemacs//ruby-enable-ruby-test-mode '(ruby-mode-hook
                                                enh-ruby-mode-hook)))
    :config
    (progn
      (spacemacs|hide-lighter ruby-test-mode)
      (dolist (mode '(ruby-mode enh-ruby-mode))
        (spacemacs/set-leader-keys-for-major-mode mode
          "tb" 'ruby-test-run
          "tt" 'ruby-test-run-at-point))))

(defun ruby/init-rvm ()
  (use-package rvm
    :if (equal ruby-version-manager 'rvm)
    :defer t
    :init
    (progn
      (setq rspec-use-rvm t)
      (spacemacs/add-to-hooks 'rvm-activate-corresponding-ruby
                              '(ruby-mode-hook enh-ruby-mode-hook)))))

(defun ruby/post-init-smartparens ()
  (spacemacs|use-package-add-hook smartparens
    :post-config
    (sp-with-modes (if ruby-enable-enh-ruby-mode 'enh-ruby-mode 'ruby-mode)
      (sp-local-pair
       "{" "}"
       :pre-handlers '(sp-ruby-pre-handler)
       :post-handlers '(sp-ruby-post-handler
                        (spacemacs/smartparens-pair-newline-and-indent "RET"))
       :suffix ""))))

(defun ruby/init-rake ()
  (use-package rake
    :defer t
    :init (setq rake-cache-file (concat spacemacs-cache-directory "rake.cache"))
    :config
    (dolist (mode '(ruby-mode enh-ruby-mode))
      (spacemacs/set-leader-keys-for-major-mode mode
        "kk"    'rake
        "kr"    'rake-rerun
        "kR"    'rake-regenerate-cache
        "kf"    'rake-find-task))))

{'fraction_non_alphanumeric': 0.15285855371447382, 'fraction_numerical': 0.0017557335674311424, 'mean_word_length': 2.091417910447761, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '97510', 'n_tokens_mistral': 6826, 'n_tokens_neox': 6413, 'n_words': 1153}