all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* eshell lisp errors
@ 2024-09-25 19:06 Christopher Howard
  2024-09-25 19:19 ` Emanuel Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Howard @ 2024-09-25 19:06 UTC (permalink / raw)
  To: Emacs Devel Mailing List

Hi, I'm doing some hackish stuff — you probably don't want to know — involving setting up an environment with eshell scripts. I found out if I try to set the value of a built-in variable, I get a lisp error. e.g., "export PWD=some-directory" raises error "eshell-set-variable: Variable ‘PWD’ is not settable".

That is fine, I suppose, but I was wondering: In eshell, is there some way to do something with the exception, rather than just report it, or trap it in the debugger? Some hook, maybe...? It would be neat, e.g., if I could examine the error, then decide if I wanted to continue on with the rest of the script, or abort.

-- 
📛 Christopher Howard
🚀 gemini://gem.librehacker.com
🌐 http://gem.librehacker.com

בראשית ברא אלהים את השמים ואת הארץ



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: eshell lisp errors
  2024-09-25 19:06 eshell lisp errors Christopher Howard
@ 2024-09-25 19:19 ` Emanuel Berg
  2024-09-26 15:00   ` Christopher Howard
  0 siblings, 1 reply; 3+ messages in thread
From: Emanuel Berg @ 2024-09-25 19:19 UTC (permalink / raw)
  To: emacs-devel

Christopher Howard wrote:

> That is fine, I suppose, but I was wondering: In eshell, is
> there some way to do something with the exception, rather
> than just report it, or trap it in the debugger? Some hook,
> maybe...? It would be neat, e.g., if I could examine the
> error, then decide if I wanted to continue on with the rest
> of the script, or abort.

But then won't people start to loose respect for errors? ;)

When you say "in eshell", you mean something else than
in Elisp

(condition-case nil
    (funcall next)
  (error (goto-char end)))

?

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: eshell lisp errors
  2024-09-25 19:19 ` Emanuel Berg
@ 2024-09-26 15:00   ` Christopher Howard
  0 siblings, 0 replies; 3+ messages in thread
From: Christopher Howard @ 2024-09-26 15:00 UTC (permalink / raw)
  To: emacs-devel

Emanuel Berg <incal@dataswamp.org> writes:

>
> When you say "in eshell", you mean something else than
> in Elisp
>
> (condition-case nil
>     (funcall next)
>   (error (goto-char end)))

Hi, to be honest I'm not sure sure that I properly understand the question, so I'm not sure how to respond.

Maybe I can try to restate/clarify my motivation: I found out, when writing my own eshell script, that it is possible for commands I have entered — in command form — to throw an elisp error. Conceivably any command that involves an eshell built-in, or that specifies a list function as the command, could throw an elisp error, and so I might want to have some kind of handling/logic depending on the type of error or the significance of the command. Currently what happens is, depending on the debugging settings, either the script just continues on (with an error message reported) or it gets thrown to the debugger, where the user has to decide to quit or continue.

One could, I suppose, just replace the command form with an elisp form that includes error handling. But if you wanted to somehow preserve the convenience of the command form, you would have to wrap the command form up in an eshell-command call or something.

I suppose maybe what I am wanting is something like a command you can enter in a script that sets things up so that if the following X set of commands throws an error, then the error is inspected, some arbitrary thing can be done, and also it can decide whether or not to abort the script. Or perhaps something like the "trap" command in bash (https://phoenixnap.com/kb/bash-trap-command).

But maybe this is just asking too much of eshell, or trying to make things too complicated. In traditional system shells, you aren't dealing with handling exceptions, properly speaking — only with processing the return value from the previous program call. And handling process signals is not really the same thing as lisp exception handling.

Looking now, I see Emacs 30 has an eshell-trap-errors macro and an eshell-this-command-hook but I'm not sure if/how they are meant to be used by these user.

Hopefully my rambling here is somehow heading in a useful direction...

-- 
Christopher Howard



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-26 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-25 19:06 eshell lisp errors Christopher Howard
2024-09-25 19:19 ` Emanuel Berg
2024-09-26 15:00   ` Christopher Howard

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.