From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: acm@muc.de, Eli Zaretskii <eliz@gnu.org>, 67455@debbugs.gnu.org
Subject: bug#67455: (Record source position, etc., in doc strings, and use this in *Help* and backtraces.)
Date: Sun, 10 Mar 2024 19:22:04 +0000 [thread overview]
Message-ID: <Ze4IXIrh-WbZaTSu@ACM> (raw)
In-Reply-To: <jwvcys2j9wp.fsf-monnier+emacs@gnu.org>
Hello, Stefan.
On Sun, Mar 10, 2024 at 13:19:03 -0400, Stefan Monnier wrote:
> > I've got a version almost ready which actually does something, namely
> > prefixes "anonymous" lines of a backtrace with the name of the defining
> > symbol, like {foo} . It'll soon be time to start seriously thinking
> > about what information ought to go there for the live version.
> Cool!
I've finally got something to show. I've just committed a merge and a
fix for it to branch feature/positioned-lambdas at savannah.
With this Emacs running, type the following into *scratch*
(defun foo () "foo doc" (lambda (bar) "lambda doc" (car bar)))
.. Either evaluate this or byte compile it with compile-defun. Then do
M-: (funcall (foo) 'baz)
.. This will produce a backtrace like:
Debugger entered--Lisp error: (wrong-type-argument listp baz)
car(baz)
{foo} #f(compiled-function (bar) "lambda doc" #<bytecode -0x14ae78a46439bbc>)(baz)
funcall({foo} #f(compiled-function (bar) "lambda doc" #<bytecode -0x14ae78a46439bbc>) baz)
(progn (funcall (foo) 'baz))
eval((progn (funcall (foo) 'baz)) t)
elisp--eval-last-sexp(nil)
{eval-last-sexp} #f(compiled-function () #<bytecode -0x1e8241efdb3d2890>)()
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
command-execute(eval-last-sexp)
.. Note the {eval-last-sexp} and {foo} on the anonymous functions.
:-)
> >> - Testing `byte-compile-in-progress` can't be right. Do you to test
> >> whether the result of this backquote will be byte-compiled or do you
> >> really mean to test whether this backquote happens to be executed
> >> during compilation (which could be because the compiler ends up
> >> loading code while executing `eval-when-compile` or `require`)?
> > Quite simply, during compilation, all symbols (except nil) get read with
> > position, so to strip their positions here would be wrong.
> This isn't quite right: during compilation, some code is read with
> positions (the code that we will compile), but some code is read in the
> normal way (the code we load for the purpose of running).
> The distinction is important.
OK, I wasn't really counting code that we load as "during compilation",
but I take the point.
> >> - My gut tells me that changing backquote can't be right.
> > I tend to agree. I put the code into backquote-process when having
> > problems with things like:
> > (mapatoms #'(lambda (,(car spec)) ,@body)
> > in cl-macs.el, where it's impossible to know where the doc string (if
> > any) is until after the expansion of the backquotes, or even at run time
> > (as here). In the latter case, rather than "posifying" the doc string
> > at macro expansion time, we have to generate code to do it at run time.
> Hmm... here what you call "run time" is really some later
> macro-expansion, right? The `lambda` symbol comes from the first
> macro-expansion (ME1), but the docstring comes from the second (ME2).
Yes. I often get confused between lots of different macro expansion
times, compile time and run time. It's a lot easier in C. ;-)
> IIUC the problem you face is that you want to get the function's
> position info from the `lambda` symbol, which here would be wrong (even if we
> try to preserve it long enough), is that it?
Something like that. The lambda's position currently gets preserved in
the generated code so that ME2 can use it.
> [ Tho, in more complex cases it becomes debatable whether the function's
> position should point to the position corresponding to ME1 or to that
> of ME2. ]
The code currently preserves both positions. :-) But only one buffer
name.
My latest thoughts on that are perhaps two file names (relative to the
Emacs top directory) would be better than one buffer name. Then I could
put buttons on the backtrace display which on being clicked would open
either of the source files at the right position.
> More generally: what goes wrong in the above example if you just treat
> that as a list of symbol (stripping them all of their position info).
> AFAICT when *that* macro is expanded (i.e. ME2) you'll presumably get
> code like
> (mapatoms #'(lambda (FOO/p) (DO/p SOME/p (THING/p))))
> right? [ where "/p" means that the symbol has a sympos. ]
> Isn't that sufficient info to add a docstring with position?
It's the lambda which has a position rather than the expanded bits from
ME2.
> >> (lambda (f) ..) *can* appear within a backquote without it being an
> >> actual lambda expression.
> >> What alternatives have you considered?
> > Not a lot of them, as yet. Maybe testing for (function (lambda ...))
> > would be safer.
> No matter how many extra tests you add to reduce the frequency, you're
> fundamentally adding a bug :-(
Yes. I'll see what I can do to remove that extra code from
backquote-process.
> Stefan
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2024-03-10 19:22 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-26 14:30 bug#67455: Record source position, etc., in doc strings, and use this in *Help* and backtraces Alan Mackenzie
2023-12-04 17:36 ` Alan Mackenzie
2023-12-04 18:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 21:32 ` Alan Mackenzie
2023-12-04 21:56 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-04 22:30 ` Alan Mackenzie
2023-12-04 22:59 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-15 18:23 ` Alan Mackenzie
2023-12-15 23:12 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
[not found] ` <handler.67455.B.170100905232659.ack@debbugs.gnu.org>
2024-03-04 15:38 ` bug#67455: (Record source position, etc., in doc strings, and use this in *Help* and backtraces.) Alan Mackenzie
2024-03-09 21:36 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-10 16:02 ` Alan Mackenzie
2024-03-10 17:19 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-10 19:22 ` Alan Mackenzie [this message]
2024-03-10 21:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-24 11:04 ` Alan Mackenzie
2024-03-25 18:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-25 21:03 ` Alan Mackenzie
2024-03-25 22:10 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-26 9:48 ` Alan Mackenzie
2024-03-26 13:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-26 16:55 ` Alan Mackenzie
2024-03-26 19:40 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-26 20:21 ` Alan Mackenzie
2024-03-26 20:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-27 3:35 ` Alan Mackenzie
2024-03-27 12:23 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-27 22:00 ` Alan Mackenzie
2024-03-26 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-26 21:13 ` Drew Adams
2024-03-27 10:04 ` Alan Mackenzie
2024-03-27 12:22 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-27 21:43 ` Alan Mackenzie
2024-03-28 16:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-28 16:48 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-30 9:10 ` Alan Mackenzie
2024-03-30 9:53 ` Alan Mackenzie
2024-03-31 2:22 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 11:35 ` Alan Mackenzie
2024-04-08 2:19 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 2:56 ` Alan Mackenzie
2024-04-10 8:53 ` Alan Mackenzie
2024-03-30 11:03 ` Alan Mackenzie
2024-03-31 2:54 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-07 10:57 ` Alan Mackenzie
2024-04-08 3:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-08 8:32 ` Alan Mackenzie
2024-04-08 12:00 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-02 13:38 ` Alan Mackenzie
2024-06-03 4:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-06-05 15:01 ` Alan Mackenzie
2024-03-10 22:27 ` Alan Mackenzie
2024-03-11 0:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-13 10:54 ` Alan Mackenzie
2024-03-13 11:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-19 16:18 ` Alan Mackenzie
2024-03-19 20:47 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-19 21:40 ` Alan Mackenzie
2024-03-19 22:32 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-24 11:21 ` Alan Mackenzie
2024-06-01 17:40 ` Alan Mackenzie
2024-06-01 18:01 ` Eli Zaretskii
2024-06-01 18:15 ` Eli Zaretskii
2024-06-01 18:17 ` Alan Mackenzie
2024-06-01 23:14 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ze4IXIrh-WbZaTSu@ACM \
--to=acm@muc.de \
--cc=67455@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).