+ (move-marker end nil)
+ ;; Keep the active region in transient mode.
+ (when (eq (cadr overriding-terminal-local-map) indent-rigidly-map)
+ (setq deactivate-mark nil)))))
+
+(defun indent-rigidly--pop-undo ()
+ (and (memq last-command '(indent-rigidly-left indent-rigidly-right
+ indent-rigidly-left-to-tab-stop
+ indent-rigidly-right-to-tab-stop))
+ (consp buffer-undo-list)
+ (eq (car buffer-undo-list) nil)
+ (pop buffer-undo-list)))
+
+(defun indent-rigidly-left (beg end)
+ "Indent all lines between BEG and END leftward by one space."
+ (interactive "r")
+ (indent-rigidly--pop-undo)
+ (indent-rigidly
+ beg end
+ (if (eq (current-bidi-paragraph-direction) 'right-to-left) 1 -1)))
+
+(defun indent-rigidly-right (beg end)
+ "Indent all lines between BEG and END rightward by one space."
+ (interactive "r")
+ (indent-rigidly--pop-undo)
+ (indent-rigidly
+ beg end
+ (if (eq (current-bidi-paragraph-direction) 'right-to-left) -1 1)))
+
+(defun indent-rigidly-left-to-tab-stop (beg end)
+ "Indent all lines between BEG and END leftward to a tab stop."
+ (interactive "r")
+ (indent-rigidly--pop-undo)
+ (let* ((current (indent-rigidly--current-indentation beg end))
+ (rtl (eq (current-bidi-paragraph-direction) 'right-to-left))
+ (next (indent-next-tab-stop current (if rtl nil 'prev))))
+ (indent-rigidly beg end (- next current))))
+
+(defun indent-rigidly-right-to-tab-stop (beg end)
+ "Indent all lines between BEG and END rightward to a tab stop."
+ (interactive "r")
+ (indent-rigidly--pop-undo)
+ (let* ((current (indent-rigidly--current-indentation beg end))
+ (rtl (eq (current-bidi-paragraph-direction) 'right-to-left))
+ (next (indent-next-tab-stop current (if rtl 'prev))))
+ (indent-rigidly beg end (- next current))))