commit db5e819acca9015765761a6c16ce461ea07fd782 Author: Jeremy Dormitzer Date: Tue Jun 2 17:46:43 2020 -0400 Initial commit: Hard-coded table diff --git a/structlog-mode.el b/structlog-mode.el new file mode 100644 index 0000000..193becd --- /dev/null +++ b/structlog-mode.el @@ -0,0 +1,42 @@ +(require 'cl-lib) + +(defvar structlog-fields nil + "Currently selected structlog fields") +(defvar structlog-logs nil + "Current structlog log lines, formatted as plists") + +(defun structlog--make-list-entries () + "Makes the tabulated-list-mode entries list for structlog" + (cl-map 'list + (lambda (log-plist) + (list log-plist + (cl-map 'vector + (lambda (field) + (plist-get log-plist field)) + structlog-fields))) + structlog-logs)) + +(define-derived-mode structlog-mode tabulated-list-mode "structlog" + "Major mode to query structured log lines" + (setq tabulated-list-format + (cl-map 'vector + (lambda (field) + (list (symbol-name field) 20 t)) + structlog-fields) + tabulated-list-entries #'structlog--make-list-entries) + (tabulated-list-init-header)) + +;;;###autoload +(defun structlog () + (interactive) + (when (get-buffer "*structlog*") + (kill-buffer "*structlog*")) + (with-current-buffer (get-buffer-create "*structlog*") + ;; TODO do something real here + (setq structlog-fields '(time event) + structlog-logs '((time "2020-06-02T16:55:00" event "Got a baz") + (time "2020-06-02T17:00:00" event "Got a bar") + (time "2020-06-02T17:04:00" event "Got a foo"))) + (structlog-mode) + (tabulated-list-print)) + (switch-to-buffer "*structlog*"))