Emacs cc-mode的制表符行为

4

按下Tab键多次不会将文本向右移动。是否有一种方法使其像Visual Studio的智能缩进一样行为?第一个Tab键缩进,后续的Tab键将文本移至下一个制表符位置。谢谢。

2个回答

5

类似这样的吗?

(defun even-more-tabby-indent (&optional arg)
  "This indent function tries to be more like Microsoft's IDEs
than `C-INDENT-COMMAND' and does the following: If we're at the
beginning of the line or `C-TAB-ALWAYS-INDENT' is true or `ARG'
is non-nil, indent like a sensible text editor. Otherwise the
user probably WANTS MOAR TABS. So call `C-INSERT-TAB-FUNCTION'."
  (interactive "P")
  (if (or c-tab-always-indent (bolp) arg)
      (c-indent-command arg)
    (funcall c-insert-tab-function)))

您需要将选项卡插入绑定到类似以下内容的东西。
(defun setup-tabby-indent ()
  (local-set-key (kbd "<tab>") 'even-more-tabby-indent)
  (setq c-tab-always-indent nil))

(add-hook 'c-mode-hook 'setup-tabby-indent)

我很多年没用MS Visual Studio了,所以我不确定这是否完全符合你的要求,但希望修改方法非常清楚。


啊,就像Lazylabs所说的那样,也许你想使用(tab-to-tab-stop)而不是我建议的(funcall c-insert-tab-function)。 - Rupert Swarbrick

1

M-i(tab-to-tab-stop)将带您到下一个制表位。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接