GNU bug report logs - #12060
24.1.50; python.el: Preserve position of point when indenting

Previous Next

Package: emacs;

Reported by: Lawrence Mitchell <wence <at> gmx.li>

Date: Thu, 26 Jul 2012 18:54:02 UTC

Severity: normal

Found in version 24.1.50

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 12060 in the body.
You can then email your comments to 12060 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-gnu-emacs <at> gnu.org:
bug#12060; Package emacs. (Thu, 26 Jul 2012 18:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lawrence Mitchell <wence <at> gmx.li>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 26 Jul 2012 18:54:02 GMT) Full text and rfc822 format available.

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

From: Lawrence Mitchell <wence <at> gmx.li>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.1.50; python.el: Preserve position of point when indenting
Date: Thu, 26 Jul 2012 19:45:44 +0100
The new version of python.el has somewhat surprising (at least to
me) indenting behaviour.

When indenting, point is moved from the current position on the
line to the first non-whitespace character.  This is unlike most
other progmodes which preserve the relative position of point in
the line when indenting and only move to the first non-whitespace
character when point is in whitespace at the beginning of the
line.

Here's a patch + changelog entry to introduce the normal
behaviour:

python: Preserve relative position of point when indenting

* lisp/progmodes/python.el (python-indent-line): Restore point if we
weren't in whitespace at the beginning of the line.

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 132951a..224d0ae 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -862,17 +862,20 @@ possible indentation levels and saves it in the variable
 `python-indent-levels'.  Afterwards it sets the variable
 `python-indent-current-level' correctly so offset is equal
 to (`nth' `python-indent-current-level' `python-indent-levels')"
-  (if (or (and (eq this-command 'indent-for-tab-command)
-               (eq last-command this-command))
-          force-toggle)
-      (if (not (equal python-indent-levels '(0)))
-          (python-indent-toggle-levels)
-        (python-indent-calculate-levels))
-    (python-indent-calculate-levels))
-  (beginning-of-line)
-  (delete-horizontal-space)
-  (indent-to (nth python-indent-current-level python-indent-levels))
-  (python-info-closing-block-message))
+  (let ((pos (- (point-max) (point))))
+    (if (or (and (eq this-command 'indent-for-tab-command)
+                 (eq last-command this-command))
+            force-toggle)
+        (if (not (equal python-indent-levels '(0)))
+            (python-indent-toggle-levels)
+          (python-indent-calculate-levels))
+      (python-indent-calculate-levels))
+    (beginning-of-line)
+    (delete-horizontal-space)
+    (indent-to (nth python-indent-current-level python-indent-levels))
+    (if (> (- (point-max) pos) (point))
+        (goto-char (- (point-max) pos)))
+    (python-info-closing-block-message)))
 
 (defun python-indent-line-function ()
   "`indent-line-function' for Python mode.



In GNU Emacs 24.1.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10)
 of 2012-07-07 on e4300lm
Windowing system distributor `The X.Org Foundation', version 11.0.11103000
Configured using:
 `configure '--prefix=/home/lmitche4/Apps/emacs' '-C' 'CFLAGS=-O0
 -ggdb3''





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12060; Package emacs. (Mon, 24 Sep 2012 18:21:01 GMT) Full text and rfc822 format available.

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

From: Fabián Ezequiel Gallina <fabian <at> anue.biz>
To: 12060 <at> debbugs.gnu.org
Subject: 24.1.50; python.el: Preserve position of point when indenting
Date: Mon, 24 Sep 2012 15:18:31 -0300
A fix for this has been committed in revno 110170.




bug closed, send any further explanations to 12060 <at> debbugs.gnu.org and Lawrence Mitchell <wence <at> gmx.li> Request was from Fabián Ezequiel Gallina <fabian <at> anue.biz> to control <at> debbugs.gnu.org. (Mon, 24 Sep 2012 18:21:02 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, 23 Oct 2012 11:24:04 GMT) Full text and rfc822 format available.

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

Previous Next


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