blob: 1154b02d0a92626cfecf6065c24205a48696d072 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
;;; lava-log-mode --- A major mode for viewing LAVA log files
;;
;; Copyright (C) 2014 Alex Bennée
;; Author: Alex Bennée <alex.bennee@linaro.org>
;; Maintainer: Alex Bennée <alex.bennee@linaro.org>
;; Version: 0.1
;; Homepage: git.linaro.org/people/alex.bennee/lava-mode.git
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;;; Commentary:
;;
;; This provides a Major mode for viewing LAVA log files.
;;
;;; Code:
;; Require prerequisites
(require 'log4j-mode)
;; Variables
;; Syntax higlighting
(defvar lava-log-font-lock-keywords
(list
'("<LAVA_.*>" . font-lock-comment-face))
"Minimal highlighting expressions for LAVA Log Mode.")
(defvar lava-log-hacking-session
" \\(\\w*@[[:digit:].]\\{7,15\\}+\\)"
"Regex used to find hacking sessions, the capture group includes IP address.")
;;; Mode magic
(defvar lava-log-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") 'lava-log-mode-done)
map)
"Keymap for major mode `lava-log-mode'.")
(defun lava-log-find-hacking-session ()
"Search the log file for a hacking session and copy to kill-ring if
found"
(interactive)
(save-excursion
(goto-char (point-min))
(when (re-search-forward lava-log-hacking-session nil t)
(let ((login (match-string 1)))
(kill-new login)
(message "Found hacking session prompt: %s" login)))))
;; Define the mode
;;###autoload
(define-derived-mode lava-log-mode view-mode "LAVA Log"
"A major mode for viewing LAVA log files .
\{lava-log-mode-map}"
:lighter " LVL"
(set (make-local-variable 'font-lock-defaults)
'(lava-log-font-lock-keywords))
(lava-log-find-hacking-session))
;; Done, close buffer
(defun lava-log-mode-done ()
"When in a LAVA log mode buffer, close it"
(interactive)
(when (derived-mode-p 'lava-log-mode)
(kill-buffer)))
(provide 'lava-log-mode)
;;; lava-log-mode.el ends here
|