Search code examples
pythonemacscommentsindentationpython-mode

Emacs python-mode.el comments start a new line


I am using python-mode.el in Emacs to edit some Python code and it has the most annoying feature where it auto-indents a comment and then starts a new line. For example, if I have this:

def x():
    y = 1
<cursor is here, at root indentation level>

And then add in one # at the root indentation level:

def x():
    y = 1
    #
<cursor is now here>

It automatically indents, inserts the #, and inserts a carriage return after the #. It's driving me crazy. I want my comments to stay exactly where I put them! Any suggestions?

I've looked through the elisp code for the mode and can't find anything yet nor can I find anything elsewhere online. All I can find is that comments won't be used for future indentation (py-honor-comment-indentation) but nothing related to the comment itself. Nor the strange carriage return.


Solution

  • filed a bug report at

    https://bugs.launchpad.net/python-mode/+bug/1092847

    M-x customize py-electric-comment-p RET

    setting it to `nil' should solve it.

    See also variable `py-indent-comments'