Say I have an existing, simple block of code that uses an indent width of 4, as such
def incDictValue(d, k):
if not k in d:
d[k] = 1
else:
d[k] += 1
return
and setup python-mode in my init.el file to use a 2 space indent offset, like such
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode nil)
(setq tab-width 2)
(setq python-indent-guess-indent-offset nil)
(setq py-indent-offset 2)))
If I place the cursor on any line and hit TAB, the existing code is properly indented to match the indent offset of 2.
However, if I highlight the entire code block and M-x indent-region
, only the second level indents are adjusted to 2. The first level indents (the 'if', 'else', and 'return' statements) are kept at 4.
def incDictValue(d, k):
if not k in d:
d[k] = 1
else:
d[k] += 1
return
Why is this? This clearly isn't the desired result that one would want when applying indent-region. I would like indent-region to apply the indent settings of python-mode to the entire block of code, to all levels of indentation (much as if I hit TAB on each line sequentially)