forked from google/mtail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtail-mode.el
92 lines (76 loc) · 2.75 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
; Copyright 2011 Google Inc. All Rights Reserved.
; This file is available under the Apache license.
(defvar mtail-mode-hook nil)
(defcustom mtail-indent-offset 2
"Indent offset for `mtail-mode'.")
(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")
"All types in the mtail language. Used for font locking.")
(defconst mtail-mode-keywords
'("as" "by" "const" "hidden" "def" "next")
"All keywords in the mtail language. Used for font locking.")
(defconst mtail-mode-builtins
'("len" "strptime" "timestamp")
"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 "emtail"
"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)
(unload-feature 'mtail-mode)
(add-to-list 'load-path "/home/jaq/src/mtail")
(require 'mtail-mode)
(mtail-mode))
(provide 'mtail-mode)
(add-to-list 'auto-mode-alist (cons "\\.em$" #'mtail-mode))