Subject: bug#2421: 23.0.90; python-mode: Indent commands behavior

From: Milan Zamazal <[email-masked]>
Date: Mon, 23 Feb 2009 19:25:28 +0100

>>>>> "mr" == martin rudalics <[email-masked]> writes:

    mr> I don't know whether `python-shift-left' and
    mr> `python-shift-right' are of any use without a prefix argument.

They are, I often use them after adding or removing a statement in a
code.
    
    mr> With a prefix argument, they are simple wrappers for
    mr> `indent-rigidly'.  

Yes, this makes no sense.  It would be more logical if they indented by
(* python-indent count).

    mr> Maybe you could propose a patch to provide the behavior you
    mr> like.  

OK, see below for some suggestion.

    mr> In any case, it might be better to use `use-region-p' instead of
    mr> `mark-active' to be more consistent with Emacs 23.

But then the indent commands would work only if transient-mark-mode was
enabled, wouldn't they?

2009-02-23  Milan Zamazal  <[email-masked]>

	* python.el (python-shift-left, python-shift-right): When called
	with a prefix argument, indent by that many levels, not columns.

	* python.el (python-shift-left, python-shift-right): Don't
	deactivate the active mark.

--- python.el.orig	2009-02-23 19:06:19.000000000 +0100
+++ python.el	2009-02-23 19:18:37.000000000 +0100
@@ -2013,17 +2013,18 @@
        (list (region-beginning) (region-end) current-prefix-arg)
      (list (line-beginning-position) (line-end-position) current-prefix-arg)))
   (if count
-      (setq count (prefix-numeric-value count))
+      (setq count (* python-indent (prefix-numeric-value count)))
     (setq count python-indent))
-  (when (> count 0)
-    (save-excursion
-      (goto-char start)
-      (while (< (point) end)
-	(if (and (< (current-indentation) count)
-		 (not (looking-at "[ \t]*$")))
-	    (error "Can't shift all lines enough"))
-	(forward-line))
-      (indent-rigidly start end (- count)))))
+  (let (deactivate-mark)
+    (when (> count 0)
+      (save-excursion
+        (goto-char start)
+        (while (< (point) end)
+          (if (and (< (current-indentation) count)
+                   (not (looking-at "[ \t]*$")))
+              (error "Can't shift all lines enough"))
+          (forward-line))
+        (indent-rigidly start end (- count))))))
 
 (add-to-list 'debug-ignored-errors "^Can't shift all lines enough")
 
@@ -2036,10 +2037,11 @@
    (if mark-active
        (list (region-beginning) (region-end) current-prefix-arg)
      (list (line-beginning-position) (line-end-position) current-prefix-arg)))
-  (if count
-      (setq count (prefix-numeric-value count))
-    (setq count python-indent))
-  (indent-rigidly start end count))
+  (let (deactivate-mark)
+    (if count
+        (setq count (* python-indent (prefix-numeric-value count)))
+      (setq count python-indent))
+    (indent-rigidly start end count)))
 
 (defun python-outline-level ()
   "`outline-level' function for Python mode.

Regards,

Milan Zamazal