-
Notifications
You must be signed in to change notification settings - Fork 0
/
influx.el
81 lines (61 loc) · 2.61 KB
/
influx.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
;;; influx.el --- Run inferior influx process -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Manoj Kumar Manikchand
;; Author: Manoj Kumar Manikchand <[email protected]>
;; Keywords: tools
;;; Commentary:
;;
;;; Code:
;;;; Dependencies
(require 'comint)
;;;; Customizations
(defvar influx-cli-file-path "influx"
"Path to influx-cli binary.")
(defvar influx-cli-arguments '("-host" "localhost" "-precision" "rfc3339")
"Commandline arguments to pass to influx-cli.")
;;;;; Keymap
;;;###autoload
(defvar influx-mode-map
(let ((map (nconc (make-sparse-keymap) comint-mode-map)))
(define-key map "\t" 'completion-at-point)
map)
"Basic mode map for `run-influx'.")
;;;;; Keywords
(defconst influx-keywords-upcase
'("ALL" "ALTER" "ANY" "AS" "ASC" "BEGIN"
"BY" "CREATE" "CONTINUOUS" "DATABASE" "DATABASES" "DEFAULT"
"DELETE" "DESC" "DESTINATIONS" "DIAGNOSTICS" "DISTINCT" "DROP"
"DURATION" "END" "EVERY" "EXPLAIN" "FIELD" "FOR"
"FROM" "GRANT" "GRANTS" "GROUP" "GROUPS" "IN"
"INF" "INSERT" "INTO" "KEY" "KEYS" "KILL"
"LIMIT" "SHOW" "MEASUREMENT" "MEASUREMENTS" "NAME" "OFFSET"
"ON" "ORDER" "PASSWORD" "POLICY" "POLICIES" "PRIVILEGES"
"QUERIES" "QUERY" "READ" "REPLICATION" "RESAMPLE" "RETENTION"
"REVOKE" "SELECT" "SERIES" "SET" "SHARD" "SHARDS"
"SLIMIT" "SOFFSET" "STATS" "SUBSCRIPTION" "SUBSCRIPTIONS" "TAG"
"TO" "USER" "USERS" "VALUES" "WHERE" "WITH"
"WRITE"))
(defconst influx-keywords-downcase (mapcar #'downcase influx-keywords-upcase))
(defvar influx-font-lock-keywords
(list
;; highlight all the reserved commands.
`(,(concat "\\_<"
(regexp-opt (nconc influx-keywords-upcase influx-keywords-downcase))
"\\_>") . font-lock-keyword-face))
"Keywords to highlight in `influx-mode'.")
;;;;; Commands
;;;###autoload
(defun run-influx ()
"Run an inferior instance of influx-cli inside Emacs."
(interactive)
(apply #'make-comint-in-buffer "Influx" nil influx-cli-file-path
nil influx-cli-arguments)
(pop-to-buffer "*Influx*")
(influx-mode))
;;;###autoload
(define-derived-mode influx-mode comint-mode "Influx"
"Major mode for `run-influx'.
\\<influx-mode-map>"
(setq comint-prompt-read-only t)
(set (make-local-variable 'font-lock-defaults) '(influx-font-lock-keywords t)))
(provide 'influx)
;;; influx.el ends here