my-log-mode.el
changeset 1666 06937ff1ec5f
parent 1665 3685e2321a9b
child 1667 7f70095fbf32
equal deleted inserted replaced
1665:3685e2321a9b 1666:06937ff1ec5f
     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   "Visit file according to error specification at POINT."
       
    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       (when fname
       
    32         (setq fline (string-to-number (match-string 2 line))))
       
    33       )
       
    34     (cond
       
    35      ( (and fname (file-exists-p fname))
       
    36        (find-file-other-window fname)
       
    37        (goto-char (point-min))
       
    38        (forward-line (1- fline)) )
       
    39      ( t
       
    40        (if fname
       
    41            (message "File '%s' is not found (default directory is '%s')." fname default-directory)
       
    42          (message "No file under current line.") ) )
       
    43      )
       
    44     ))
       
    45 
       
    46 (defvar my-log-mode-map (make-sparse-keymap))
       
    47 (define-key my-log-mode-map (kbd "RET") 'my-log-goto)
       
    48 
       
    49 (require 'generic-x)
       
    50 
       
    51 ;;;###autoload
       
    52 (define-generic-mode
       
    53   'my-log-mode
       
    54   nil
       
    55   nil
       
    56   '(
       
    57     ("^\\([^:]+\\):\\([[:digit:]]+\\):[^
       
    58 ]+$" (1 font-lock-function-name-face) (2 font-lock-type-face))
       
    59     ("^\\([^:]\\{1,10\\}\\):[^
       
    60 ]+$" (1 font-lock-keyword-face))
       
    61     )
       
    62   ;; '("\\.log$")
       
    63   nil
       
    64   (list
       
    65    (lambda nil
       
    66      (use-local-map my-log-mode-map)
       
    67      (modify-syntax-entry ?' ".")
       
    68      (modify-syntax-entry ?\" ".")
       
    69      ))
       
    70   )
       
    71 
       
    72 ;;; my-log-mode.el ends here