From: Dan Espen <despen@verizon.net>
To: help-gnu-emacs@gnu.org
Subject: Re: factor out error message functions, access function stack to know location
Date: Sun, 25 Oct 2015 22:42:34 -0400 [thread overview]
Message-ID: <n0k3qq$t3j$1@dont-email.me> (raw)
In-Reply-To: mailman.1053.1445821696.7904.help-gnu-emacs@gnu.org
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
next parent reply other threads:[~2015-10-26 2:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.1053.1445821696.7904.help-gnu-emacs@gnu.org>
2015-10-26 2:42 ` Dan Espen [this message]
2015-10-27 0:27 ` factor out error message functions, access function stack to know location Emanuel Berg
2015-10-27 1:50 ` Emanuel Berg
2015-10-26 1:17 Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='n0k3qq$t3j$1@dont-email.me' \
--to=despen@verizon.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.