开发者

Emacs 23 built-in python.el indentation broken using tabs with width 4

I've been using the version of python.el found here for a couple of years in Emacs 23 without incident. I decided to try the stock python.el, and ran into a开发者_如何转开发 strange issue:

When using tabs for indentation and a tab width of 4, the stock python.el will indent two tab characters for every level instead of 1. With a tab width of 5, the indentation will be 1 tab plus 3 spaces. So, when indent-tabs-mode is t, indent-for-tab-command seems to always force a tab size of 8, regardless of what tab-width is set to.

Is there some other tab-related variable I can set to override this behavior?


I think I've figured this out after digging through the source code for the stock Emacs 23 python.el and the newest python.el on the block.

Given these settings in a python-mode buffer, indentation with tabs and a tab-width of 4 works as expected in stock python.el:

(setq indent-tabs-mode t
      tab-width 4
      python-indent 4)

For the new python.el, you need to change python-indent to python-indent-offset. I'm using both settings for both modes without issue.

If someone has a better solution to this problem, please add it and I'll gladly accept it as the correct answer.


stuck using tabs? check

trying out emacs 23 with python.el? check

I've run into the same wall as you recently... what I've learned is that I truly hate tabs and that I find python's whitespace significance incredibly annoying.

Are you setting tab-width in your init or with customize?

I had to make sure to change tab-width in the "Editing Basics" section via customize to get "4 space" tabs to stick (something to do with global/local scope). But the fun doesn't end there... python.el seems to only want to indent to the first tab-stop (column 4 now) and no further no matter what I set indent-tab-mode or tab-always-indent to. I finally gave up and went back to using python-mode.el, which has it's own set of idiosyncrasies, but at least python code is indenting "correctly".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜