Frage

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.

War es hilfreich?

Lösung

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'

Andere Tipps

Ok, found it.

The offending function is py-electric-comment.

By default this is enabled to be called after inserting a #. You can disable this by setting py-electric-comment-p to nil.

You can also edit py-electric-comment by editing this part of the function:

    (let ((orig (copy-marker (point)))
                (indent (py-compute-indentation)))
      (unless (eq (current-indentation) indent)
            (goto-char orig)  ;;; REMOVE THIS LINE
              (beginning-of-line)
              (delete-horizontal-space)

This will let you keep py-electric-comment enabled but not attempt to go back to the original indentation level, fixing the original problem.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top