changeset 108987:18cf7a828b34

* lisp/nxml/nxml-mode.el (nxml-indent-line): Standardize indent behavior.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 13 Jun 2010 21:43:11 -0400
parents c879988fd08d
children 65de28008783
files lisp/ChangeLog lisp/nxml/nxml-mode.el
diffstat 2 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Jun 14 01:33:06 2010 +0200
+++ b/lisp/ChangeLog	Sun Jun 13 21:43:11 2010 -0400
@@ -1,3 +1,7 @@
+2010-06-14  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* nxml/nxml-mode.el (nxml-indent-line): Standardize indent behavior.
+
 2010-06-12  Chong Yidong  <cyd@stupidchicken.com>
 
 	* term/common-win.el (x-colors): Add all the color names defined
--- a/lisp/nxml/nxml-mode.el	Mon Jun 14 01:33:06 2010 +0200
+++ b/lisp/nxml/nxml-mode.el	Sun Jun 13 21:43:11 2010 -0400
@@ -1370,17 +1370,21 @@
 
 (defun nxml-indent-line ()
   "Indent current line as XML."
-  (let ((indent (nxml-compute-indent))
-	(from-end (- (point-max) (point))))
-    (when (and indent
-	       (/= indent (current-indentation)))
-      (beginning-of-line)
-      (let ((bol (point)))
-	(skip-chars-forward " \t")
-	(delete-region bol (point)))
-      (indent-to indent)
-      (when (> (- (point-max) from-end) (point))
-	(goto-char (- (point-max) from-end))))))
+  (let* ((savep (point))
+         (indent (condition-case nil
+                     (save-excursion
+                       (forward-line 0)
+                       (skip-chars-forward " \t")
+                       (if (>= (point) savep) (setq savep nil))
+                       (or (nxml-compute-indent) 0))
+                   (error 0))))
+    (if (not (numberp indent))
+        ;; If something funny is used (e.g. `noindent'), return it.
+        indent
+      (if (< indent 0) (setq indent 0)) ;Just in case.
+      (if savep
+          (save-excursion (indent-line-to indent))
+        (indent-line-to indent)))))
 
 (defun nxml-compute-indent ()
   "Return the indent for the line containing point."