rails-log.el
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: svn://rubyforge.org/var/svn/emacs-rails/trunk/rails-log.el $ 9 ;; $Id: rails-log.el 114 2007-03-25 18:15:35Z dimaexe $ 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 "-f" (rails-core:file (concat "log/" log-file))))) 52 53 (defun rails-log:open (log-file) 54 (interactive 55 (list (completing-read "Select log (with autocomplete): " 56 (list->alist (rails-log:files)) 57 nil 58 t 59 rails-log:last-log))) 60 (setq rails-log:last-log log-file) 61 (let ((name (rails-log:buffer-name log-file))) 62 (unless (get-buffer name) 63 (rails-log:open-file log-file)) 64 (switch-to-buffer name) 65 (recenter t))) 66 67 (defun rails-log:open-production () 68 (interactive) 69 (rails-log:open "production.log")) 70 71 (defun rails-log:open-development () 72 (interactive) 73 (rails-log:open "development.log")) 74 75 (defun rails-log:open-test () 76 (interactive) 77 (rails-log:open "test.log")) 78 79 (provide 'rails-log)