aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell/esh-util.el
diff options
context:
space:
mode:
authorJim Porter2023-08-29 17:02:40 -0700
committerJim Porter2023-08-31 18:42:03 -0700
commitccb62321d234993a66287c4e1a3cfdea63d140ff (patch)
tree7ffd2b146ef96a19522ae701586fa82b73ddc680 /lisp/eshell/esh-util.el
parent17188e07ab9084f8d25dedcb784957a461348fa9 (diff)
downloademacs-ccb62321d234993a66287c4e1a3cfdea63d140ff.tar.gz
emacs-ccb62321d234993a66287c4e1a3cfdea63d140ff.zip
Fix handling of Eshell debug modes
Previously, these were enabled/disabled at byte-compilation time, but we want to control them at runtime. * lisp/eshell/esh-cmd.el (eshell-eval-command): Call 'eshell-debug-command-start'. (eshell-manipulate): Check 'eshell-debug-command' at runtime. Update callers. (eshell-debug-command): Move to "esh-util.el". (eshell/eshell-debug, pcomplate/eshell-mode/eshell-debug): Move to "em-basic.el". (eshell-debug-show-parsed-args): Update implementation. * lisp/eshell/esh-util.el (eshell-debug-command): Move from "esh-cmd.el" and convert to a list. (eshell-debug-command-buffer): New variable. (eshell-condition-case): Check 'eshell-handle-errors' at runtime. (eshell-debug-command-start): New function. (eshell-debug-command): Move from "esh-cmd.el" and convert to a macro. * lisp/eshell/em-basic.el (eshell/eshell-debug) (pcomplete/eshell-mode/eshell-debug): Move from "esh-cmd.el" and reimplement. * lisp/eshell/eshell.el (eshell-command): Pass the original input to 'eshell-eval-command'. * doc/misc/eshell.texi (Built-ins): Update documentation for 'eshell-debug'.
Diffstat (limited to 'lisp/eshell/esh-util.el')
-rw-r--r--lisp/eshell/esh-util.el44
1 files changed, 39 insertions, 5 deletions
diff --git a/lisp/eshell/esh-util.el b/lisp/eshell/esh-util.el
index 87cd1f5dcb2..8be4536cff7 100644
--- a/lisp/eshell/esh-util.el
+++ b/lisp/eshell/esh-util.el
@@ -102,6 +102,15 @@ argument matches `eshell-number-regexp'."
102 (string :tag "Username") 102 (string :tag "Username")
103 (repeat :tag "UIDs" string)))))) 103 (repeat :tag "UIDs" string))))))
104 104
105(defcustom eshell-debug-command nil
106 "A list of debug features to enable when running Eshell commands.
107Possible entries are `form', to log the manipulation of Eshell
108command forms.
109
110If nil, don't debug commands at all."
111 :version "30.1"
112 :type '(set (const :tag "Form manipulation" form)))
113
105;;; Internal Variables: 114;;; Internal Variables:
106 115
107(defvar eshell-number-regexp 116(defvar eshell-number-regexp
@@ -145,6 +154,9 @@ function `string-to-number'.")
145 ,#'eshell--mark-yanked-as-output)) 154 ,#'eshell--mark-yanked-as-output))
146 "A list of text properties to apply to command output.") 155 "A list of text properties to apply to command output.")
147 156
157(defvar eshell-debug-command-buffer "*eshell last cmd*"
158 "The name of the buffer to log debug messages about command invocation.")
159
148;;; Obsolete variables: 160;;; Obsolete variables:
149 161
150(define-obsolete-variable-alias 'eshell-host-names 162(define-obsolete-variable-alias 'eshell-host-names
@@ -164,11 +176,33 @@ function `string-to-number'.")
164 "If `eshell-handle-errors' is non-nil, this is `condition-case'. 176 "If `eshell-handle-errors' is non-nil, this is `condition-case'.
165Otherwise, evaluates FORM with no error handling." 177Otherwise, evaluates FORM with no error handling."
166 (declare (indent 2) (debug (sexp form &rest form))) 178 (declare (indent 2) (debug (sexp form &rest form)))
167 (if eshell-handle-errors 179 `(if eshell-handle-errors
168 `(condition-case-unless-debug ,tag 180 (condition-case-unless-debug ,tag
169 ,form 181 ,form
170 ,@handlers) 182 ,@handlers)
171 form)) 183 ,form))
184
185(defun eshell-debug-command-start (command)
186 "Start debugging output for the command string COMMAND.
187If debugging is enabled (see `eshell-debug-command'), this will
188start logging to `*eshell last cmd*'."
189 (when eshell-debug-command
190 (with-current-buffer (get-buffer-create eshell-debug-command-buffer)
191 (erase-buffer)
192 (insert "command: \"" command "\"\n"))))
193
194(defmacro eshell-debug-command (kind message &optional form always)
195 "Output a debugging message to `*eshell last cmd*' if debugging is enabled.
196KIND is the kind of message to log (either `form' or `io'). If
197present in `eshell-debug-command' (or if ALWAYS is non-nil),
198output this message; otherwise, ignore it."
199 (let ((kind-sym (make-symbol "kind")))
200 `(let ((,kind-sym ,kind))
201 (when ,(or always `(memq ,kind-sym eshell-debug-command))
202 (with-current-buffer (get-buffer-create eshell-debug-command-buffer)
203 (insert "\n\C-l\n[" (symbol-name ,kind-sym) "] " ,message)
204 (when-let ((form ,form))
205 (insert "\n\n" (eshell-stringify form))))))))
172 206
173(defun eshell--mark-as-output (start end &optional object) 207(defun eshell--mark-as-output (start end &optional object)
174 "Mark the text from START to END as Eshell output. 208 "Mark the text from START to END as Eshell output.