aboutsummaryrefslogtreecommitdiffstats
path: root/elisp
diff options
context:
space:
mode:
authorÓscar Nájera <hi@oscarnajera.com>2022-09-28 14:51:13 +0200
committerÓscar Nájera <hi@oscarnajera.com>2022-09-28 14:51:13 +0200
commita2701faaf8059c194ef8aa9661536cf9c8fc7661 (patch)
tree04cc807388d72397c8184315705a1bbcfc6661a0 /elisp
parent1b42e43e708ff6539da7b3a0ed11d4b7c54975f4 (diff)
downloaddotfiles-a2701faaf8059c194ef8aa9661536cf9c8fc7661.tar.gz
dotfiles-a2701faaf8059c194ef8aa9661536cf9c8fc7661.tar.bz2
dotfiles-a2701faaf8059c194ef8aa9661536cf9c8fc7661.zip
Font lock livestatus query
Diffstat (limited to 'elisp')
-rw-r--r--elisp/cmk.el42
1 files changed, 27 insertions, 15 deletions
diff --git a/elisp/cmk.el b/elisp/cmk.el
index a139258..6e2b7e0 100644
--- a/elisp/cmk.el
+++ b/elisp/cmk.el
@@ -135,20 +135,32 @@ Default is \"%Y-%m-%d %H:%M\"."
(setq tabulated-list-entries (cmk-parse-rows (process-buffer cmks) cmk-problem-col-spec))
(tabulated-list-print 'remember)))
-(defun cmk-edit-lq (query buffer)
- (interactive (list cmk-livestatus-query (current-buffer)))
- (with-current-buffer (get-buffer-create "*LQ*")
- (prog-mode)
- (insert query)
- (local-set-key "\C-c\C-c"
- (lambda ()
- (interactive)
- (let ((new-query (-> (buffer-string) (string-trim) (concat "\n\n"))))
- (kill-buffer)
- (switch-to-buffer buffer)
- (setq-local cmk-livestatus-query new-query)
- (cmk-table--refresh))))
- (switch-to-buffer (current-buffer))))
+(define-derived-mode cmk-livestatus-mode prog-mode "livestatus"
+ "Major mode for viewing journalctl output."
+ ;; 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)
+ (,(rx bol (or "And" "Or" "Negate") ":" whitespace) . font-lock-keyword-face)
+ (,(rx whitespace (or "~" "=" "=~" "~~" "<" ">" "<=" ">=") whitespace) . font-lock-keyword-face)))))
+
+(defun cmk-edit-lq (buffer)
+ "Open window to edit the livestatus query of current BUFFER."
+ (interactive (list (current-buffer)))
+ (let ((query cmk-livestatus-query)
+ (edit-buffer (get-buffer-create "*LQ*")))
+ (with-current-buffer edit-buffer
+ (cmk-livestatus-mode)
+ (insert query)
+ (local-set-key "\C-c\C-c"
+ (lambda ()
+ (interactive)
+ (let ((new-query (-> (buffer-string) (string-trim) (concat "\n\n"))))
+ (kill-buffer)
+ (switch-to-buffer buffer)
+ (setq-local cmk-livestatus-query new-query)
+ (cmk-table--refresh)))))
+ (switch-to-buffer edit-buffer)))
(defun cmk-problems ()
(interactive)
@@ -157,7 +169,7 @@ Default is \"%Y-%m-%d %H:%M\"."
(setq-local cmk-livestatus-query
(concat (string-join `("GET services"
,(cmk-colums-from-spec cmk-problem-col-spec)
- "Filter: service_description ~ load") "\n")
+ ,cmk-lq-problems-filter) "\n")
"\n\n"))
(setq tabulated-list-format (vconcat cmk-problem-col-spec))
(setq tabulated-list-sort-key '("STATE" . nil))