From ff0dff65db9a61f22e77b8843f72f361ccbba9cc Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Mon, 1 Oct 2018 09:31:26 +0100 Subject: [PATCH] Add ruby-guard package to vendor directory --- Makefile | 1 + modules/languages/siren-ruby.el | 4 ++ vendor/ruby-guard.el | 82 +++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 vendor/ruby-guard.el diff --git a/Makefile b/Makefile index 6fee315..f012b5d 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ $(eval $(call vendored,vendor/dired+.el,https://www.emacswiki.org/emacs/download $(eval $(call vendored,vendor/escreen.el,https://github.com/renard/escreen-el/raw/master/escreen.el)) $(eval $(call vendored,vendor/hideshowvis.el,https://www.emacswiki.org/emacs/download/hideshowvis.el)) $(eval $(call vendored,vendor/linum+.el,http://www.emacswiki.org/emacs/download/linum%2b.el)) +$(eval $(call vendored,vendor/ruby-guard.el,https://github.com/zhangkaiyulw/ruby-guard/raw/master/ruby-guard.el)) $(eval $(call vendored,vendor/tomorrow-night-paradise-theme.el,https://github.com/jimeh/tomorrow-night-paradise-theme.el/raw/master/tomorrow-night-paradise-theme.el)) diff --git a/modules/languages/siren-ruby.el b/modules/languages/siren-ruby.el index 17084c2..d017fa0 100644 --- a/modules/languages/siren-ruby.el +++ b/modules/languages/siren-ruby.el @@ -145,6 +145,10 @@ (use-package ruby-compilation :defer t) +(use-package ruby-guard + :ensure nil ;; loaded from vendor + :commands ruby-guard) + (use-package ruby-refactor :defer t :hook diff --git a/vendor/ruby-guard.el b/vendor/ruby-guard.el new file mode 100644 index 0000000..0a3c2b5 --- /dev/null +++ b/vendor/ruby-guard.el @@ -0,0 +1,82 @@ +;;; ruby-guard.el --- Launching guard directly inside emacs. + +;; Copyright (C) 2014 Zhang Kai Yu + +;; Author: Zhang Kai Yu +;; Version: 0.1.0 +;; Keywords: ruby, guard, rails +;; URL: https://github.com/cheunghy/ruby-guard + +;;; Commentary: + +;; M-x ruby-guard to launch. + +;;; Code: + +(defvar ruby-guard-buffer-name "*guard*") + +(defun ruby-guard-root (&optional last-directory) + "Return the directory name where guard file is located." + (locate-dominating-file (or last-directory + (file-truename default-directory)) + "Guardfile")) + +(defun ruby-guard-spring-p () + "Return non-nil if spring tmpdir found for `ruby-guard-root'." + (file-exists-p (file-truename + (concat temporary-file-directory + "spring/" + (md5 (ruby-guard-root) 0 -1) + ".pid")))) + +(defun ruby-guard-zeus-p () + "Return non-nil if `.zeus.sock' found in `ruby-guard-root'." + (file-exists-p (expand-file-name ".zeus.sock" (ruby-guard-root)))) + +(defun ruby-guard-chef-cookbook-p () + "Return non-nil if `ruby-guard-root' is in Chef cookbook." + (file-exists-p (expand-file-name "recipes" (ruby-guard-root)))) + +(defun ruby-guard-chefdk-installed-p () + "Return non-nil if Chef development kit directory is present." + (file-exists-p "/opt/chefdk")) + +(defun ruby-guard-bundle-p () + "Return non-nil if `Gemfile' found in `ruby-guard-root'." + (file-exists-p (expand-file-name "Gemfile" (ruby-guard-root)))) + +(defun ruby-guard-command-name () + "Return ruby-guard-command." + (cond ((ruby-guard-spring-p) + "spring guard") + ((ruby-guard-bundle-p) + "bundle exec guard") + ((and (ruby-guard-chef-cookbook-p) + (ruby-guard-chefdk-installed-p)) + "chef exec guard") + (t "guard"))) + +(defmacro ruby-guard-with-root (body-form) + "Run (BODY-FORM) with `ruby-guard-root' as `default-directory'." + `(let ((default-directory (ruby-guard-root))) + ,body-form)) + +;;;###autoload +(defun ruby-guard () + "Run Guard in separate buffer." + (interactive) + (let ((default-directory (ruby-guard-root))) + (if default-directory + (progn + (if (member ruby-guard-buffer-name + (mapcar 'buffer-name (buffer-list))) + (switch-to-buffer ruby-guard-buffer-name) + (ruby-guard-with-root + (async-shell-command + (ruby-guard-command-name) + (get-buffer-create ruby-guard-buffer-name))))) + (error "Cannot find Guardfile.")))) + +(provide 'ruby-guard) + +;;; ruby-guard.el ends here