all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: Leo Liu <sdl.web@gmail.com>, 18643@debbugs.gnu.org
Subject: bug#18643: 25.0.50; elisp--expect-function-p
Date: Fri, 10 Oct 2014 09:20:13 -0400	[thread overview]
Message-ID: <jwv4mvc9j20.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <543753AC.3090604@yandex.ru> (Dmitry Gutov's message of "Fri, 10 Oct 2014 07:34:04 +0400")

> 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	other threads:[~2014-10-10 13:20 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-06  5:13 bug#18643: 25.0.50; elisp--expect-function-p Leo Liu
2014-10-09  2:50 ` Dmitry Gutov
2014-10-09  3:31   ` Leo Liu
2014-10-09  6:17     ` Dmitry Gutov
2014-10-09 15:27     ` Stefan Monnier
2014-10-09 23:43       ` Leo Liu
2014-10-10  1:16         ` Stefan Monnier
2014-10-10  4:07           ` Leo Liu
2014-10-10 13:25             ` Stefan Monnier
2014-10-10 20:53               ` Dmitry Gutov
2014-10-11  0:25                 ` Leo Liu
2014-10-11 13:48                   ` Stefan Monnier
2014-10-11 14:21                     ` Leo Liu
2014-10-14 18:32                       ` Stefan Monnier
2014-10-16  2:42                         ` Dmitry Gutov
2014-10-16 13:10                           ` Stefan Monnier
2014-10-11 13:47                 ` Stefan Monnier
2014-10-11 16:18                   ` Dmitry Gutov
2014-10-14 18:34                     ` Stefan Monnier
2014-10-16  2:35                       ` Dmitry Gutov
2014-10-16  3:36                         ` Leo Liu
2014-10-16  9:59                           ` Dmitry Gutov
2014-10-11  0:16               ` Leo Liu
2014-10-10  3:56         ` Dmitry Gutov
2014-10-10  4:33           ` Leo Liu
2014-10-11 16:31             ` Dmitry Gutov
2014-10-10  3:34       ` Dmitry Gutov
2014-10-10 13:20         ` Stefan Monnier [this message]
2014-10-11 17:07           ` Dmitry Gutov
2022-04-26 13:44 ` Lars Ingebrigtsen
2022-04-26 15:46   ` Leo Liu
2022-04-27 11:52     ` Lars Ingebrigtsen

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=jwv4mvc9j20.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=18643@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=sdl.web@gmail.com \
    /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.