将邪恶的移位宽度设置为 emacs 中的缓冲区本地缩进

发布于 2024-12-20 18:42:10 字数 421 浏览 3 评论 0原文

我使用邪恶,它让

(defcustom evil-shift-width 4
  "The offset used by \\<evil-normal-state-map>\\[evil-shift-right] \
and \\[evil-shift-left]."
  :type 'integer
  :group 'evil)

我想将邪恶移位宽度设置为缓冲区本地缩进宽度(变量indent)。

(add-hook 'after-change-major-mode-hook
      (function (lambda ()
                  (setq evil-shift-width indent))))

我错过了什么?

I use evil, which got

(defcustom evil-shift-width 4
  "The offset used by \\<evil-normal-state-map>\\[evil-shift-right] \
and \\[evil-shift-left]."
  :type 'integer
  :group 'evil)

I'd like to set evil-shift-width to the buffer-local indent width (the variable indent).

(add-hook 'after-change-major-mode-hook
      (function (lambda ()
                  (setq evil-shift-width indent))))

What did I miss?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩心不撩汉 2024-12-27 18:42:10

如果没有更多信息,我相信我理解问题是希望将 evil-shift-widthpython-mode 中设置为 4,在 中设置为 2 ruby-mode (举两个例子),但它始终设置为 2。

这种情况下的问题来自于 indent 在 Emacs 中没有全局定义,当然也没有定义在Python模式下。在python-mode中有一个变量python-indent,它被设置为4,这就是要使用的变量。

虽然必须为每种主要模式使用自定义变量很烦人,但这就是每种模式实际使用的变量,并且这可能是实际有效的解决方案:

(add-hook 'python-mode-hook
  (function (lambda ()
          (setq evil-shift-width python-indent))))
(add-hook 'ruby-mode-hook
  (function (lambda ()
          (setq evil-shift-width ruby-indent-level))))

为您想要支持的每种主要模式添加一个新变量。

Without more information, I believe I understand the problem to be that desire is for evil-shift-width to be set to 4 in python-mode and 2 in ruby-mode (for two examples), yet it is always set to 2.

The problem in this case comes from the fact that indent isn't defined globally in Emacs, and certainly not in python-mode. In python-mode there is a variable python-indent, which is set to 4, and that is the variable to use.

While annoying to have to use custom variables for each of the major modes, that's what each of the modes actually use, and that's probably the solution that will actually work:

(add-hook 'python-mode-hook
  (function (lambda ()
          (setq evil-shift-width python-indent))))
(add-hook 'ruby-mode-hook
  (function (lambda ()
          (setq evil-shift-width ruby-indent-level))))

Adding a new one for each major-mode you want supported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文