From 7e50861ca7ed3f620fe62ac6572f6e88b3600ece Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 14 Sep 2023 17:51:16 -0700 Subject: [PATCH] ; Simplify how to use 'eshell-debug-command' Now, 'eshell-debug-command' works more like 'format-message', which is how we usually use it. * lisp/eshell/esh-util.el (eshell-always-debug-command): New function. (eshell-debug-command): Simplify. Update callers. --- lisp/eshell/esh-arg.el | 6 +++--- lisp/eshell/esh-cmd.el | 10 ++++++---- lisp/eshell/esh-proc.el | 41 +++++++++++++++++------------------------ lisp/eshell/esh-util.el | 26 +++++++++++++++++--------- 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/lisp/eshell/esh-arg.el b/lisp/eshell/esh-arg.el index e9c6a7f2f68..e7b5eef11db 100644 --- a/lisp/eshell/esh-arg.el +++ b/lisp/eshell/esh-arg.el @@ -294,9 +294,9 @@ then the result will be: eshell-current-argument))) (setq eshell-arg-listified nil)) (when eshell-current-modifiers - (eshell-debug-command 'form (format-message "applying modifiers %S" - eshell-current-modifiers) - eshell-current-argument)) + (eshell-debug-command 'form + "applying modifiers %S\n\n%s" eshell-current-modifiers + (eshell-stringify eshell-current-argument))) (dolist (modifier eshell-current-modifiers) (setq eshell-current-argument (list modifier eshell-current-argument)))) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index e5ddcfcaa35..0bc9ce34d32 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -424,7 +424,8 @@ hooks should be run before and after the command." (defun eshell-debug-show-parsed-args (terms) "Display parsed arguments in the debug buffer." - (ignore (eshell-debug-command 'form "parsed arguments" terms))) + (ignore (eshell-debug-command 'form + "parsed arguments\n\n%s" (eshell-stringify terms)))) (defun eshell-no-command-conversion (terms) "Don't convert the command argument." @@ -1031,10 +1032,11 @@ process(es) in a cons cell like: `(if (not (memq 'form eshell-debug-command)) (progn ,@body) (let ((,tag-symbol ,tag)) - (eshell-debug-command 'form ,tag-symbol ,form 'always) + (eshell-always-debug-command 'form + "%s\n\n%s" ,tag-symbol ,(eshell-stringify form)) ,@body - (eshell-debug-command 'form (concat "done " ,tag-symbol) ,form - 'always))))) + (eshell-always-debug-command 'form + "done %s\n\n%s " ,tag-symbol ,(eshell-stringify form)))))) (defun eshell-do-eval (form &optional synchronous-p) "Evaluate FORM, simplifying it as we go. diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el index fb6ed7a3489..aed8f8af93d 100644 --- a/lisp/eshell/esh-proc.el +++ b/lisp/eshell/esh-proc.el @@ -351,8 +351,10 @@ Used only on systems which do not support async subprocesses.") :connection-type conn-type :stderr stderr-proc :file-handler t))) - (eshell-debug-command - 'process (format-message "started external process `%s'" proc)) + (eshell-debug-command 'process + "started external process `%s'\n\n%s" proc + (mapconcat (lambda (i) (shell-quote-argument i 'posix)) + (process-command proc) " ")) (eshell-record-process-object proc) (eshell-record-process-properties proc) (when stderr-proc @@ -438,9 +440,8 @@ Used only on systems which do not support async subprocesses.") "Send the output from PROCESS (STRING) to the interactive display. This is done after all necessary filtering has been done." (when string - (eshell-debug-command - 'process (format-message "received output from process `%s'\n\n%s" - process string)) + (eshell-debug-command 'process + "received output from process `%s'\n\n%s" process string) (eshell--mark-as-output 0 (length string) string) (eshell-interactive-filter (if process (process-buffer process) (current-buffer)) @@ -453,27 +454,23 @@ This is done after all necessary filtering has been done." "Insert a string into the eshell buffer, or a process/file/buffer. PROC is the process for which we're inserting output. STRING is the output." - (eshell-debug-command - 'process (format-message "received output from process `%s'\n\n%s" - proc string)) + (eshell-debug-command 'process + "received output from process `%s'\n\n%s" proc string) (when (buffer-live-p (process-buffer proc)) (with-current-buffer (process-buffer proc) (process-put proc :eshell-pending (concat (process-get proc :eshell-pending) string)) (if (process-get proc :eshell-busy) - (eshell-debug-command - 'process (format-message "i/o busy for process `%s'" proc)) + (eshell-debug-command 'process "i/o busy for process `%s'" proc) (unwind-protect (let ((handles (process-get proc :eshell-handles)) (index (process-get proc :eshell-handle-index)) data) (while (setq data (process-get proc :eshell-pending)) (process-put proc :eshell-pending nil) - (eshell-debug-command - 'process (format-message - "forwarding output from process `%s'\n\n%s" - proc data)) + (eshell-debug-command 'process + "forwarding output from process `%s'\n\n%s" proc data) (condition-case nil (eshell-output-object data index handles) ;; FIXME: We want to send SIGPIPE to the process @@ -497,9 +494,8 @@ output." (defun eshell-sentinel (proc string) "Generic sentinel for command processes. Reports only signals. PROC is the process that's exiting. STRING is the exit message." - (eshell-debug-command - 'process (format-message "sentinel for external process `%s': %S" - proc string)) + (eshell-debug-command 'process + "sentinel for external process `%s': %S" proc string) (when (and (buffer-live-p (process-buffer proc)) (not (string= string "run"))) (with-current-buffer (process-buffer proc) @@ -531,9 +527,8 @@ PROC is the process that's exiting. STRING is the exit message." (if (or (process-get proc :eshell-busy) (and wait-for-stderr (car stderr-live))) (progn - (eshell-debug-command - 'process (format-message - "i/o busy for process `%s'" proc)) + (eshell-debug-command 'process + "i/o busy for process `%s'" proc) (run-at-time 0 nil finish-io)) (when data (ignore-error eshell-pipe-broken @@ -546,10 +541,8 @@ PROC is the process that's exiting. STRING is the exit message." ;; Clear the handles to mark that we're 100% ;; finished with the I/O for this process. (process-put proc :eshell-handles nil) - (eshell-debug-command - 'process - (format-message - "finished external process `%s'" proc)) + (eshell-debug-command 'process + "finished external process `%s'" proc) (if primary (eshell-kill-process-function proc string) (setcar stderr-live nil)))))) diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el index 5134adeb7fb..4c251a29269 100644 --- a/lisp/eshell/esh-util.el +++ b/lisp/eshell/esh-util.el @@ -192,18 +192,26 @@ start logging to `*eshell last cmd*'." (erase-buffer) (insert "command: \"" command "\"\n")))) -(defmacro eshell-debug-command (kind message &optional form always) +(defun eshell-always-debug-command (kind string &rest objects) + "Output a debugging message to `*eshell last cmd*'. +KIND is the kind of message to log. STRING and OBJECTS are as +`format-message' (which see)." + (declare (indent 1)) + (with-current-buffer (get-buffer-create eshell-debug-command-buffer) + (insert "\n\C-l\n[" (symbol-name kind) "] " + (apply #'format-message string objects)))) + +(defmacro eshell-debug-command (kind string &rest objects) "Output a debugging message to `*eshell last cmd*' if debugging is enabled. -KIND is the kind of message to log (either `form' or `io'). If -present in `eshell-debug-command' (or if ALWAYS is non-nil), -output this message; otherwise, ignore it." +KIND is the kind of message to log (either `form' or `process'). If +present in `eshell-debug-command', output this message; otherwise, ignore it. + +STRING and OBJECTS are as `format-message' (which see)." + (declare (indent 1)) (let ((kind-sym (make-symbol "kind"))) `(let ((,kind-sym ,kind)) - (when ,(or always `(memq ,kind-sym eshell-debug-command)) - (with-current-buffer (get-buffer-create eshell-debug-command-buffer) - (insert "\n\C-l\n[" (symbol-name ,kind-sym) "] " ,message) - (when-let ((form ,form)) - (insert "\n\n" (eshell-stringify form)))))))) + (when (memq ,kind-sym eshell-debug-command) + (eshell-always-debug-command ,kind-sym ,string ,@objects))))) (defun eshell--mark-as-output (start end &optional object) "Mark the text from START to END as Eshell output. -- 2.39.5