开发者

Editing Python in Emacs

I've looked at python-mode and python.el. I'm using python-mode.el. I'm also using rope and ropemacs. I'm looking either for some documentation on these that helps me, or another elisp package or something.

My current problem is that the code I'm given has inconsistent indentation sizes. For some blocks it will be two, for some it will be 4. I want to clean this up, but For some reason, when I tell emacs "fix indentation" it just hits tab on every line basically, which screws up the code. What I want is to keep the same relative indentation, but standardize on 4 spaces. Will anything let me do this easily?

I suppose I could find each instance of bad indentation, block it, and query-replace开发者_如何学Go 2 spaces with 4 spaces. But that relies a bit too much on my precision, noticing where this should be done. Also, it's a lot of code.

Someone told me that bicycle repairman would solve this, but that's been out of developement for several years now... Any other suggestions?

thanks.


Assuming you've used Sven Marnach's comment to clean up the code base, I'm guessing you just need to make python-mode.el use the indentation style that you prefer?

Look at the variables py-indent-offset, and py-smart-indentation (and perhaps also py-continuation-offset and py-honor-comment-indentation). As well as the normal indent-tabs-mode.

You can either Customize them (M-x customize-group RET python RET), or add a custom function to python-mode-hook. e.g.:

(add-hook 'python-mode-hook 'my-python-mode-hook)
(defun my-python-mode-hook ()
  (setq indent-tabs-mode nil
        py-smart-indentation nil
        py-indent-offset 4))


with py-smart-indentation set to `t'

current python-mode.el should do it.

http://launchpad.net/python-mode

In case of a bug, please report there


(custom-set-variables
   ...
   '(indent-tabs-mode nil)
   '(tab-stop-list (quote (4 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120)))
   '(tab-width 4))

Obviously these are global settings for modes that honor them (which python-mode does). I didn't fudge around with python-mode's indentation settings at all.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜