]> code.delx.au - gnu-emacs-elpa/commitdiff
Restore point even when errors.
authorArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 29 Oct 2014 18:52:18 +0000 (18:52 +0000)
committerArtur Malabarba <bruce.connor.am@gmail.com>
Wed, 29 Oct 2014 18:52:18 +0000 (18:52 +0000)
Fixes #23.

aggressive-indent.el

index 893567fc03ac1320f907252795a868bab48247e4..07bc7d511cdde7125058faf2d945d90e2e65f7af 100644 (file)
@@ -276,28 +276,30 @@ until nothing more happens."
   (let ((p (point-marker))
         was-begining-of-line)
     (set-marker-insertion-type p t)
-    (goto-char r)
-    (setq was-begining-of-line
-          (= r (line-beginning-position)))
-    ;; If L is at the end of a line, skip that line.
-    (unless (= l r)
-      (goto-char l)
-      (when (= l (line-end-position))
-        (cl-incf l)))
-    ;; Indent the affected region.
-    (unless (= l r) (indent-region l r))
-    ;; `indent-region' doesn't do anything if R was the beginning of a line, so we indent manually there.
-    (when was-begining-of-line
-      (indent-according-to-mode))
-    ;; And then we indent each following line until nothing happens.
-    (forward-line 1)
-    (while (and (null (eobp))
-                (/= (progn (skip-chars-forward "[:blank:]\n")
-                           (point))
-                    (progn (indent-according-to-mode)
-                           (point))))
-      (forward-line 1))
-    (goto-char p)))
+    (unwind-protect
+        (progn
+          (goto-char r)
+          (setq was-begining-of-line
+                (= r (line-beginning-position)))
+          ;; If L is at the end of a line, skip that line.
+          (unless (= l r)
+            (goto-char l)
+            (when (= l (line-end-position))
+              (cl-incf l)))
+          ;; Indent the affected region.
+          (unless (= l r) (indent-region l r))
+          ;; `indent-region' doesn't do anything if R was the beginning of a line, so we indent manually there.
+          (when was-begining-of-line
+            (indent-according-to-mode))
+          ;; And then we indent each following line until nothing happens.
+          (forward-line 1)
+          (while (and (null (eobp))
+                      (/= (progn (skip-chars-forward "[:blank:]\n")
+                                 (point))
+                          (progn (indent-according-to-mode)
+                                 (point))))
+            (forward-line 1)))
+      (goto-char p))))
 
 (defun -softly-indent-region-and-on (l r &rest _)
   "Indent current defun unobstrusively.