Emacs - 如何自动化python代码的格式?

时间:2017-05-01 18:46:29

标签: python-2.7 emacs formatting

假设代码粘贴在emacs中,如下所示

# x = 'global x'                                                                                                                                                                                           

def test(z):                                                                                                                                                                                               
    global x # variable from global namespace                                                                                                                                                              
    x = 'local x'                                                                                                                                                                                          
    # x = 'local x'                                                                                                                                                                                        
    # print(y)                                                                                                                                                                                             

                   print(x)                                                                                                                                                                                
                      print(z)                                                                                                                                                                             


                      # test('local z')                                                                                                                                                                    
                      # print(x)                                                                                                                                                                           

                      def outer():                                                                                                                                                                         

                             x = 'outer x'                                                                                                                                                                 

                                def inner():                                                                                                                                                               
                                          nonlocal x # local variables of enclosing function                                                                                                               
                                                x = 'inner x'                                                                                                                                              
                                                      print(x)                                                                                                                                             

                                                         inner()                                                                                                                                           
                                                            print(x)                                                                                                                                       

.emacs文件包含以下内容

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-enabled-themes (quote (deeper-blue))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

问题:

根据python缩进规则,自动格式化python代码的最佳方法是什么?

0 个答案:

没有答案
相关问题