Set evil shift width to buffer-local indentation in emacs

I use the evil that 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 would like to set the evil shift width to the width of the local indent buffer ( indent variable).

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

What did I miss?

+8
emacs elisp evil-mode
source share
1 answer

Without further information, I believe the problem is that for evil-shift-width it is necessary to set the value of evil-shift-width to 4 in python-mode and 2 to ruby-mode (for two examples), but always set to 2 .

The problem in this case is that indent not defined globally in Emacs and, of course, not in python-mode . In python-mode there is a python-indent variable that is set to 4, and this is a variable that should be used.

While annoying is the need to use custom variables for each of the main modes, what each of the modes uses, and probably this is a solution that will really 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 that you want to support.

+17
source share

All Articles