python怎么取消缩进_具有硬标签的Spacemacs中的Python缩进关闭

Let me preface by saying that I am a relatively new emacs/spacemacs convert from vim, so my my knowledge is still pretty basic.

I have spacemacs set up with the python layer, with the additional package of dtrt-indent listed in dotspacemacs-additional-packages. And setting

(dtrt-indent-mode t)

in the dotspacemacs/user-config. I need the dtrt-indent as I am working on a few projects (in python and lua) where I am not the one who sets the indentation rules.

This configuration works fine for python files with soft-tabs of varying length. This configuration also works for lua files that have hard tabs.

When I open a python file indented with hard tabs something seems to get messed up, it appears to think that the indentation is two hard tabs. Meaning, if I have code like this (pretend that the 4 spaces are tabs):

def func():|

print 'line'

and press enter, I get:

def func():

|

print 'line'

The status line prints dtrt-indent's message saying:

Note: indent-tabs-mode adjusted to t

Note: As stated I'm pretty new at this, and my spacemacs configuration is pretty sparse. There is nothing else in my user-config, I have not custom layers, I don't even have any additional packages other than dtrt-indent.

EDIT:

python-indent-offset is set to 8

indent-tabs-mode is set to t

tab-width is set to 4

解决方案

Try M-x whitespace-mode and repeat this experiment. What do you see? Did you indent with spaces or with tabs?

I'm guessing you'll see something like this:

def·func():

········

» print·'line'

This would mean you have python-indent-offset set to 8, indent-tabs-mode set to nil (aka indent with spaces), and tab-width set to 4.

If that's not the case, what are the values of those variables (C-h v python-indent-offset, etc.)?

If that is the case, you can fix the problem by running

(setq-default python-indent-offset 4)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值