I\'m looking for a way in emacs to shift text to the right or to the left by n
spaces. A similar functionality that it in vim <<
or >>
To achieve this I usually do a trick:
This can be done also programmatically in some way (in the same way).
EDIT: I've just read the article in emacs wiki, it's the same solution except for the CUA mode that is infinitely more powerful than the "common" rectanguar selection (since it's visual).
You could select the region then C-u C-x <tab>
will shift 4 spaces. You can type a number after C-u to change 4 to anything else.
Maybe this works the way you want.
(defun shift-text (distance) (if (use-region-p) (let ((mark (mark))) (save-excursion (indent-rigidly (region-beginning) (region-end) distance) (push-mark mark t t) (setq deactivate-mark nil))) (indent-rigidly (line-beginning-position) (line-end-position) distance))) (defun shift-right (count) (interactive "p") (shift-text count)) (defun shift-left (count) (interactive "p") (shift-text (- count)))