author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 20 Dec 2012 23:42:25 +0200 | |
changeset 1013 | e88896e74332 |
parent 572 | ead98b9f85c3 |
child 1246 | abd80227aa4b |
permissions | -rw-r--r-- |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
;;; my-log-mode.el --- major mode for error logs |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
;; Copyright (C) 2010 by Oleksandr Gavenko <gavenkoa@gmail.com> |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
;; You can do anything with this file without any warranty. |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
;; Author: Oleksandr Gavenko <gavenkoa@gmail.com> |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com> |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
;; Created: 2011-02-09 |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
;; Version: 0.1 |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
;; Keywords: logging |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
;;; Commentary: |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
;; |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
;; Very pure release. |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
;;; Code: |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
(defun my-log-goto (point) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
"" |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
(interactive "d") |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
(let ( start stop line fname fline (fregex "^\\([^:]+\\):\\([[:digit:]]+\\):") ) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
(save-excursion |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
(move-beginning-of-line 1) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |
(setq start (point)) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
26 |
(move-end-of-line 1) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
(setq stop (point)) |
569
7d7bb0a92f2a
Remove text properties.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
568
diff
changeset
|
28 |
(setq line (filter-buffer-substring start stop nil t)) |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
29 |
(string-match fregex line) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
30 |
(setq fname (match-string 1 line)) |
566
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
31 |
(when fname |
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
32 |
(setq fline (string-to-int (match-string 2 line))) |
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
33 |
) |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
34 |
) |
572
ead98b9f85c3
Fix trailing spaces.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
571
diff
changeset
|
35 |
(cond |
570
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
36 |
( (and fname (file-exists-p fname)) |
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
37 |
(find-file-other-window fname) |
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
38 |
(goto-line fline) |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
39 |
) |
570
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
40 |
( t |
571
012f4c694435
Fix error reporting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
570
diff
changeset
|
41 |
(if fname |
012f4c694435
Fix error reporting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
570
diff
changeset
|
42 |
(message "File '%s' is not found (default directory is '%s')." fname default-directory) |
012f4c694435
Fix error reporting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
570
diff
changeset
|
43 |
(message "No file under current line.") |
012f4c694435
Fix error reporting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
570
diff
changeset
|
44 |
) |
570
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
45 |
) |
53f62308c963
Report error if file not found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
569
diff
changeset
|
46 |
) |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
47 |
)) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
48 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
49 |
(setq my-log-mode-map (make-sparse-keymap)) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
50 |
(define-key my-log-mode-map (kbd "RET") 'my-log-goto) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
51 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
52 |
(require 'generic-x) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
53 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
54 |
;;;###autoload |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
55 |
(define-generic-mode |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
56 |
'my-log-mode |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
57 |
nil |
566
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
58 |
nil |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
59 |
'( |
566
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
60 |
("^\\([^:]+\\):\\([[:digit:]]+\\):[^ |
567 | 61 |
]+$" (1 font-lock-function-name-face) (2 font-lock-type-face)) |
566
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
62 |
("^\\([^:]\\{1,10\\}\\):[^ |
567 | 63 |
]+$" (1 font-lock-keyword-face)) |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
64 |
) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
65 |
;; '("\\.log$") |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
nil |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
(list |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
68 |
(lambda nil |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
69 |
(use-local-map my-log-mode-map) |
566
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
70 |
(modify-syntax-entry ?' ".") |
5efbc78b8c41
Fix error when fline is nil. Optimize regex for highlighting. Set quotes as
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
565
diff
changeset
|
71 |
(modify-syntax-entry ?\" ".") |
565
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
72 |
)) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
73 |
) |
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
74 |
|
a9f4afeefe2a
Major mode for error logs.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
75 |
;;; my-log-mode.el ends here |