GNU bug report logs - #18796
24.4; python indent-for-tab-command fails to recognize if-elif-else

Previous Next

Package: emacs;

Reported by: Carlos Pita <carlosjosepita <at> gmail.com>

Date: Wed, 22 Oct 2014 16:37:02 UTC

Severity: normal

Tags: patch

Merged with 18843

Found in versions 24.4, 24.4.50

Done: fgallina <at> gnu.org (Fabián Ezequiel Gallina)

Bug is archived. No further changes may be made.

Full log


Message #14 received at 18796 <at> debbugs.gnu.org (full text, mbox):

From: Carlos Pita <carlosjosepita <at> gmail.com>
To: 18796 <at> debbugs.gnu.org
Cc: fabian <at> anue.biz
Subject: Re:
Date: Wed, 22 Oct 2014 15:20:23 -0300
This fix seems to work:

In python-indent-region replace:

                (delete-horizontal-space)
                (indent-to (python-indent-calculate-indentation)))))

for

            (let ((indentation (python-indent-calculate-indentation)))
                  (delete-horizontal-space)
                  (indent-to indentation)))))

So the new indentation is calculated on the basis of the original one
(that is, before removing horizontal space).

On Wed, Oct 22, 2014 at 3:11 PM, Carlos Pita <carlosjosepita <at> gmail.com> wrote:
> I've doing some debugging. I found out why the bug happens, but I
> still have to think of a way to fix it:
>
> Say you are in a dedenter line like "else:". In python-indent-region
> delete-horizontal-space gets executed, so the dedenter "else:" moves
> to the first column and the current indentation becomes 0. Now
> python-info-dedenter-opening-block-position initializes indentation as
> the value returned by (current-indentation), that is 0. Then the
> opening block position is calculated and the following code gets
> executed:
>
>         (if (<= (current-indentation) indentation)
>             (setq position (car positions))
>           (setq positions (cdr positions)))))
>
> In this code (current-indentation) returns the indentation of the
> opening block, which is fine. But it gets compared to indentation,
> which is always 0. So the else branch is taken every time and
> positions is set to nil (cdr positions).
>
> Obviously the problem is that at the point
> python-info-dedenter-opening-block-position is called the original
> dedenter indentation was lost.
>
> Maybe the original indentation should be saved as a dynamic variable
> before deleting the horizontal space. Or the horizontal space
> shouldn't be deleted at all and indentation should happen as a
> displacement from the original position instead of a displacement from
> the left margin.




This bug report was last modified 10 years and 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.