aboutsummaryrefslogtreecommitdiffstats
path: root/elisp
diff options
context:
space:
mode:
Diffstat (limited to 'elisp')
-rw-r--r--elisp/cmk.el53
1 files changed, 52 insertions, 1 deletions
diff --git a/elisp/cmk.el b/elisp/cmk.el
index df424ad..6023cf0 100644
--- a/elisp/cmk.el
+++ b/elisp/cmk.el
@@ -21,6 +21,8 @@
(require 'subr-x)
(require 'cl-lib)
(require 'dash)
+(require 'company)
+(require 'csv-mode)
(defun cmk-state-coloring (state)
"Font color for numeric STATE input as string."
@@ -128,14 +130,63 @@ Default is \"%Y-%m-%d %H:%M\"."
(setq tabulated-list-entries (cmk-parse-rows (process-buffer cmks) tabulated-list-format))
(tabulated-list-print 'remember)))
+(defun cmk-timestamp-eldoc-documentation ()
+ (when-let ((number (thing-at-point 'number)))
+ (format-time-string "%Y-%m-%d %H:%M" (seconds-to-time number))))
+
+(defconst cmk-livestatus-headers
+ '("Filter" "Columns" "Stats" "Limit" "ColumnHeaders" "OutputFormat"))
+
(define-derived-mode cmk-livestatus-mode prog-mode "livestatus"
"Major mode for viewing journalctl output."
+ (add-function :before-until (local 'eldoc-documentation-function)
+ #'cmk-timestamp-eldoc-documentation)
+ ;; (setq-local company-backends (cons 'company-cmk-lq company-backends))
+ ;; (setq-local completion-at-point-functions '(cmk-lq-capf))
+ (add-hook 'completion-at-point-functions 'cmk-lq-capf nil 'local)
;; code for syntax highlighting
(setq font-lock-defaults `(((,(rx bol "GET" eow) . font-lock-keyword-face)
(,(rx word-start (or "hosts" "services") word-end) . font-lock-constant-face)
- (,(rx bol (or "Filter" "Columns" "Stats" "Limit") ":" whitespace) . font-lock-function-name-face)
+ (,(concat "^" (regexp-opt cmk-livestatus-headers 'words) ":[[:space:]]") . font-lock-function-name-face)
(,(rx bol (or "And" "Or" "Negate") ":" whitespace) . font-lock-keyword-face)
(,(rx whitespace (or "~" "=" "=~" "~~" "<" ">" "<=" ">=") whitespace) . font-lock-keyword-face)))))
+(defun cmk-custom-livestatus-query ()
+ (interactive)
+ (let ((query cmk-livestatus-query)
+ (edit-buffer (get-buffer-create "*LQ*")))
+ (with-current-buffer edit-buffer
+ (cmk-livestatus-mode)
+ (if (string-blank-p query) (insert "GET ") (insert query))
+ (local-set-key "\C-c\C-c"
+ (lambda ()
+ (interactive)
+ (let ((new-query (-> (buffer-string) (string-trim) (concat "\n\n"))))
+ (kill-buffer)
+ (let ((cmk (cmk-livestatus-query new-query)))
+ (switch-to-buffer (process-buffer cmk))
+ (setq csv-separators '(";")
+ csv-separator-regexp "[;]"
+ csv-separator-chars '(59))
+ (csv-align-mode)
+ (setq-local cmk-livestatus-query new-query))))))
+ (switch-to-buffer edit-buffer)))
+
+(defun company-cmk-lq (command &optional arg &rest ignored)
+ (interactive (list 'interactive))
+ (cl-case command
+ (interactive (company-begin-backend 'company-cmk-lq))
+ (prefix (company-grab-word))
+ (candidates (cl-loop for header in cmk-livestatus-headers
+ when (string-prefix-p arg header t) collect header))
+ (meta (format "This value is named %s" arg))))
+
+(defun cmk-lq-capf ()
+ (when (looking-back (rx bol (+ alpha)) 1)
+ (list (match-beginning 0)
+ (match-end 0)
+ (cl-loop for header in cmk-livestatus-headers
+ when (string-prefix-p (match-string-no-properties 0) header t)
+ collect (concat header ": ")))))
(defun cmk-edit-lq (buffer)
"Open window to edit the livestatus query of current BUFFER."