[英]Python indentation in Spacemacs with hard tabs is off
Let me preface by saying that I am a relatively new emacs/spacemacs convert from vim, so my my knowledge is still pretty basic. 首先,让我说我是从vim转换而来的emacs / spacemacs相对较新,因此我的知识仍然很基础。
I have spacemacs set up with the python layer, with the additional package of dtrt-indent listed in dotspacemacs-additional-packages. 我在python层设置了spacemacs,并在dotspacemacs-additional-packages中列出了dtrt-indent的其他软件包。 And setting
和设置
(dtrt-indent-mode t)
in the dotspacemacs/user-config. 在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.
我需要dtrt-indent,因为我正在处理一些项目(在python和lua中),但我不是设置缩进规则的人。
This configuration works fine for python files with soft-tabs of varying length. 此配置适用于带有不同长度软标签的python文件。 This configuration also works for lua files that have hard tabs.
此配置也适用于具有硬标签的lua文件。
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. 当我打开带有硬标签的缩进的python文件时,似乎有些混乱,似乎认为缩进是两个硬标签。 Meaning, if I have code like this (pretend that the 4 spaces are tabs):
意思是,如果我有这样的代码(假设4个空格是制表符):
def func():| <--- Cursor
print 'line'
and press enter, I get: 然后按Enter,我得到:
def func():
| <--- Cursor
print 'line'
The status line prints dtrt-indent's message saying: 状态行显示dtrt-indent的消息,内容为:
Note: indent-tabs-mode adjusted to t
Note: As stated I'm pretty new at this, and my spacemacs configuration is pretty sparse. 注意:如前所述,我在这方面还很陌生,而我的spacemacs配置非常稀疏。 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.
我的用户配置中没有其他内容,没有自定义层,除了dtrt-indent之外,我什至没有任何其他软件包。
EDIT: 编辑:
python-indent-offset is set to 8 python-indent-offset设置为8
indent-tabs-mode is set to t indent-tabs-mode设置为t
tab-width is set to 4 制表符宽度设置为4
Try Mx whitespace-mode
and repeat this experiment. 尝试使用
Mx whitespace-mode
并重复此实验。 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. 这意味着您将
python-indent-offset
设置为8,将indent-tabs-mode
设置为nil(又称带空格的缩进),并将tab-width
设置为4。
If that's not the case, what are the values of those variables ( Ch v python-indent-offset
, etc.)? 如果不是这种情况,那么这些变量的值是什么(
Ch v python-indent-offset
等)?
If that is the case, you can fix the problem by running 如果是这样,您可以通过运行来解决问题
(setq-default python-indent-offset 4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.