]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
(py-indent-right, py-outdent-left): new commands, bound to C-c C-r and
authorBarry Warsaw <barry@python.org>
Wed, 15 Mar 1995 16:23:59 +0000 (16:23 +0000)
committerBarry Warsaw <barry@python.org>
Wed, 15 Mar 1995 16:23:59 +0000 (16:23 +0000)
C-c C-l respectively.

Misc/python-mode.el

index ec2b5cb321b835a3e75215658db858ef7e2cf550..be08e0018d52f86dff7ba971e8528792e93faadc 100644 (file)
@@ -48,6 +48,7 @@
 ;; - proper interaction with pending-del and del-sel modes.
 ;; - New py-electric-colon (:) command for improved outdenting.  Also
 ;;   py-indent-line (TAB) should handle outdented lines better.
+;; - New commands py-outdent-left (C-c C-l) and py-indent-right (C-c C-r)
 
 ;; Here's a brief to do list:
 ;;
@@ -247,6 +248,8 @@ Currently-active file is at the head of the list.")
            ("\n"        . py-newline-and-indent)
            ("\C-c:"     . py-guess-indent-offset)
            ("\C-c\t"    . py-indent-region)
+           ("\C-c\C-l"  . py-outdent-left)
+           ("\C-c\C-r"  . py-indent-right)
            ("\C-c<"     . py-shift-region-left)
            ("\C-c>"     . py-shift-region-right)
            ("\C-c\C-n"  . py-next-statement)
@@ -443,6 +446,44 @@ argument is provided, that many colons are inserted non-electrically."
        (indent-to (- indent outdent))
        ))))
 
+(defun py-indent-right (arg)
+  "Indent the line by one `py-indent-offset' level.
+With numeric arg, indent by that many levels.  You cannot indent
+farther right than the distance the line would be indented by
+\\[py-indent-line]."
+  (interactive "p")
+  (let ((col (current-indentation))
+       (want (* arg py-indent-offset))
+       (indent (py-compute-indentation))
+       (pos (- (point-max) (point)))
+       (bol (save-excursion (beginning-of-line) (point))))
+    (if (<= (+ col want) indent)
+       (progn
+         (beginning-of-line)
+         (delete-horizontal-space)
+         (indent-to (+ col want))
+         (if (> (- (point-max) pos) (point))
+             (goto-char (- (point-max) pos)))
+         ))))
+
+(defun py-outdent-left (arg)
+  "Outdent the line by one `py-indent-offset' level.
+With numeric arg, outdent by that many levels.  You cannot outdent
+farther left than column zero."
+  (interactive "p")
+  (let ((col (current-indentation))
+       (want (* arg py-indent-offset))
+       (pos (- (point-max) (point)))
+       (bol (save-excursion (beginning-of-line) (point))))
+    (if (<= 0 (- col want))
+       (progn
+         (beginning-of-line)
+         (delete-horizontal-space)
+         (indent-to (- col want))
+         (if (> (- (point-max) pos) (point))
+             (goto-char (- (point-max) pos)))
+         ))))
+
 \f
 ;;; Functions that execute Python commands in a subprocess
 (defun py-shell ()