From bc8103b8f8bca1706ec9ee0dd0cdfa1621987438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20N=C3=A1jera?= Date: Wed, 7 Sep 2022 23:19:38 +0200 Subject: journalctl cleanup buffer --- elisp/journalctl.el | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/elisp/journalctl.el b/elisp/journalctl.el index fd6582c..f36ebc1 100644 --- a/elisp/journalctl.el +++ b/elisp/journalctl.el @@ -123,9 +123,19 @@ "--boot" "--since" "--until" + "--user" "--priority") "List of possible options to be given to journalctl." ) +(defun journalctl--clean-buffer () + "Produce a clean buffer for the log. +It seems I must kill the buffer for tramp to behave correctly on the new calls." + (let* ((name-buffer "JOURNAL LOG") + (buffer (get-buffer name-buffer))) + (when (buffer-live-p buffer) + (kill-buffer buffer)) + (get-buffer-create name-buffer))) + (defun journalctl-system-units (host-location) "Query HOST-LOCATION (a tramp path) for its systemd units." (interactive (list (completing-read "Tramp host: " journalctl-hosts))) @@ -138,46 +148,40 @@ (delq nil) (completing-read "Unit: "))))) - (defun journalctl (host options) "Query the log of HOST given OPTIONS." (interactive (let* ((picked-host (completing-read "Tramp host: " journalctl-hosts)) (default-options `(("--unit" ,(journalctl-system-units picked-host)) ("--follow")))) (list picked-host default-options))) - (let ((buffer (get-buffer-create "JOURNAL LOG")) + (let ((buffer (journalctl--clean-buffer)) (default-directory host)) (apply #'start-file-process "Journal" buffer "journalctl" (flatten-tree options)) (with-current-buffer buffer (journalctl-mode) (setq-local journalctl-current-host host) - (setq-local journalctl-current-opts options) - (switch-to-buffer (current-buffer))))) + (setq-local journalctl-current-opts options)) + (switch-to-buffer buffer))) (defun journalctl-remove-opt (opt) - "Remove option from journalctl call. - -If OPT is set, remove this option." + "Remove an OPT flag from the journal query." (interactive (list (completing-read "remove option" (mapcar #'car journalctl-current-opts) nil t))) (let ((new-opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts)) (host journalctl-current-host)) - (kill-buffer (get-buffer "JOURNAL LOG")) (journalctl host new-opts))) - (defun journalctl-add-opt (opt) "Remove option from journalctl call. If OPT is set, remove this option." - (interactive (list (completing-read "add option" journalctl-list-of-options nil t))) - (let* ((buff (get-buffer "JOURNAL LOG")) - (opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts)) - (host journalctl-current-host)) - (kill-buffer buff) + (interactive (list (completing-read "add option: " journalctl-list-of-options nil t))) + (let ((opts (delq (assoc opt journalctl-current-opts) journalctl-current-opts)) + (host journalctl-current-host)) (thread-last (pcase opt ((or "--since" "--until") (org-read-date t)) - ((or "--follow" "--reverse")) + ((or "--follow" "--reverse" "--user")) + ("--unit" (journalctl-system-units host)) (_ (read-string (concat opt "= ")))) (list opt) (list) @@ -187,20 +191,19 @@ If OPT is set, remove this option." (defun journalctl-edit-opts () "Edit the value of 'journalctl-current-opts'." (interactive) - (let* ((buff (get-buffer "JOURNAL LOG")) - (host journalctl-current-host) - (opts (when buff (with-current-buffer buff journalctl-current-opts)))) - (with-current-buffer (get-buffer-create "Edit Journalctl options") + (let* ((host journalctl-current-host) + (opts journalctl-current-opts) + (edit-buff (get-buffer-create "Edit Journalctl options"))) + (with-current-buffer edit-buff (emacs-lisp-mode) (cl-prettyprint opts) (local-set-key "\C-c\C-c" (lambda () (interactive) (goto-char (point-min)) - (kill-buffer buff) (let ((standard-input (current-buffer))) (journalctl host (read))) - (kill-buffer))) + (kill-buffer edit-buff))) (switch-to-buffer (current-buffer))))) -- cgit v1.2.3