public
Description: Rinari Is Not A Rails IDE
Homepage: http://rinari.rubyforge.org
Clone URL: git://github.com/technomancy/rinari.git
eschulte (author)
Tue Jun 24 15:37:47 -0700 2008
commit  9c51fe7699fdea4b57318ec47acc635abe5e8d88
tree    81c4c5e3a294dcfad5900b710d309d0860ae2cc1
parent  b12e8dbbeeeb9e213da4316e00c1b511f44980af
rinari / ruby-compilation.el
100644 73 lines (63 sloc) 2.749 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;;; ruby-compilation.el --- run a ruby process in a compilation buffer
 
;; Eric Schulte
 
;;; Code:
(require 'ansi-color)
 
(defvar ruby-compilation-error-regexp
  "^[[:space:]]*\\[?\\([^[:space:]]*\\):\\([[:digit:]]+\\)"
  "regular expression to match errors in ruby process output")
 
(defvar ruby-compilation-error-regexp-alist
  `((,ruby-compilation-error-regexp 1 2))
  "a version of `compilation-error-regexp-alist' to be used in
rails logs (should be used with `make-local-variable')")
 
(defun ruby-run-w/compilation (cmd)
  "Run a ruby process dumping output to a ruby compilation buffer."
  (interactive "FRuby Comand: ")
  (let ((default-directory (ruby-root))
  (name (file-name-nondirectory cmd))
  (cmdlist (ruby-args-to-list (expand-file-name cmd))))
    (unless (comint-check-proc (format "*%s*" name))
      (let* ((buffer (apply 'make-comint name "ruby" nil cmdlist))
   (proc (get-buffer-process buffer)))
  (set-buffer buffer)
  (set-process-sentinel proc 'ruby-compilation-sentinel)
  (set-process-filter proc 'ruby-compilation-insertion-filter)
  (set (make-variable-buffer-local 'compilation-error-regexp-alist)
   ruby-compilation-error-regexp-alist)
  (define-key compilation-minor-mode-map (kbd "C-c C-c") 'comint-interrupt-subjob)
  (set (make-variable-buffer-local 'kill-buffer-hook)
   (lambda ()
   (let ((orphan-proc (get-buffer-process (buffer-name))))
     (if orphan-proc
     (kill-process orphan-proc)))))
  (compilation-minor-mode)
  (ruby-minor-mode)))
    (pop-to-buffer (format "*%s*" name))))
 
(defun ruby-compilation-insertion-filter (proc string)
  "Insert text to buffer stripping ansi color codes"
  (with-current-buffer (process-buffer proc)
    (let ((moving (= (point) (process-mark proc))))
      (save-excursion
  (goto-char (process-mark proc))
  (insert (ansi-color-filter-apply string))
  (set-marker (process-mark proc) (point)))
      (if moving (goto-char (process-mark proc))))))
 
(defun ruby-compilation-sentinel (proc msg)
  "Notify to changes in process state"
  (message "%s - %s" proc (replace-regexp-in-string "\n" "" msg)))
 
(defun ruby-compilation-previous-error-group ()
  "Jump to the start of the previous error group in the current
compilation buffer."
  (interactive)
  (compilation-previous-error 1)
  (while (string-match ruby-compilation-error-regexp (thing-at-point 'line))
    (forward-line -1))
  (forward-line 1) (recenter))
 
(defun ruby-compilation-next-error-group ()
  "Jump to the start of the previous error group in the current
compilation buffer."
  (interactive)
  (while (string-match ruby-compilation-error-regexp (thing-at-point 'line))
    (forward-line 1))
  (compilation-next-error 1) (recenter))
 
(provide 'ruby-compilation)
;;; ruby-compilation.el ends here