在文本模式下在 Emacs 中设置 4 个空格缩进 [英] Set 4 Space Indent in Emacs in Text Mode

查看:38
本文介绍了在文本模式下在 Emacs 中设置 4 个空格缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在主要模式 text-mode 的缓冲区中按下 TAB 时,我未能让 Emacs 从 8 个空格选项卡切换到 4 个空格选项卡.我在 .emacs 中添加了以下内容:

I've been unsuccessful in getting Emacs to switch from 8 space tabs to 4 space tabs when pressing the TAB in buffers with the major mode text-mode. I've added the following to my .emacs:

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

;;; And I have tried
(setq indent-tabs-mode nil)
(setq tab-width 4)

无论我如何更改我的 .emacs 文件(或我的缓冲区的局部变量),TAB 按钮总是做同样的事情.

No matter how I change my .emacs file (or my buffer's local variables) the TAB button always does the same thing.

  1. 如果上面没有文字,缩进8个空格
  2. 如果上一行有文字,缩进到第二个单词的开头

尽管我很喜欢 Emacs,但它越来越烦人.当上一行没有文本时,有没有办法让 Emacs 至少缩进 4 个空格?

As much as I love Emacs this is getting annoying. Is there a way to make Emacs to at least indent 4 space when there's not text in the previous line?

推荐答案

不要将变量 tab-width 与变量 tab-stop-list 混淆.前者用于显示文字 TAB 字符.后者控制在某些模式下按 TAB 字符时插入的字符.

Do not confuse variable tab-width with variable tab-stop-list. The former is used for the display of literal TAB characters. The latter controls what characters are inserted when you press the TAB character in certain modes.

-- GNU Emacs 手册

(customize-variable (quote tab-stop-list))

或在 .emacs 文件中的 custom-set-variables 中添加 tab-stop-list 条目:

or add tab-stop-list entry to custom-set-variables in .emacs file:

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(tab-stop-list (quote (4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80 84 88 92 96 100 104 108 112 116 120))))

另一种编辑标签行为的方法是使用 M-x edit-tab-stops.

Another way to edit the tab behavior is with with M-x edit-tab-stops.

请参阅 关于制表位的 GNU Emacs 手册 有关 edit-tab-stops 的更多信息.

See the GNU Emacs Manual on Tab Stops for more information on edit-tab-stops.

这篇关于在文本模式下在 Emacs 中设置 4 个空格缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆