Skip to content

Instantly share code, notes, and snippets.

@eiel
Created May 22, 2012 10:24
Show Gist options
  • Save eiel/2768176 to your computer and use it in GitHub Desktop.
Save eiel/2768176 to your computer and use it in GitHub Desktop.
(add-to-list 'auto-mode-alist '("Rakefile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Gemfile" . ruby-mode))
(add-to-list 'auto-mode-alist '("Ocmgen" . ruby-mode))
(defun ruby-mode-hook-init ()
"encodingを自動挿入しないようにする"
(remove-hook 'before-save-hook 'ruby-mode-set-encoding)
(define-key ruby-mode-map " " nil)
(define-key ruby-mode-map "\C-ce" 'my-ruby-mode-set-encoding)
(define-key ruby-mode-map "\C-j" nil))
(add-hook 'ruby-mode-hook 'ruby-mode-hook-init)
(defun my-ruby-mode-set-encoding ()
"set-encoding ruby-mode"
(interactive)
(ruby-mode-set-encoding))
(defun my-ruby-insert-encoding ()
"set-encoding utf-8"
(interactive)
(save-excursion
(beginning-of-buffer)
(insert "# -*- coding: utf-8 -*-\n")))
;;; ruby-electric
(defun ruby-mode-hook-ruby-elecrtric ()
(ruby-electric-mode t)
(define-key ruby-mode-map "\C-c\C-e" 'ruby-insert-end))
;; (add-hook 'ruby-mode-hook 'ruby-mode-hook-ruby-elecrtric)
;;; rubydb
;; (install-elisp "http://svn.ruby-lang.org/repos/ruby/trunk/misc/rubydb3x.el")
(autoload 'rubydb "rubydb3x" "ruby debug t")
;;; auto-installによってインストールした elisp の設定
;; (install-elisp-from-emacswiki "ruby-block.el")
(require 'ruby-block)
(setq ruby-block-highlight-toggle t)
(defun ruby-mode-hook-ruby-block()
(ruby-block-mode t))
(add-hook 'ruby-mode-hook 'ruby-mode-hook-ruby-block)
;;; rhtml-mode
(require 'rinari)
(setq rinari-tags-file-name "TAGS")
(require 'ruby-compilation-rspec)
(require 'rhtml-mode)
(require 'rspec-mode)
(setq rspec-use-rake-flag nil)
(setq rspec-use-bundler-when-possible nil)
(require 'ruby-compilation)
(defun rspec:target-file ()
"現在のファイルに対するターゲットファイルを探す。テストコードを開いていれば実装ファイル名を返す。実装ファイルをひらいていればテストーファイル名を返す。"
(if (rspec-buffer-is-spec-p)
(rspec-target-file-for (buffer-file-name))
(rspec-spec-file-for (buffer-file-name))))
(defun rspec:find-target-other-window ()
"編集しているファイルを別のwindowにテストコードまたはテスト対象ファイルを開く"
(interactive)
(find-file-other-window (rspec:target-file)))
(defun git-project:root-dir ()
(file-name-directory (file-truename
(shell-command-to-string "git rev-parse --git-dir"))))
(defun project-root (&optional dir)
(git-project:root-dir))
(require 'ruby-compilation)
(defun rspec:verify (&optional rspec-options)
(interactive)
(when (stringp rspec-options)
(setq rspec-options (list rspec-options)))
(let ((ruby-compilation-executable "rspec")
(file-name (rspec-spec-file-for (buffer-file-name)))
(options (append rspec-options (list "-I" (project-root)))))
(ruby-compilation-run file-name rspec-options file-name)))
(defun rspec:verify-single ()
(interactive)
(rspec:verify (list "--line_number" (number-to-string (line-number-at-pos)))))
(defun ruby-mode-hook-rspec ()
(define-key ruby-mode-map (kbd "C-c c r") 'rspec:verify)
(define-key ruby-mode-map (kbd "C-c c s") 'rspec:verify-single)
(define-key ruby-mode-map (kbd "C-c t") 'rspec:find-target-other-window)
(define-key ruby-mode-map (kbd "C-c c t") 'rspec-toggle-spec-and-target))
(add-hook 'ruby-mode-hook 'ruby-mode-hook-rspec)
(defun rhtml-mode-hook-rspec ()
(define-key rhtml-mode-map (kbd "C-c c r") 'rspec:verify)
(define-key rhtml-mode-map (kbd "C-c t") 'rspec:find-target-other-window)
(define-key rhtml-mode-map (kbd "C-c c t") 'rspec-toggle-spec-and-target))
(add-hook 'rhtml-mode-hook 'rhtml-mode-hook-rspec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment