Set python indent to 2 spaces in emacs 23?

前端 未结 3 834
名媛妹妹
名媛妹妹 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:31

    Either in you .emacs file or in a file referenced by your .emacs add:

    (setq-default indent-tabs-mode nil)
    (setq-default tab-width 2)
    

    You can put in a hook if you want to localize

    ;; Python Hook
    (add-hook 'python-mode-hook
              (function (lambda ()
                          (setq indent-tabs-mode nil
                                tab-width 2))))
    

    EDIT: I have found the following the following issues can mess with my settings:

    • setting the variable before the library is loaded
    • other packages/configs resetting the global variables

    For both those issues I have found creating hooks and localizing the variables can help.

提交回复
热议问题