Function: rst-shift-region
rst-shift-region is an interactive and byte-compiled function defined
in rst.el.gz.
Signature
(rst-shift-region BEG END CNT)
Documentation
Shift region BEG to END by CNT tabs.
Shift by one tab to the right (CNT > 0) or left (CNT < 0) or
remove all indentation (CNT = 0). A tab is taken from the text
above. If no suitable tab is found rst-indent-width is used.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-shift-region (beg end cnt)
"Shift region BEG to END by CNT tabs.
Shift by one tab to the right (CNT > 0) or left (CNT < 0) or
remove all indentation (CNT = 0). A tab is taken from the text
above. If no suitable tab is found `rst-indent-width' is used."
(interactive "r\np")
(let ((tabs (sort (rst-compute-tabs beg)
(lambda (x y)
(<= x y))))
(leftmostcol (rst-find-leftmost-column beg end)))
(when (or (> leftmostcol 0) (> cnt 0))
;; Apply the indent.
(indent-rigidly
beg end
(if (zerop cnt)
(- leftmostcol)
;; Find the next tab after the leftmost column.
(let* ((cmp (if (> cnt 0) #'> #'<))
(tabs (if (> cnt 0) tabs (reverse tabs)))
(len (length tabs))
(dir (cl-signum cnt)) ; Direction to take.
(abs (abs cnt)) ; Absolute number of steps to take.
;; Get the position of the first tab beyond leftmostcol.
(fnd (cl-position-if (lambda (elt)
(funcall cmp elt leftmostcol))
tabs))
;; Virtual position of tab.
(pos (+ (or fnd len) (1- abs)))
(tab (if (< pos len)
;; Tab exists - use it.
(nth pos tabs)
;; Column needs to be computed.
(let ((col (+ (or (car (last tabs)) leftmostcol)
;; Base on last known column.
(* (- pos (1- len)) ; Distance left.
dir ; Direction to take.
rst-indent-width))))
(if (< col 0) 0 col)))))
(- tab leftmostcol)))))))