From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Ivan Andrus <darthandrus@gmail.com>
Cc: 11974@debbugs.gnu.org
Subject: bug#11974: 24.1.50; python-nav-forward-sexp-function doesn't skip over strings
Date: Thu, 19 Jul 2012 03:52:02 -0400 [thread overview]
Message-ID: <jwvliigw6e3.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <C1E7CE7B-0F74-4BB0-BCD8-178A316D5071@gmail.com> (Ivan Andrus's message of "Wed, 18 Jul 2012 14:29:39 +0200")
> (let* ((bos (python-info-ppss-context 'string)))
> (goto-char bos)
> (forward-sexp 1)
> (narrow-to-region bos (point)))
> This is broken now since forward-sexp goes to the end of the block, far
> past the end of the string (or not moving at all). If you have any
> undindented code at the end of your buffer, then forward-sexp (and up-list)
> will refuse to move past it e.g.
There's a similar problem in SMIE's implementation of forward-sexp.
Basically, the issue is that there are several "sexp"s that start at
point and forward-sexp has to choose which one to skip over.
Every choice is valid, but since there's no way for the user to say
which choice she wants, any choice is bound to disappoint and/or
surprise the user sometimes.
That doesn't mean that it's a hopeless problem and that we shouldn't try
to improve the behavior, tho: in practice (maybe just for historical
reasons), I find that I generally prefer "the smallest sexp", especially
since I can repeat forward-sexp if it didn't skip enough.
I.e. Python's forward-sexp should only try to skip over
indentation-delimited blocks when it has a clear indication that only
skipping the current line/statement would be wrong, or that there's an
easy/intuitive way for the user to get the other behavior (e.g. by
starting the forward-sexp from elsewhere).
For example, with SMIE if I have
a + b * c
and I'm before "b", forward-sexp will only skip over "b", but if I move
to just before the "+", then forward-sexp will skip to after "c".
I'm not sure if Python's indentation-delimited blocks can find a similar
"convention" for the user to express her intention.
> What I would expect form a "perfect" python forward-sexp is to skip over
> a block if and only if you are at the very beginning of the block.
You mean that forward-sexp would generally skip over just a statement,
except if it's the first statement of a block in which case it skips the
whole block? That sounds a bit arbitrary, making it difficult for the
user to skip over just the first statement.
[ Bear in mind, I never write Python. ]
How 'bout
def foo():
toto
bar
if I'm before `toto' on the same line, forward-sexp should skip over
"toto", but if I'm right after the ":" (and before the \n) then
forward-sexp should skip to after "bar".
Stefan
next prev parent reply other threads:[~2012-07-19 7:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 12:29 bug#11974: 24.1.50; python-nav-forward-sexp-function doesn't skip over strings Ivan Andrus
2012-07-19 7:52 ` Stefan Monnier [this message]
2012-07-19 19:40 ` Ivan Andrus
[not found] ` <D3BE0B6C-F35A-4E54-A68C-FAB0F92E30D8@gmail.com>
2012-07-19 22:54 ` Stefan Monnier
2012-09-28 21:18 ` Ivan Andrus
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=jwvliigw6e3.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=11974@debbugs.gnu.org \
--cc=darthandrus@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 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).