all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#12060: 24.1.50; python.el: Preserve position of point when indenting
@ 2012-07-26 18:45 Lawrence Mitchell
  2012-09-24 18:18 ` Fabián Ezequiel Gallina
  0 siblings, 1 reply; 2+ messages in thread
From: Lawrence Mitchell @ 2012-07-26 18:45 UTC (permalink / raw
  To: 12060


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






^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#12060: 24.1.50; python.el: Preserve position of point when indenting
  2012-07-26 18:45 bug#12060: 24.1.50; python.el: Preserve position of point when indenting Lawrence Mitchell
@ 2012-09-24 18:18 ` Fabián Ezequiel Gallina
  0 siblings, 0 replies; 2+ messages in thread
From: Fabián Ezequiel Gallina @ 2012-09-24 18:18 UTC (permalink / raw
  To: 12060

A fix for this has been committed in revno 110170.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-09-24 18:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-26 18:45 bug#12060: 24.1.50; python.el: Preserve position of point when indenting Lawrence Mitchell
2012-09-24 18:18 ` Fabián Ezequiel Gallina

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.