| 1 |
;;; rails-log.el --- provide features for Rails log files
|
| 2 |
|
| 3 |
;; Copyright (C) 2006 Dmitry Galinsky <dima dot exe at gmail dot com>
|
| 4 |
|
| 5 |
;; Authors: Dmitry Galinsky <dima dot exe at gmail dot com>
|
| 6 |
|
| 7 |
;; Keywords: ruby rails languages oop
|
| 8 |
;; $URL$
|
| 9 |
;; $Id$
|
| 10 |
|
| 11 |
;;; License
|
| 12 |
|
| 13 |
;; This program is free software; you can redistribute it and/or
|
| 14 |
;; modify it under the terms of the GNU General Public License
|
| 15 |
;; as published by the Free Software Foundation; either version 2
|
| 16 |
;; of the License, or (at your option) any later version.
|
| 17 |
|
| 18 |
;; This program is distributed in the hope that it will be useful,
|
| 19 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 20 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 21 |
;; GNU General Public License for more details.
|
| 22 |
|
| 23 |
;; You should have received a copy of the GNU General Public License
|
| 24 |
;; along with this program; if not, write to the Free Software
|
| 25 |
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 26 |
|
| 27 |
;;; Code:
|
| 28 |
|
| 29 |
(defvar rails-log:last-log nil)
|
| 30 |
|
| 31 |
(defun rails-log:files ()
|
| 32 |
(directory-files (rails-core:file "log") nil "\\.log$"))
|
| 33 |
|
| 34 |
(defun rails-log:buffer-name (log-file)
|
| 35 |
(concat "*" log-file "*"))
|
| 36 |
|
| 37 |
(defun rails-log:open-file (log-file)
|
| 38 |
(let ((buffer (rails-log:buffer-name log-file))
|
| 39 |
(current (buffer-name)))
|
| 40 |
(unless (get-buffer buffer)
|
| 41 |
(get-buffer-create buffer)
|
| 42 |
(set-buffer buffer)
|
| 43 |
(setq auto-window-vscroll t)
|
| 44 |
(rails-minor-mode t)
|
| 45 |
(setq buffer-read-only t)
|
| 46 |
(set-buffer current)
|
| 47 |
(apply-colorize-to-buffer buffer))
|
| 48 |
(start-process "tail"
|
| 49 |
buffer
|
| 50 |
"tail"
|
| 51 |
"-n" (message "%d" rails-number-of-lines-shown-when-opening-log-file)
|
| 52 |
"-f" (rails-core:file (concat "log/" log-file)))))
|
| 53 |
|
| 54 |
(defun rails-log:open (log-file)
|
| 55 |
(interactive
|
| 56 |
(list (completing-read "Select log (with autocomplete): "
|
| 57 |
(list->alist (rails-log:files))
|
| 58 |
nil
|
| 59 |
t
|
| 60 |
rails-log:last-log)))
|
| 61 |
(setq rails-log:last-log log-file)
|
| 62 |
(let ((name (rails-log:buffer-name log-file)))
|
| 63 |
(unless (get-buffer name)
|
| 64 |
(rails-log:open-file log-file))
|
| 65 |
(switch-to-buffer name)
|
| 66 |
(recenter t)))
|
| 67 |
|
| 68 |
(defun rails-log:open-production ()
|
| 69 |
(interactive)
|
| 70 |
(rails-log:open "production.log"))
|
| 71 |
|
| 72 |
(defun rails-log:open-development ()
|
| 73 |
(interactive)
|
| 74 |
(rails-log:open "development.log"))
|
| 75 |
|
| 76 |
(defun rails-log:open-test ()
|
| 77 |
(interactive)
|
| 78 |
(rails-log:open "test.log"))
|
| 79 |
|
| 80 |
(provide 'rails-log) |