set the evil shift width to the buffer-local indentation in emacs
Question
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?
Solution
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.