This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/ruby/packages.el

308 lines
11 KiB
EmacsLisp
Raw Normal View History

;;; packages.el --- Ruby Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; 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
ggtags
counsel-gtags
helm-gtags
minitest
2017-04-26 11:42:13 +00:00
org
2016-01-23 16:08:18 +00:00
popwin
rbenv
robe
rspec-mode
2015-09-08 23:03:42 +00:00
rubocop
(ruby-mode :location built-in :toggle (not ruby-enable-enh-ruby-mode))
ruby-refactor
2015-12-06 02:08:22 +00:00
ruby-test-mode
ruby-tools
rvm
smartparens
2016-02-29 19:24:52 +00:00
rake
2015-09-08 23:03:42 +00:00
))
2015-12-06 02:08:22 +00:00
(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))))
2015-12-06 02:08:22 +00:00
(defun ruby/post-init-company ()
(when (configuration-layer/package-used-p 'robe)
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends
:backends company-robe
:modes ruby-mode enh-ruby-mode))
(with-eval-after-load 'company-dabbrev-code
(dolist (mode '(ruby-mode enh-ruby-mode))
(push mode company-dabbrev-code-modes))))
2015-12-06 02:08:22 +00:00
(defun ruby/init-chruby ()
2015-07-14 12:38:27 +00:00
(use-package chruby
:if (equal ruby-version-manager 'chruby)
:commands chruby-use-corresponding
2015-07-14 12:38:27 +00:00
:defer t
:init (spacemacs/add-to-hooks 'chruby-use-corresponding
'(ruby-mode-hook enh-ruby-mode-hook))))
2015-07-14 12:38:27 +00:00
2015-02-21 03:47:12 +00:00
(defun ruby/init-enh-ruby-mode ()
(use-package enh-ruby-mode
2016-02-24 13:40:25 +00:00
: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"
2016-08-13 13:43:37 +00:00
:init
(progn
(setq enh-ruby-deep-indent-paren nil
enh-ruby-hanging-paren-deep-indent-level 2))))
2014-12-08 21:04:34 +00:00
(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/enable-flycheck 'ruby-mode)
(spacemacs/enable-flycheck 'enh-ruby-mode))
(defun ruby/post-init-ggtags ()
(add-hook 'ruby-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun ruby/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'ruby-mode))
(defun ruby/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'ruby-mode))
(defun ruby/init-minitest ()
(use-package minitest
:defer t
:init
(progn
(spacemacs/add-to-hooks 'spacemacs//ruby-enable-minitest-mode
'(ruby-mode-local-vars-hook
enh-ruby-mode-local-vars-hook))
;; remove hooks added by minitest mode
(dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
(remove-hook hook 'minitest-enable-appropriate-mode)))
:config
(progn
(spacemacs|hide-lighter minitest-mode)
(dolist (mode '(ruby-mode enh-ruby-mode))
(spacemacs/set-leader-keys-for-major-mode mode
"ta" 'minitest-verify-all
"tb" 'minitest-verify
"tr" 'minitest-rerun
"ts" 'minitest-verify-single)))))
2017-04-26 11:42:13 +00:00
(defun ruby/pre-init-org ()
(spacemacs|use-package-add-hook org
:post-config (add-to-list 'org-babel-load-languages '(ruby . t))))
2016-01-23 16:08:18 +00:00
(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)
2016-01-23 16:08:18 +00:00
popwin:special-display-config))
2015-12-06 02:08:22 +00:00
(defun ruby/init-rbenv ()
(use-package rbenv
:if (equal ruby-version-manager 'rbenv)
:defer t
:init (spacemacs/add-to-hooks 'spacemacs//enable-rbenv
'(ruby-mode-hook enh-ruby-mode-hook))))
2014-12-08 21:04:34 +00:00
(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))
2016-08-13 13:43:37 +00:00
(spacemacs/add-to-hooks 'robe-jump
'(spacemacs-jump-handlers-ruby-mode
spacemacs-jump-handlers-enh-ruby-mode)))
:config
(progn
2015-03-21 22:41:31 +00:00
(spacemacs|hide-lighter robe-mode)
(dolist (mode '(ruby-mode enh-ruby-mode))
2015-10-20 08:17:43 +00:00
(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
"hh" '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)))))
2014-12-08 21:04:34 +00:00
(defun ruby/init-rspec-mode ()
(use-package rspec-mode
:defer t
:init
(progn
(spacemacs/add-to-hooks 'spacemacs//ruby-enable-rspec-mode
'(ruby-mode-local-vars-hook
enh-ruby-mode-local-vars-hook))
;; remove hooks automatically added by rspec via autoload
;; because we want to be able to control when rspec-mode is
;; loaded based on the layer variable `ruby-test-runner'
(dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
(remove-hook hook 'rspec-enable-appropriate-mode)))
2015-03-09 03:12:28 +00:00
:config
(progn
(add-hook 'rspec-compilation-mode-hook 'spacemacs//inf-ruby-auto-enter)
(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)))))
2015-09-08 23:03:42 +00:00
(defun ruby/init-rubocop ()
(use-package rubocop
:defer t
:init (spacemacs/add-to-hooks 'rubocop-mode '(ruby-mode-hook
enh-ruby-mode-hook))
:config (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))))
2015-09-08 23:03:42 +00:00
2015-12-06 02:08:22 +00:00
(defun ruby/init-ruby-mode ()
(use-package ruby-mode
:defer t
2016-02-24 13:40:25 +00:00
:mode (("Appraisals\\'" . ruby-mode)
("Puppetfile" . ruby-mode))
2016-08-13 13:43:37 +00:00
:init
(progn
2017-01-04 23:14:10 +00:00
(spacemacs/declare-prefix-for-mode 'ruby-mode "mt" "ruby/test")
(spacemacs/add-to-hooks
'spacemacs/ruby-maybe-highlight-debugger-keywords
'(ruby-mode-local-vars-hook enh-ruby-mode-local-vars-hook)))
:config (spacemacs/set-leader-keys-for-major-mode 'ruby-mode
"'" 'ruby-toggle-string-quotes
"{" 'ruby-toggle-block)))
2015-12-06 02:08:22 +00:00
(defun ruby/init-ruby-refactor ()
(use-package ruby-refactor
:defer t
:init (dolist (hook '(ruby-mode-hook enh-ruby-mode-hook))
(add-hook hook 'ruby-refactor-mode-launch))
:config
(progn
(dolist (mode '(ruby-mode enh-ruby-mode))
(spacemacs/declare-prefix-for-mode mode "mrR" "ruby/refactor")
(spacemacs/set-leader-keys-for-major-mode mode
"rRm" 'ruby-refactor-extract-to-method
"rRv" 'ruby-refactor-extract-local-variable
"rRc" 'ruby-refactor-extract-constant
"rRl" 'ruby-refactor-extract-to-let)))))
2015-12-06 02:08:22 +00:00
(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))
2015-12-06 02:08:22 +00:00
: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 (spacemacs/add-to-hooks 'spacemacs//ruby-enable-ruby-test-mode
'(ruby-mode-local-vars-hook
enh-ruby-mode-local-vars-hook))
:config
(progn
;; `ruby-test-mode' adds a hook to enable itself, this hack
;; removes it to be sure that we control the loading of the
;; mode
(remove-hook 'ruby-mode-hook 'ruby-test-enable)
(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 ""))))
2016-02-29 19:24:52 +00:00
(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))))