my-log-mode.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 11 Oct 2017 00:28:06 +0300
changeset 1541 dca10cecc9e2
parent 1260 47bc80daa918
permissions -rw-r--r--
Set font size depending on DPI.

;;; my-log-mode.el --- major mode for error logs

;; Copyright (C) 2010 by Oleksandr Gavenko <gavenkoa@gmail.com>

;; You can do anything with this file without any warranty.

;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
;; Created: 2011-02-09
;; Version: 0.1
;; Keywords: logging

;;; Commentary:
;;
;; Very pure release.

;;; Code:

(defun my-log-goto (point)
  "Visit file according to error specification at POINT."
  (interactive "d")
  (let ( start stop line fname fline (fregex "^\\([^:]+\\):\\([[:digit:]]+\\):") )
    (save-excursion
      (move-beginning-of-line 1)
      (setq start (point))
      (move-end-of-line 1)
      (setq stop (point))
      (setq line (filter-buffer-substring start stop))
      (string-match fregex line)
      (setq fname (match-string 1 line))
      (when fname
        (setq fline (string-to-number (match-string 2 line))))
      )
    (cond
     ( (and fname (file-exists-p fname))
       (find-file-other-window fname)
       (goto-char (point-min))
       (forward-line (1- fline)) )
     ( t
       (if fname
           (message "File '%s' is not found (default directory is '%s')." fname default-directory)
         (message "No file under current line.") ) )
     )
    ))

(defvar my-log-mode-map (make-sparse-keymap))
(define-key my-log-mode-map (kbd "RET") 'my-log-goto)

(require 'generic-x)

;;;###autoload
(define-generic-mode
  'my-log-mode
  nil
  nil
  '(
    ("^\\([^:]+\\):\\([[:digit:]]+\\):[^
]+$" (1 font-lock-function-name-face) (2 font-lock-type-face))
    ("^\\([^:]\\{1,10\\}\\):[^
]+$" (1 font-lock-keyword-face))
    )
  ;; '("\\.log$")
  nil
  (list
   (lambda nil
     (use-local-map my-log-mode-map)
     (modify-syntax-entry ?' ".")
     (modify-syntax-entry ?\" ".")
     ))
  )

;;; my-log-mode.el ends here