help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: factor out error message functions, access function stack to know lo


From: Dan Espen
Subject: Re: factor out error message functions, access function stack to know location
Date: Sun, 25 Oct 2015 22:42:34 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

> In the sweet science of shell scripting, I wrote some
> zsh the other day (that appears last in this post),
> along with a couple of other functions that will cover
> other typical error situations. [1]
>
> The thought is to have uniform error messages so that
> when a function for example doesn't get sufficient
> input, or cannot verity it, as those situations are
> common to many functions, an error function will be
> called to print a stderr message, rather than to have
> that coded over and over in all those functions.
>
> Only problem is, in order for debugging to be much
> less painful, the location where the problem happens
> must still be known. In the below zsh, the first line
> handles this by accessing the function stack - pretty
> clever, ey?
>
> Note: arrays in zsh are *not* zero-indexed, so the
> first element of funcstack is funcstack[1] and that is
> the current function! Ergo, funcstack[2] is the
> function that called the error handler!
>
> My question is, how do I do the same in Lisp (Elisp)?
>
> The zsh:
>
>     no-file-msg () {
>         local fun=$funcstack[2]
>         local file=$1
>         echo "$fun: no such file: $file" >&2
>     }
>
> [1] http://user.it.uu.se/~embe8573/conf/.zsh/error

Pretty good discussion here, including access to the call stack:

http://emacs.stackexchange.com/questions/2310/can-functions-access-their-name

-- 
Dan Espen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]