my-log-mode.el
changeset 565 a9f4afeefe2a
child 566 5efbc78b8c41
equal deleted inserted replaced
564:0eae7b87c27a 565:a9f4afeefe2a
       
     1 ;;; my-log-mode.el --- major mode for error logs
       
     2 
       
     3 ;; Copyright (C) 2010 by Oleksandr Gavenko <gavenkoa@gmail.com>
       
     4 
       
     5 ;; You can do anything with this file without any warranty.
       
     6 
       
     7 ;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
       
     8 ;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
       
     9 ;; Created: 2011-02-09
       
    10 ;; Version: 0.1
       
    11 ;; Keywords: logging
       
    12 
       
    13 ;;; Commentary:
       
    14 ;;
       
    15 ;; Very pure release.
       
    16 
       
    17 ;;; Code:
       
    18 
       
    19 (defun my-log-goto (point)
       
    20   ""
       
    21   (interactive "d")
       
    22   (let ( start stop line fname fline (fregex "^\\([^:]+\\):\\([[:digit:]]+\\):") )
       
    23     (save-excursion
       
    24       (move-beginning-of-line 1)
       
    25       (setq start (point))
       
    26       (move-end-of-line 1)
       
    27       (setq stop (point))
       
    28       (setq line (filter-buffer-substring start stop))
       
    29       (string-match fregex line)
       
    30       (setq fname (match-string 1 line))
       
    31       (setq fline (string-to-int (match-string 2 line)))
       
    32       )
       
    33     (when (file-exists-p fname)
       
    34       (find-file-other-window fname)
       
    35       (goto-line fline)
       
    36       )
       
    37     ))
       
    38 
       
    39 (setq my-log-mode-map (make-sparse-keymap))
       
    40 (define-key my-log-mode-map (kbd "RET") 'my-log-goto)
       
    41 
       
    42 (require 'generic-x)
       
    43 
       
    44 ;;;###autoload
       
    45 (define-generic-mode
       
    46   'my-log-mode
       
    47   nil
       
    48   '("INT" "WM")
       
    49   '(
       
    50     ("^\\([^:]+\\):\\([[:digit:]]+\\):" (1 font-lock-constant-face) (2 font-lock-constant-face))
       
    51     )
       
    52   ;; '("\\.log$")
       
    53   nil
       
    54   (list
       
    55    (lambda nil
       
    56      ;; (setq buffer-read-only t)
       
    57      (use-local-map my-log-mode-map)
       
    58      ))
       
    59   )
       
    60 
       
    61 ;;; my-log-mode.el ends here