all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
Cc: "Fabián E. Gallina" <fabian@anue.biz>, 17658@debbugs.gnu.org
Subject: bug#17658: Python mode has odd indentation behavior
Date: Mon, 02 Jun 2014 09:36:56 -0400	[thread overview]
Message-ID: <jwvy4xf78f4.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <538C1754.40903@easy-emacs.de> ("Andreas Röhler"'s message of "Mon, 02 Jun 2014 08:19:00 +0200")

>> Makes no difference,
> Did you try it?

I tried it in Emacs-24.3 which doesn't enable electric-indent-mode by
default, but suffers from the same problem.  Admittedly, In 24.4,
I half-fixed the problem by linking this python-mode feature to
electric-indent-mode, so that it can be turned off.

> The chars, which trigger an indent, may differ. In this case a comma
> triggers it.

Any char triggers it.  As I said:

   The important detail is not to hit "," but to insert a char right
   before the inner close paren.

The comma is not in electric-indent-chars.

Here's the offending code in python-indent-post-self-insert-function:

     ((and (not (bolp))
           (memq (char-after) '(?\) ?\] ?\})))
      (save-excursion
        (goto-char (line-beginning-position))
        ;; If after going to the beginning of line the point
        ;; is still inside a paren it's ok to do the trick
        (when (python-syntax-context 'paren)
          (let ((indentation (python-indent-calculate-indentation)))
            (when (< (current-indentation) indentation)
              (indent-line-to indentation))))))

This means that current line is reindented whenever you insert a char
right before a close-paren and line-beginning-position is inside some
parentheses.  Since reindenting a line is problematic in Python, it
should only be done when we really know for sure that the current indent
is wrong.  So clearly the above condition triggers too often.
But I don't understand the intention of the code, i.e. I don't
understand when the above is meant to trigger reindentation, so I don't
know how to fix it.  Presumably Fabián should be able to shed some
light here.



        Stefan





  reply	other threads:[~2014-06-02 13:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-01  1:49 bug#17658: Python mode has odd indentation behavior Adam Connor
2014-06-01  2:47 ` Stefan Monnier
2014-06-01 15:32   ` Andreas Röhler
2014-06-01 21:18     ` Stefan Monnier
2014-06-02  6:19       ` Andreas Röhler
2014-06-02 13:36         ` Stefan Monnier [this message]
2014-06-02 16:05           ` Andreas Röhler
2014-07-01  2:33 ` Fabián Ezequiel Gallina
2014-07-01  4:00 ` Fabián Ezequiel Gallina

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=jwvy4xf78f4.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=17658@debbugs.gnu.org \
    --cc=andreas.roehler@easy-emacs.de \
    --cc=fabian@anue.biz \
    /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.