aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell/esh-cmd.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-cmd.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-cmd.el')
-rw-r--r--lisp/eshell/esh-cmd.el105
1 files changed, 23 insertions, 82 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 80066263396..ed2d6c71fc8 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -237,17 +237,6 @@ return non-nil if the command is complex."
237 :version "24.1" ; removed eshell-cmd-initialize 237 :version "24.1" ; removed eshell-cmd-initialize
238 :type 'hook) 238 :type 'hook)
239 239
240(defcustom eshell-debug-command nil
241 "If non-nil, enable Eshell debugging code.
242This is slow, and only useful for debugging problems with Eshell.
243If you change this without using customize after Eshell has loaded,
244you must re-load `esh-cmd.el'."
245 :initialize 'custom-initialize-default
246 :set (lambda (symbol value)
247 (set symbol value)
248 (load "esh-cmd"))
249 :type 'boolean)
250
251(defcustom eshell-deferrable-commands 240(defcustom eshell-deferrable-commands
252 '(eshell-named-command 241 '(eshell-named-command
253 eshell-lisp-command 242 eshell-lisp-command
@@ -436,22 +425,9 @@ hooks should be run before and after the command."
436 (run-hooks 'eshell-post-command-hook))) 425 (run-hooks 'eshell-post-command-hook)))
437 (macroexp-progn commands)))) 426 (macroexp-progn commands))))
438 427
439(defun eshell-debug-command (tag subform)
440 "Output a debugging message to `*eshell last cmd*'."
441 (let ((buf (get-buffer-create "*eshell last cmd*"))
442 (text (eshell-stringify eshell-current-command)))
443 (with-current-buffer buf
444 (if (not tag)
445 (erase-buffer)
446 (insert "\n\C-l\n" tag "\n\n" text
447 (if subform
448 (concat "\n\n" (eshell-stringify subform)) ""))))))
449
450(defun eshell-debug-show-parsed-args (terms) 428(defun eshell-debug-show-parsed-args (terms)
451 "Display parsed arguments in the debug buffer." 429 "Display parsed arguments in the debug buffer."
452 (ignore 430 (ignore (eshell-debug-command 'form "parsed arguments" terms)))
453 (if eshell-debug-command
454 (eshell-debug-command "parsed arguments" terms))))
455 431
456(defun eshell-no-command-conversion (terms) 432(defun eshell-no-command-conversion (terms)
457 "Don't convert the command argument." 433 "Don't convert the command argument."
@@ -942,38 +918,6 @@ This avoids the need to use `let*'."
942;; finishes, it will resume the evaluation using the remainder of the 918;; finishes, it will resume the evaluation using the remainder of the
943;; command tree. 919;; command tree.
944 920
945(defun eshell/eshell-debug (&rest args)
946 "A command for toggling certain debug variables."
947 (ignore
948 (cond
949 ((not args)
950 (if eshell-handle-errors
951 (eshell-print "errors\n"))
952 (if eshell-debug-command
953 (eshell-print "commands\n")))
954 ((member (car args) '("-h" "--help"))
955 (eshell-print "usage: eshell-debug [kinds]
956
957This command is used to aid in debugging problems related to Eshell
958itself. It is not useful for anything else. The recognized `kinds'
959at the moment are:
960
961 errors stops Eshell from trapping errors
962 commands shows command execution progress in `*eshell last cmd*'
963"))
964 (t
965 (while args
966 (cond
967 ((string= (car args) "errors")
968 (setq eshell-handle-errors (not eshell-handle-errors)))
969 ((string= (car args) "commands")
970 (setq eshell-debug-command (not eshell-debug-command))))
971 (setq args (cdr args)))))))
972
973(defun pcomplete/eshell-mode/eshell-debug ()
974 "Completion for the `debug' command."
975 (while (pcomplete-here '("errors" "commands"))))
976
977(iter-defun eshell--find-subcommands (haystack) 921(iter-defun eshell--find-subcommands (haystack)
978 "Recursively search for subcommand forms in HAYSTACK. 922 "Recursively search for subcommand forms in HAYSTACK.
979This yields the SUBCOMMANDs when found in forms like 923This yields the SUBCOMMANDs when found in forms like
@@ -1049,10 +993,7 @@ process(es) in a cons cell like:
1049 (if here 993 (if here
1050 (eshell-update-markers here)) 994 (eshell-update-markers here))
1051 (eshell-do-eval ',command)))) 995 (eshell-do-eval ',command))))
1052 (and eshell-debug-command 996 (eshell-debug-command-start input)
1053 (with-current-buffer (get-buffer-create "*eshell last cmd*")
1054 (erase-buffer)
1055 (insert "command: \"" input "\"\n")))
1056 (setq eshell-current-command command) 997 (setq eshell-current-command command)
1057 (let* (result 998 (let* (result
1058 (delim (catch 'eshell-incomplete 999 (delim (catch 'eshell-incomplete
@@ -1088,17 +1029,17 @@ process(es) in a cons cell like:
1088 (error 1029 (error
1089 (error (error-message-string err))))) 1030 (error (error-message-string err)))))
1090 1031
1091(defmacro eshell-manipulate (tag &rest commands) 1032(defmacro eshell-manipulate (form tag &rest body)
1092 "Manipulate a COMMAND form, with TAG as a debug identifier." 1033 "Manipulate a command FORM with BODY, using TAG as a debug identifier."
1093 (declare (indent 1)) 1034 (declare (indent 2))
1094 ;; Check `bound'ness since at compile time the code until here has not 1035 (let ((tag-symbol (make-symbol "tag")))
1095 ;; executed yet. 1036 `(if (not (memq 'form eshell-debug-command))
1096 (if (not (and (boundp 'eshell-debug-command) eshell-debug-command)) 1037 (progn ,@body)
1097 `(progn ,@commands) 1038 (let ((,tag-symbol ,tag))
1098 `(progn 1039 (eshell-debug-command 'form ,tag-symbol ,form 'always)
1099 (eshell-debug-command ,(eval tag) form) 1040 ,@body
1100 ,@commands 1041 (eshell-debug-command 'form (concat "done " ,tag-symbol) ,form
1101 (eshell-debug-command ,(concat "done " (eval tag)) form)))) 1042 'always)))))
1102 1043
1103(defun eshell-do-eval (form &optional synchronous-p) 1044(defun eshell-do-eval (form &optional synchronous-p)
1104 "Evaluate FORM, simplifying it as we go. 1045 "Evaluate FORM, simplifying it as we go.
@@ -1125,8 +1066,8 @@ have been replaced by constants."
1125 ;; we can modify any `let' forms to evaluate only once. 1066 ;; we can modify any `let' forms to evaluate only once.
1126 (if (macrop (car form)) 1067 (if (macrop (car form))
1127 (let ((exp (copy-tree (macroexpand form)))) 1068 (let ((exp (copy-tree (macroexpand form))))
1128 (eshell-manipulate (format-message "expanding macro `%s'" 1069 (eshell-manipulate form
1129 (symbol-name (car form))) 1070 (format-message "expanding macro `%s'" (symbol-name (car form)))
1130 (setcar form (car exp)) 1071 (setcar form (car exp))
1131 (setcdr form (cdr exp))))) 1072 (setcdr form (cdr exp)))))
1132 (let ((args (cdr form))) 1073 (let ((args (cdr form)))
@@ -1138,7 +1079,7 @@ have been replaced by constants."
1138 (let ((new-form (copy-tree `(let ((eshell--command-body nil) 1079 (let ((new-form (copy-tree `(let ((eshell--command-body nil)
1139 (eshell--test-body nil)) 1080 (eshell--test-body nil))
1140 (eshell--wrapped-while ,@args))))) 1081 (eshell--wrapped-while ,@args)))))
1141 (eshell-manipulate "modifying while form" 1082 (eshell-manipulate form "modifying while form"
1142 (setcar form (car new-form)) 1083 (setcar form (car new-form))
1143 (setcdr form (cdr new-form))) 1084 (setcdr form (cdr new-form)))
1144 (eshell-do-eval form synchronous-p))) 1085 (eshell-do-eval form synchronous-p)))
@@ -1161,7 +1102,7 @@ have been replaced by constants."
1161 (setq eshell--command-body nil 1102 (setq eshell--command-body nil
1162 eshell--test-body (copy-tree (car args))))) 1103 eshell--test-body (copy-tree (car args)))))
1163 ((eq (car form) 'if) 1104 ((eq (car form) 'if)
1164 (eshell-manipulate "evaluating if condition" 1105 (eshell-manipulate form "evaluating if condition"
1165 (setcar args (eshell-do-eval (car args) synchronous-p))) 1106 (setcar args (eshell-do-eval (car args) synchronous-p)))
1166 (eshell-do-eval 1107 (eshell-do-eval
1167 (cond 1108 (cond
@@ -1180,7 +1121,7 @@ have been replaced by constants."
1180 (eval form)) 1121 (eval form))
1181 ((eq (car form) 'let) 1122 ((eq (car form) 'let)
1182 (unless (eq (car-safe (cadr args)) 'eshell-do-eval) 1123 (unless (eq (car-safe (cadr args)) 'eshell-do-eval)
1183 (eshell-manipulate "evaluating let args" 1124 (eshell-manipulate form "evaluating let args"
1184 (dolist (letarg (car args)) 1125 (dolist (letarg (car args))
1185 (when (and (listp letarg) 1126 (when (and (listp letarg)
1186 (not (eq (cadr letarg) 'quote))) 1127 (not (eq (cadr letarg) 'quote)))
@@ -1207,7 +1148,7 @@ have been replaced by constants."
1207 ;; the let-bindings' values so that those values are 1148 ;; the let-bindings' values so that those values are
1208 ;; correct when we resume evaluation of this form. 1149 ;; correct when we resume evaluation of this form.
1209 (when deferred 1150 (when deferred
1210 (eshell-manipulate "rebinding let args after `eshell-defer'" 1151 (eshell-manipulate form "rebinding let args after `eshell-defer'"
1211 (let ((bindings (car args))) 1152 (let ((bindings (car args)))
1212 (while bindings 1153 (while bindings
1213 (let ((binding (if (consp (car bindings)) 1154 (let ((binding (if (consp (car bindings))
@@ -1232,7 +1173,7 @@ have been replaced by constants."
1232 (unless (eq (car form) 'unwind-protect) 1173 (unless (eq (car form) 'unwind-protect)
1233 (setq args (cdr args))) 1174 (setq args (cdr args)))
1234 (unless (eq (caar args) 'eshell-do-eval) 1175 (unless (eq (caar args) 'eshell-do-eval)
1235 (eshell-manipulate "handling special form" 1176 (eshell-manipulate form "handling special form"
1236 (setcar args `(eshell-do-eval ',(car args) ,synchronous-p)))) 1177 (setcar args `(eshell-do-eval ',(car args) ,synchronous-p))))
1237 (eval form)) 1178 (eval form))
1238 ((eq (car form) 'setq) 1179 ((eq (car form) 'setq)
@@ -1242,7 +1183,7 @@ have been replaced by constants."
1242 (list 'quote (eval form))) 1183 (list 'quote (eval form)))
1243 (t 1184 (t
1244 (if (and args (not (memq (car form) '(run-hooks)))) 1185 (if (and args (not (memq (car form) '(run-hooks))))
1245 (eshell-manipulate 1186 (eshell-manipulate form
1246 (format-message "evaluating arguments to `%s'" 1187 (format-message "evaluating arguments to `%s'"
1247 (symbol-name (car form))) 1188 (symbol-name (car form)))
1248 (while args 1189 (while args
@@ -1283,7 +1224,7 @@ have been replaced by constants."
1283 (setq result (eval form)))))) 1224 (setq result (eval form))))))
1284 (if new-form 1225 (if new-form
1285 (progn 1226 (progn
1286 (eshell-manipulate "substituting replacement form" 1227 (eshell-manipulate form "substituting replacement form"
1287 (setcar form (car new-form)) 1228 (setcar form (car new-form))
1288 (setcdr form (cdr new-form))) 1229 (setcdr form (cdr new-form)))
1289 (eshell-do-eval form synchronous-p)) 1230 (eshell-do-eval form synchronous-p))
@@ -1292,7 +1233,7 @@ have been replaced by constants."
1292 (procs (eshell-make-process-pair result))) 1233 (procs (eshell-make-process-pair result)))
1293 (if synchronous-p 1234 (if synchronous-p
1294 (eshell/wait (cdr procs)) 1235 (eshell/wait (cdr procs))
1295 (eshell-manipulate "inserting ignore form" 1236 (eshell-manipulate form "inserting ignore form"
1296 (setcar form 'ignore) 1237 (setcar form 'ignore)
1297 (setcdr form nil)) 1238 (setcdr form nil))
1298 (throw 'eshell-defer procs)) 1239 (throw 'eshell-defer procs))