-
Notifications
You must be signed in to change notification settings - Fork 378
/
mtail-mode.el
118 lines (98 loc) · 3.41 KB
/
mtail-mode.el
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
;;; mtail-mode.el -- Major mode for editing mtail programs.
;;;
;;; Copyright 2011 Google Inc. All Rights Reserved.
;;; This file is available under the Apache license.
;;;
;;; Commentary:
;;;
;;; Code:
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.mtail$" . mtail-mode))
(defgroup mtail nil
"Support for the mtail language."
:group 'languages
:prefix "mtail-")
(defcustom mtail-mode-hook nil
"Hook run when entering mtail mode."
:type 'hook
:group 'mtail)
(defcustom mtail-indent-offset 2
"Indent offset for `mtail-mode'."
:type 'integer
:group 'mtail)
;; font locking
(defvar mtail-mode-syntax-table
(let ((st (make-syntax-table)))
; Add _ to :word: class
(modify-syntax-entry ?_ "." st)
; Comments
(modify-syntax-entry ?\# "< b" st)
(modify-syntax-entry ?\n "> b" st)
; Regex
(modify-syntax-entry ?/ "|" st)
; String
(modify-syntax-entry ?\" "\"" st)
; Square brackets like parens
(modify-syntax-entry ?\[ "(]" st)
(modify-syntax-entry ?\] ")[" st)
; Operators
(modify-syntax-entry ?+ "." st)
(modify-syntax-entry ?- "." st)
(modify-syntax-entry ?< "." st)
(modify-syntax-entry ?> "." st)
(modify-syntax-entry ?= "." st)
(modify-syntax-entry ?! "." st)
st)
"Syntax table used while in `mtail-mode'.")
(defconst mtail-mode-types
'("counter" "gauge" "text" "timer")
"All types in the mtail language. Used for font locking.")
(defconst mtail-mode-keywords
'("after" "as" "by" "const" "def" "del" "else" "hidden" "next" "otherwise" "stop")
"All keywords in the mtail language. Used for font locking.")
(defconst mtail-mode-builtins
'("bool" "float" "getfilename" "int" "len" "settime" "string" "strptime" "strtol" "timestamp" "tolower")
"All builtins in the mtail language. Used for font locking.")
(defvar mtail-mode-font-lock-defaults
(eval-when-compile
(list
(cons (concat "\\<"
(regexp-opt mtail-mode-types 'words)
"\\>")
'font-lock-type-face)
(cons (concat "\\<"
(regexp-opt mtail-mode-builtins 'words)
"\\>")
'font-lock-builtin-face)
(cons (concat "\\<"
(regexp-opt mtail-mode-keywords 'words)
"\\>")
'font-lock-keyword-face)
(cons "\\<@[a-zA-Z0-9_]+\\>" 'font-lock-function-name-face)
(cons "\\<\\$?[a-zA-Z0-9_]+\\>" 'font-lock-variable-name-face)
)))
;;;###autoload
(define-derived-mode mtail-mode awk-mode "mtail"
"Major mode for editing mtail programs."
:syntax-table mtail-mode-syntax-table
(set (make-local-variable 'paragraph-separate) "^[ \t]*$")
(set (make-local-variable 'paragraph-start) "^[ \t]*$")
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-start-skip) "#+\\s-*")
;; Font lock
(set (make-local-variable 'font-lock-defaults)
'(mtail-mode-font-lock-defaults))
(setq indent-tabs-mode nil))
(defun mtail-mode-reload ()
"Reload mtail-mode.el and put the current buffer into emtail-mode. Useful for debugging."
(interactive)
;; Store the file that contains mtail-mode, this file.
(let ((mtail-mode-filename (symbol-file 'mtail-mode)))
(progn
(unload-feature 'mtail-mode)
(load-file mtail-mode-filename)
(require 'mtail-mode)
;; Whatever buffer we're in, reset its mode.
(set-auto-mode t))))
(provide 'mtail-mode)
;;; mtail-mode.el ends here