Set python indent to 2 spaces in emacs 23?

前端 未结 3 835
名媛妹妹
名媛妹妹 2021-02-05 07:12

I am using emacs 23.1.1 on Ubuntu 10.04. I wish to program in Python with a 2-space indent. emacs looks to have a default mode for python (python.el?).

I put the follow

3条回答
  •  别那么骄傲
    2021-02-05 07:36

    You can put this into your .emacs file:

    (add-hook 'python-mode-hook '(lambda () 
     (setq python-indent 2)))
    

    The reason why

        (setq-default python-indent 2)
    

    does not work may because this variable does not exit when .emacs is loaded. (But I am an emacs newbie. I am not sure about my explanation.)

    However, PEP 8 -- Style Guide for Python Code recommends "4 spaces per indentation level" and I find 4 spaces more readable. I actually use this piece of code to force a 4 spaces indentation.

提交回复
热议问题