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

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

bug#18643: 25.0.50; elisp--expect-function-p


From: Stefan Monnier
Subject: bug#18643: 25.0.50; elisp--expect-function-p
Date: Fri, 10 Oct 2014 09:20:13 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> I'm glad that you think this approach will work. Sounds like then the code
> will just have to handle a fixed number of forms, which is solvable.

I'm not sure it will, but experience seems to indicate that it works
well for local variables, so there's hope.

> Now I just have to wrap my head around `elisp--local-variables'. :)

It's very simple:

It takes the string between the first opening paren and point, appends
a special symbol (the witness) followed by the number of missing closing
parens to make the whole string a valid sexp, than reads&macroexpands
that.  And then we traverse the expanded code (a tree) straight from the
root to the leaf corresponding to point (which is done in
elisp--local-variables-1), collecting various info along the way.

Of course, traversing the tree efficiently is hard/impossible because
we don't know for sure where is the witness (which represents point) in
the tree, so we'd have to go through all the nodes of the tree, whereas
we want to limit ourselves to going down from the root straight to the
right leaf without backtracking.

Luckily, we know that point started "at the very end" of the sexp, and
macroexpansion tends to preserve the order, so if we always follow "the
rightmost child", we often find the witness.

Of course, it doesn't always work: e.g. if we start from (with-foo
witness), we'll generally end up with a macro-expanded code of the form
(unwind-protect (progn (something) witness) (somethingelse)) and going
down the rightmost child won't find the witness.

Maybe we could/should do a full backtracking traversal of the whole tree
instead, so it works more often.  After all, we use macroexpand-all
already, so we do perform such a traversal elsewhere anyway (and we
don't really have to: we could perform the macroexpansion only along the
spine we descend).


        Stefan





reply via email to

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