Commit 826255ba authored by Barry Warsaw's avatar Barry Warsaw

(py-indent-right, py-indent-left): support indentation of regions or

current line.
parent 71ac9453
...@@ -434,6 +434,13 @@ py-beep-if-tab-change\tring the bell if tab-width is changed" ...@@ -434,6 +434,13 @@ py-beep-if-tab-change\tring the bell if tab-width is changed"
(run-hooks 'py-mode-hook))) (run-hooks 'py-mode-hook)))
(defun py-keep-region-active ()
;; Do whatever is necessary to keep the region active in
;; XEmacs 19. This is unnecessary, but no-op in Emacs 19, so just
;; ignore byte-compiler warnings you might see.
(and (boundp 'zmacs-region-stays)
(setq zmacs-region-stays t)))
;; electric characters ;; electric characters
(defun py-outdent-p () (defun py-outdent-p ()
;; returns non-nil if the current line should outdent one level ;; returns non-nil if the current line should outdent one level
...@@ -485,43 +492,71 @@ Electric behavior is inhibited inside a string or comment." ...@@ -485,43 +492,71 @@ Electric behavior is inhibited inside a string or comment."
(indent-to (- indent outdent)) (indent-to (- indent outdent))
))))) )))))
(defun py-indent-right (arg) (defun py-indent-right (start end arg)
"Indent the line by one `py-indent-offset' level. "Indent lines in the region by one `py-indent-offset' level.
With numeric arg, indent by that many levels. You cannot indent With numeric arg, indent by that many levels. You cannot indent
farther right than the distance the line would be indented by farther right than the distance the line would be indented by
\\[py-indent-line]." \\[py-indent-line]. With no active region, indent only the
(interactive "p") current line."
(let ((col (current-indentation)) (interactive
(want (* arg py-indent-offset)) (let ((p (point))
(indent (py-compute-indentation)) (m (mark)))
(pos (- (point-max) (point))) (list (min p m) (max p m) (prefix-numeric-value current-prefix-arg))))
(bol (save-excursion (beginning-of-line) (point)))) (let ((pos (- (point-max) (point)))
(if (<= (+ col want) indent) (end (save-excursion
(progn (goto-char (or end (1+ start)))
(beginning-of-line) (and (not (bolp))
(delete-horizontal-space) (forward-line 1))
(indent-to (+ col want)) (set-marker (make-marker) (point))))
(if (> (- (point-max) pos) (point)) col want indent)
(goto-char (- (point-max) pos))) (goto-char start)
)))) (beginning-of-line)
(unwind-protect
(defun py-outdent-left (arg) (while (< (point) end)
"Outdent the line by one `py-indent-offset' level. (setq col (current-indentation)
want (* arg py-indent-offset)
indent (py-compute-indentation))
(if (<= (+ col want) indent)
(progn
(beginning-of-line)
(delete-horizontal-space)
(indent-to (+ col want))))
(forward-line 1))
(set-marker end nil))
(goto-char (- (point-max) pos))
(py-keep-region-active)))
(defun py-outdent-left (start end arg)
"Outdent lines in the region by one `py-indent-offset' level.
With numeric arg, outdent by that many levels. You cannot outdent With numeric arg, outdent by that many levels. You cannot outdent
farther left than column zero." farther left than column zero. With no active region, outdent only
(interactive "p") the current line."
(let ((col (current-indentation)) (interactive
(want (* arg py-indent-offset)) (let ((p (point))
(pos (- (point-max) (point))) (m (mark)))
(bol (save-excursion (beginning-of-line) (point)))) (list (min p m) (max p m) (prefix-numeric-value current-prefix-arg))))
(if (<= 0 (- col want)) (let ((pos (- (point-max) (point)))
(progn (end (save-excursion
(beginning-of-line) (goto-char (or end (1+ start)))
(delete-horizontal-space) (and (not (bolp))
(indent-to (- col want)) (forward-line 1))
(if (> (- (point-max) pos) (point)) (set-marker (make-marker) (point))))
(goto-char (- (point-max) pos))) col want)
)))) (goto-char start)
(beginning-of-line)
(unwind-protect
(while (< (point) end)
(setq col (current-indentation)
want (* arg py-indent-offset))
(if (<= 0 (- col want))
(progn
(beginning-of-line)
(delete-horizontal-space)
(indent-to (- col want))))
(forward-line 1))
(set-marker end nil))
(goto-char (- (point-max) pos))
(py-keep-region-active)))
;;; Functions that execute Python commands in a subprocess ;;; Functions that execute Python commands in a subprocess
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment