help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Indentation in python.el after "Enter"


From: Ruslan Spivak
Subject: Re: Indentation in python.el after "Enter"
Date: Wed, 11 Jul 2007 11:46:04 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

"Alexander Tsamutali" <astsmtl@gmail.com> writes:

> Hi, all!
>
> I am novice emacs user and i'm using emacs to write python programs. I
> used python-mode.el from http://python-mode.sourceforge.net and was
> quite happy. A few days ago i updated emacs to 22.1 and read that the
> default python.el mode is updated and recommended for use.
> I removed python-mode.el and yes, python.el works good. The only thing
> i miss form the old python-mode.el is that when i hit "Enter" on the
> line which is indented by itself or opens the new block, emacs
> maintains/creates indentation on the new line, so i don't need to hit
> "Tab". For ex.:
>
> def foo():
>    a = 1 # hit "Enter"
>    b = 2 # this line was already indented
>
> if a == b: # hit "Enter"
>    # cursor jumps here because i opened the block
>
> When using python.el cursor always jumps to the first column and i
> need to hit "Tab" to indent new line properly.
>
> Can someone help me to make my emacs smarter in this area? :)
>
> -- 
> Alexander Tsamutali

Hi, Alexander

You can use something like this in your dot emacs file:

(defun my-python-hook ()
  (define-key python-mode-map "\C-m" 'newline-and-indent))

(add-hook 'python-mode-hook 'my-python-hook)

or a bit shorter version

(add-hook 'python-mode-hook
          '(lambda ()
              (define-key python-mode-map "\C-m" 'newline-and-indent)))

Regards,
Ruslan

-- 
Computers are useless.  They can only give you answers.
  - Pablo Picasso





reply via email to

[Prev in Thread] Current Thread [Next in Thread]