I got the below function from an article on howardism.org. Its purpose is to exit eshell and close the corresponding window.
;; GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.10) of 2019-08-29
(defun eshell/x ()
(insert "exit")
(eshell-send-input)
(delete-window))
(setq debug-on-error t)
Looked pretty straightforward to me. But when I start emacs -Q
(See above code block for version info), then evaluate the above code and type x<RET>
in an eshell window. I get the following:
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
eshell-lisp-command(eshell/x nil)
eshell-plain-command("x" nil)
eshell-named-command("x")
(prog1 (eshell-named-command "x") (run-hooks (quote eshell-this-command-hook)))
(condition-case err (prog1 (eshell-named-command "x") (run-hooks (quote eshell-this-command-hook))) ((debug error) (run-hooks (quote eshell-this-command-hook)) (eshell-errorn (error-message-string err)) (eshell-close-handles 1)))
(condition-case-unless-debug err (prog1 (eshell-named-command "x") (run-hooks (quote eshell-this-command-hook))) (error (run-hooks (quote eshell-this-command-hook)) (eshell-errorn (error-message-string err)) (eshell-close-handles 1)))
(eshell-condition-case err (prog1 (eshell-named-command "x") (run-hooks (quote eshell-this-command-hook))) (error (run-hooks (quote eshell-this-command-hook)) (eshell-errorn (error-message-string err)) (eshell-close-handles 1)))
(let ((eshell-this-command-hook (quote (ignore)))) (eshell-condition-case err (prog1 (eshell-named-command "x") (run-hooks (quote eshell-this-command-hook))) (error (run-hooks (quote eshell-this-command-hook)) (eshell-errorn (error-message-string err)) (eshell-close-handles 1))))
(eshell-trap-errors (eshell-named-command "x"))
(progn (eshell-trap-errors (eshell-named-command "x")))
(catch (quote top-level) (progn (eshell-trap-errors (eshell-named-command "x"))))
(progn (run-hooks (quote eshell-pre-command-hook)) (catch (quote top-level) (progn (eshell-trap-errors (eshell-named-command "x")))) (run-hooks (quote eshell-post-command-hook)))
(let ((eshell-current-handles (eshell-create-handles t (quote append))) eshell-current-subjob-p) (progn (run-hooks (quote eshell-pre-command-hook)) (catch (quote top-level) (progn (eshell-trap-errors (eshell-named-command "x")))) (run-hooks (quote eshell-post-command-hook))))
(eshell-commands (progn (run-hooks (quote eshell-pre-command-hook)) (catch (quote top-level) (progn (eshell-trap-errors (eshell-named-command "x")))) (run-hooks (quote eshell-post-command-hook))))
eval((eshell-commands (progn (run-hooks (quote eshell-pre-command-hook)) (catch (quote top-level) (progn (eshell-trap-errors (eshell-named-command "x")))) (run-hooks (quote eshell-post-command-hook)))))
eshell-send-input(nil)
funcall-interactively(eshell-send-input nil)
call-interactively(eshell-send-input nil nil)
command-execute(eshell-send-input)
Without debug-on-error the "Wrong type argument"-message ends up in the buffer I was working in when invoking eshell.
To add to my confusion, this only happens the first time I call eshell/x
.
Stepping through the function with edebug suggests that the error occurs in neither of the functions called inside eshell/x
as the debugger only starts after I stepped over the last function call. Also when changing the function to this
(defun eshell/x ()
(insert "exit")
(eshell-send-input)
(delete-window)
(message "done deleting window"))
The debugger only gets entered after "done deleting window" appeared in the echo area.
Now I don't know how to continue searching for the error. Can someone please help me identify the error?