GNU bug report logs - #3238
python mode comments should define indentation level

Previous Next

Package: emacs;

Reported by: akkana <at> shallowsky.com (Akkana Peck)

Date: Thu, 7 May 2009 17:25:06 UTC

Severity: normal

Done: Fabián Ezequiel Gallina <fabian <at> anue.biz>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: akkana <at> shallowsky.com (Akkana Peck)
To: bug-gnu-emacs <at> gnu.org
Subject: python mode comments should define indentation level
Date: Thu,  7 May 2009 10:20:01 -0700 (PDT)
In python mode (python.el), I'm having a lot of trouble adding comments
because newline-and-indent always re-indents to the level of the last
code line, ignoring comment lines.

For instance, if I have this code:

    for item in items :
        for c in chars :
            do_stuff()
            # hitting return after do_stuff() will indent 12 spaces

    # But I want to start a comment block with a 4-space indent.
    # Here is the start of a comment describing what the next code block does.
    # Each of these lines is indented 12 spaces, not 4.

When I hit return after the do_stuff() line, I'm indented 12 spaces,
which is reasonable given the context. I backspace 8 chars to where I
actually want to be. If I now type a code line, like i = 10, and hit
return, the next line will be indented 4 spaces. But if I type a comment
line like the one shown in my example, the next line will be indented
12 spaces, not 4. So it's difficult to add comments for functions or
blocks of code, because you have to correct the indentation with
every line you type.

newline-and-indent in python mode should do the same thing from comment
lines as it does from code lines: use the indentation of the current line.


In GNU Emacs 22.2.1 (i486-pc-linux-gnu, GTK+ Version 2.14.1)
 of 2008-09-05 on vernadsky, modified by Ubuntu
Windowing system distributor `The X.Org Foundation', version 11.0.10502000
configured using `configure  '--build=i486-linux-gnu' '--host=i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs22:/etc/emacs:/usr/local/share/emacs/22.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/22.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/22.2/leim' '--with-x=yes' '--with-x-toolkit=gtk' 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g -Wl,--as-needed' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: C
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8
  default-enable-multibyte-characters: t

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  unify-8859-on-encoding-mode: t
  utf-translate-cjk-mode: t
  line-number-mode: t
  transient-mark-mode: identity

Recent input:
C-b C-b C-w C-x C-s <help-echo> C-u C-v C-u C-v C-n 
C-n C-n C-n C-n C-a C-k C-k C-p C-p C-y C-p <tab> C-n 
C-a C-k C-k C-x C-f <tab> <tab> C-g C-x C-f s h a <tab> 
<return> C-s d e l e t e C-n C-x b <return> <return> 
C-h C-h C-h C-h g i m p . d e l e t e ( n e w i m g 
) C-x C-s C-p <return> C-h C-h C-h C-h # SPC I f SPC 
t h e SPC s a v e SPC w a s SPC s u c c e s s f u l 
, SPC w e SPC d o n ' t SPC n e e d SPC t o SPC s h 
o w SPC t h e SPC n e w SPC i m a g e , <return> C-h 
C-h C-h C-h # SPC s o SPC d e l e t e SPC i t : C-x 
C-s C-n C-n C-a <return> C-x C-s C-x b <return> C-x 
k <return> C-x b <return> <next> <next> <down-mouse-1> 
<mouse-1> C-h . <return> C-h C-h C-h C-h # SPC C-x 
C-f C-w C-h / . e m a c s <return> C-x b <return> C-x 
C-s X X X C-x C-s C-h C-h C-h C-x C-s C-x b <return> 
C-s p y t h o n C-s C-s C-s C-s C-a C-x b <return> 
C-h C-h C-h SPC a s d f SPC a s d f SPC a s d f a s 
SPC d f a s d SPC f a s d SPC f a s d SPC f a s d f 
M-q M-x r e p o t C-h r t - e m <tab> <return>

Recent messages:
Making completion list...
Quit
Mark saved where search started
Wrote /home/akkana/.gimp-2.6/plug-ins/wallpaper.py [3 times]
Wrote /home/akkana/bin/pytopo [3 times]
Mark saved where search started
Loading newcomment...done
Loading emacsbug...
Loading regexp-opt...done
Loading emacsbug...done





This bug report was last modified 12 years and 229 days ago.

Previous Next


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