GNU bug report logs - #2421
23.0.90; python-mode: Indent commands behavior

Previous Next

Package: emacs;

Reported by: Milan Zamazal <pdm <at> zamazal.org>

Date: Sat, 21 Feb 2009 10:30:05 UTC

Severity: wishlist

Done: Fabián Ezequiel Gallina <fabian <at> anue.biz>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 2421 in the body.
You can then email your comments to 2421 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Sat, 21 Feb 2009 10:30:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 21 Feb 2009 10:30:06 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: emacs-pretest-bug <at> gnu.org
Subject: 23.0.90; python-mode: Indent commands behavior
Date: Sat, 21 Feb 2009 11:25:22 +0100
In GNU Emacs 23.0.90.1 (x86_64-pc-linux-gnu, GTK+ Version 2.12.11)
 of 2009-02-03 on blackbird, modified by Debian
 (emacs-snapshot package, version 1:20090202-1)

The indent commands `C-c <' and `C-c >' work only on active regions.
This is annoying, inconsistent with `C-x TAB' behavior, and not useful
(even if it worked as announced in its documentation, i.e. shifting the
current line, which it doesn't, a similar effect can be achieved more
easily by TAB presses).

So I suggest to change the behavior of these commands to always work on
the region, whether it is active or not, or to provide a configuration
option which can enable such a behavior.

Regards,

Milan Zamazal




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Sat, 21 Feb 2009 14:20:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 21 Feb 2009 14:20:03 GMT) Full text and rfc822 format available.

Message #10 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: 2421 <at> debbugs.gnu.org
Cc: Milan Zamazal <pdm <at> zamazal.org>
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Sat, 21 Feb 2009 15:10:46 +0100
> The indent commands `C-c <' and `C-c >' work only on active regions.
> This is annoying, inconsistent with `C-x TAB' behavior, and not useful
> (even if it worked as announced in its documentation, i.e. shifting the
> current line, which it doesn't,

I changed that yesterday, so it now should work as documented.

> a similar effect can be achieved more
> easily by TAB presses).
>
> So I suggest to change the behavior of these commands to always work on
> the region, whether it is active or not, or to provide a configuration
> option which can enable such a behavior.

Isn't that shift behavior something that should be done via rectangles?
IIRC, someone even proposed to keep the region active after the command
completes in order to apply a second shift step if needed.

martin





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Sat, 21 Feb 2009 15:05:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 21 Feb 2009 15:05:05 GMT) Full text and rfc822 format available.

Message #15 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Sat, 21 Feb 2009 15:59:09 +0100
>>>>> "mr" == martin rudalics <rudalics <at> gmx.at> writes:

    mr> Isn't that shift behavior something that should be done via
    mr> rectangles?  

Do you mean by the user?  No, this would require marking the region on
exact characters rather than lines, i.e. it would be less comfortable
and would make the operation more visual than logical.  `C-x TAB' is
also not superfluous.

    mr> IIRC, someone even proposed to keep the region active after the
    mr> command completes in order to apply a second shift step if
    mr> needed.

This would be OK for me.

Regards,

Milan Zamazal




Severity set to `wishlist' from `normal' Request was from Glenn Morris <rgm <at> gnu.org> to control <at> emacsbugs.donarmstrong.com. (Sat, 21 Feb 2009 19:50:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Sun, 22 Feb 2009 18:40:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sun, 22 Feb 2009 18:40:05 GMT) Full text and rfc822 format available.

Message #22 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Milan Zamazal <pdm <at> zamazal.org>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Sun, 22 Feb 2009 19:29:52 +0100
>     mr> Isn't that shift behavior something that should be done via
>     mr> rectangles?
>
> Do you mean by the user?  No, this would require marking the region on
> exact characters rather than lines, i.e. it would be less comfortable

You're right that rect.el doesn't have suitable code for highlighting
and dragging rectangles.  cua-rect.el has two functions for shifting
rectangles, but I don't know whether they could be used here.

> and would make the operation more visual than logical.

That was my intention.  I don't know whether `python-shift-left' and
`python-shift-right' are of any use without a prefix argument.  With a
prefix argument, they are simple wrappers for `indent-rigidly'.  And
`indent-rigidly' is a purely visual operation.  That is, if indenting
part of a program changes the semantics of the program, it's the user
who's responsible, without any "logical" support from `python-mode'.

But since I never use these functions you shouldn't take my remarks too
seriously.  Maybe you could propose a patch to provide the behavior you
like.  In any case, it might be better to use `use-region-p' instead of
`mark-active' to be more consistent with Emacs 23.

martin





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Mon, 23 Feb 2009 18:35:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Mon, 23 Feb 2009 18:35:04 GMT) Full text and rfc822 format available.

Message #27 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Mon, 23 Feb 2009 19:25:28 +0100
[Message part 1 (text/plain, inline)]
>>>>> "mr" == martin rudalics <rudalics <at> gmx.at> 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  <pdm <at> zamazal.org>

	* 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.patch (text/x-diff, inline)]
--- 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.
[Message part 3 (text/plain, inline)]
Regards,

Milan Zamazal

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Tue, 24 Feb 2009 13:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Tue, 24 Feb 2009 13:50:03 GMT) Full text and rfc822 format available.

Message #32 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Milan Zamazal <pdm <at> zamazal.org>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Tue, 24 Feb 2009 14:40:17 +0100
>     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.

I'm confused.  Why don't you use TAB in that case?

>     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).

It might be even more logical to restrict ourselves to valid indentation
points only.  In any case we would need some feedback from `python-mode'
users for such a change.  The same goes for not deactivating the mark.

>     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?

The commands should DTRT when `transient-mark-mode' is enabled because
it's the default with Emacs 23.  That is, with `transient-mark-mode' on,
these commands should operate on the region only if the mark is active
and should respect `use-empty-active-region'.  I have no idea what TRT
is now when `transient-mark-mode' is off.  You appear reluctant to use
transient mark mode, I suppose ...

martin





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Tue, 24 Feb 2009 15:05:07 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Tue, 24 Feb 2009 15:05:07 GMT) Full text and rfc822 format available.

Message #37 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Tue, 24 Feb 2009 15:58:25 +0100
>>>>> "mr" == martin rudalics <rudalics <at> gmx.at> writes:

    mr> Why don't you use TAB in that case?

Because I didn't know it can work on regions!  Perhaps this makes the
python-shift-* commands redundant for my use, I'll see.  I'm sorry for
the confusion.

Regards,

Milan Zamazal




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Wed, 04 Mar 2009 16:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Wed, 04 Mar 2009 16:50:02 GMT) Full text and rfc822 format available.

Message #42 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Wed, 04 Mar 2009 17:42:16 +0100
>>>>> "mr" == martin rudalics <rudalics <at> gmx.at> 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> I'm confused.  Why don't you use TAB in that case?

Well, actually TAB runs indent-region.  But I need simple shift instead.
Consider the following example:

  def foo():
      for i in range(3):
  print i
  print i + 1
  print i + 2

I just pasted the print lines from a differently indented code and want
to fix the indentation by shifting the region of the print lines:

  def foo():
      for i in range(3):
          print i
          print i + 1
          print i + 2

TAB can't do it:

  def foo():
      for i in range(3):
          print i
  print i + 1
  print i + 2

Neither repeated pressing of C->:

  def foo():
      for i in range(3):
      print i
      print i + 1
      print i + 2

To get what I want I have to press `C-8 C->'.  I don't like it, I'd like
to call `M-x SOMETHING-shift-right' twice or
`M-2 M-x SOMETHING-shift-right'.

    >> It would be more logical if they indented by (* python-indent
    >> count).

    mr> It might be even more logical to restrict ourselves to valid
    mr> indentation points only.

Perhaps, but it's not that important.

    mr> In any case we would need some feedback from `python-mode' users
    mr> for such a change.  The same goes for not deactivating the mark.

If people like the current behavior, configuration options may be
introduced.

    mr> I have no idea what TRT is now when `transient-mark-mode' is
    mr> off.  

Neither do I.

Regards,

Milan Zamazal




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Thu, 05 Mar 2009 19:10:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Thu, 05 Mar 2009 19:10:05 GMT) Full text and rfc822 format available.

Message #47 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Milan Zamazal <pdm <at> zamazal.org>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Thu, 05 Mar 2009 19:58:09 +0100
> Well, actually TAB runs indent-region.  But I need simple shift instead.
> Consider the following example:
>
>   def foo():
>       for i in range(3):
>   print i
>   print i + 1
>   print i + 2
>
> I just pasted the print lines from a differently indented code and want
> to fix the indentation by shifting the region of the print lines:
>
>   def foo():
>       for i in range(3):
>           print i
>           print i + 1
>           print i + 2
>
> TAB can't do it:
>
>   def foo():
>       for i in range(3):
>           print i
>   print i + 1
>   print i + 2

We could pass the prefix argument to `indent-region' with the semantics
that the latter ignores the mode-specific `indent-region-function' and
calls `indent-line' for each line in the region instead.

Alternatively, `python-indent-region' could, like `python-indent-line',
remember whether the last command was an `indent-for-tab-command' and
call `python-indent-line-1' with no argument for each line in the
region.  Obviously, the region would have to stay to make this
practical.  And in some pathological cases it might be hard to find the
appropriate indentation points.

Anyhow, I'm afraid that people won't approve such changes.

> To get what I want I have to press `C-8 C->'.  I don't like it, I'd like
> to call `M-x SOMETHING-shift-right' twice or
> `M-2 M-x SOMETHING-shift-right'.

That's why I earlier said that some rectangle code should handle this.

martin




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#2421; Package emacs. (Fri, 06 Mar 2009 08:35:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Milan Zamazal <pdm <at> zamazal.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 06 Mar 2009 08:35:03 GMT) Full text and rfc822 format available.

Message #52 received at 2421 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Milan Zamazal <pdm <at> zamazal.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 2421 <at> debbugs.gnu.org
Subject: Re: bug#2421: 23.0.90; python-mode: Indent commands behavior
Date: Fri, 06 Mar 2009 09:24:55 +0100
Hm, it seems the easiest solution will be that I put my own definitions
to ~/.emacs.

Regards,

Milan Zamazal




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#2421; Package emacs. (Mon, 08 Oct 2012 21:44:02 GMT) Full text and rfc822 format available.

Message #55 received at 2421 <at> debbugs.gnu.org (full text, mbox):

From: Fabián Ezequiel Gallina <fabian <at> anue.biz>
To: 2421 <at> debbugs.gnu.org
Subject: 23.0.90; python-mode: Indent commands behavior
Date: Mon, 08 Oct 2012 18:43:27 -0300
Trunk's python mode works the same whether the region is active or not.

Closing this one.





bug closed, send any further explanations to 2421 <at> debbugs.gnu.org and Milan Zamazal <pdm <at> zamazal.org> Request was from Fabián Ezequiel Gallina <fabian <at> anue.biz> to control <at> debbugs.gnu.org. (Mon, 08 Oct 2012 21:45:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 06 Nov 2012 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 232 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.