emacs - 缩进制表符模式仍然使用空格

标签 emacs indentation

下面是我的 init.el 脚本。它正在加载,因为列指示器是可见的。然而,编辑任何 C 文件时,当我只需要制表符 (\t) 时,制表符键仍然会产生 4 个空格。我从未使用过 lisp,而且我是 emacs 新手,有什么问题吗?

(setq-default indent-tabs-mode t)
(require 'fill-column-indicator)


(defun my-c-mode-hook ()
  (setq-default c-default-style "bsd"
                c-basic-offset 4
                tab-width 4
                indent-tabs-mode t)

  (c-set-offset 'substatement-open 0)
  (fci-mode))

(add-hook 'c-mode-hook 'my-c-mode-hook)

最佳答案

试试这个:

(setq c-default-style "bsd")

(defun my-c-mode-hook ()
  (setq c-basic-offset 4
        tab-width 4
        indent-tabs-mode t)

  (c-set-offset 'substatement-open 0)
  (fci-mode))

(add-hook 'c-mode-hook 'my-c-mode-hook)

变量具有全局值,并且可能具有缓冲区本地值。

此外,当您设置某些变量时,它们将自动使用缓冲区本地值。这些变量包括c-basic-offsettab-widthindent-tabs-mode(如果你描述的话,你可以自己看到他们通过 C-hv)

setq-default 设置变量的全局值,但在 c-mode-hook 运行缓冲区本地时值已经建立,因此此时设置默认值并不是您真正想要的,因为它不会影响现有的本地值(尽管取决于模式的工作方式,这样做可能会导致 future 缓冲以获得所需的值)。

setq 设置缓冲区本地值(如果存在)(否则设置全局值),因此这就是您要对大多数变量使用的值。

相反,

c-default-style 不会自动本地缓冲区,因此使用 c-mode-hook 设置它应该没有任何意义。我们只需设置它的(全局)值一次。

关于emacs - 缩进制表符模式仍然使用空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43992346/

相关文章:

vim - 如何做一个 Go 项目工作区来使用依赖工具和 Go 工具?

emacs - Emacs : wrong-type-argument error in Emacs23 but not in Emacs24

angular - VS Code Auto Indent/Code Formatting 将单引号改为双引号

vim - 为这段代码寻找正确的cinoptions

c - 1TBS 用于长条件表达式

emacs如何将 "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK"绑定(bind)到击键

emacs - 如何在Emacs中逐步搜索全小写模式?

python - 如何缩进多行字符串的内容?

python - 你能帮我修复 python while 循环的错误吗

emacs - 如何在 emacs 中 grep 光标下的当前单词?