indent-rigidly (associated with Cx TAB) does what you want. This is in indent.el, which should be part of the standard emacs distribution.
Also, so that it complains / interrupts when there is not enough space somewhere, you can do something like this: (quick ugly cracking of source code with indentation)
(defun enough-whitespace-to-indent-p (start end arg) (save-excursion (goto-char end) (setq end (point-marker)) (goto-char start) (or (bolp) (forward-line 1)) (while (and (< (point) end) (>= (+ (current-indentation) arg) 0)) (forward-line 1)) (>= (point) end))) (defun indent-rigidly-and-be-picky (start end arg) (interactive "r\np") (if (or (plusp arg) (enough-whitespace-to-indent-p start end arg)) (indent-rigidly start end arg) (message "Not enough whitespace to unindent!")))
source share