Permalink
Browse files

add compile-rspec generously provided by hemant

  • Loading branch information...
1 parent d51c937 commit f4ecfe4bd031ba6ab28278cef811c3f1481b86a2 @iffyuva committed Dec 19, 2012
Showing with 56 additions and 1 deletion.
  1. +52 −0 emacs.d/compile-rspec.el
  2. +2 −0 emacs.d/dot-emacs.el
  3. +2 −0 emacs.d/mad-coding.el
  4. +0 −1 emacs.d/org-config.el
View
@@ -0,0 +1,52 @@
+;;; Hemant Kumar
+;; Given by Hemant, he is the culprit of something fails to work! :P
+
+(require 'cl) ; If you don't have it already
+
+(defun* get-closest-gemfile-root (&optional (file "Gemfile"))
+ "Determine the pathname of the first instance of FILE starting from the current directory towards root.
+This may not do the correct thing in presence of links. If it does not find FILE, then it shall return the name
+of FILE in the current directory, suitable for creation"
+ (let ((root (expand-file-name "/"))) ; the win32 builds should translate this correctly
+ (loop
+ for d = default-directory then (expand-file-name ".." d)
+ if (file-exists-p (expand-file-name file d))
+ return d
+ if (equal d root)
+ return nil)))
+
+(require 'compile)
+
+(defun rspec-compile-file ()
+ (interactive)
+ (compile (format "cd %s;bundle exec rspec %s"
+ (get-closest-gemfile-root)
+ (file-relative-name (buffer-file-name) (get-closest-gemfile-root))
+ )))
+
+(defun rspec-compile-on-line ()
+ (interactive)
+ (compile (format "cd %s;bundle exec rspec %s -l %s"
+ (get-closest-gemfile-root)
+ (file-relative-name (buffer-file-name) (get-closest-gemfile-root))
+ (line-number-at-pos)
+ )))
+
+(add-hook 'ruby-mode-hook
+ (lambda ()
+ (local-set-key (kbd "C-c l") 'rspec-compile-on-line)
+ (local-set-key (kbd "C-c k") 'rspec-compile-file)
+ ))
+
+;; http://stackoverflow.com/questions/3072648/cucumbers-ansi-colors-messing-up-emacs-compilation-buffer
+(require 'ansi-color)
+
+(defun colorize-compilation-buffer ()
+ (toggle-read-only)
+ (ansi-color-apply-on-region (point-min) (point-max))
+ (toggle-read-only))
+(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
+
+
+
+(provide 'compile-rspec)
View
@@ -62,6 +62,8 @@
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")
+;; ansi color for compilation mode
+(require 'ansi-color)
;; load elpa packages
(require 'new-elpa)
View
@@ -48,6 +48,8 @@
(add-to-list 'auto-mode-alist
'("\\(\\.\\(rb\\|rake\\|gemspec\\)\\|Rakefile\\|Gemfile\\)$" . ruby-mode))
+;; add rspec mode
+(require 'compile-rspec)
;; add haml and sass modes
(require 'haml-mode)
View
@@ -16,7 +16,6 @@
(setq load-path
(cons (concat top-dir "/vendor/org-mode/lisp") load-path))
(require 'org)
-(require 'org-install)
(add-to-list 'auto-mode-alist
'("\\.\\(org\\|org-archive\\)$" . org-mode))

0 comments on commit f4ecfe4

Please sign in to comment.